diff options
author | Guyzmo <guyzmo+github@m0g.net> | 2016-05-12 16:35:51 +0200 |
---|---|---|
committer | Guyzmo <guyzmo+github@m0g.net> | 2016-05-12 17:43:59 +0200 |
commit | 89ade7bfff534ae799d7dd693b206931d5ed3d4f (patch) | |
tree | 5b54deb61df6ad6605d5d263911bd9916c1a92b1 /git/cmd.py | |
parent | fb577c8a1eca8958415b76cde54d454618ac431e (diff) | |
download | gitpython-89ade7bfff534ae799d7dd693b206931d5ed3d4f.tar.gz |
Fix order of operators before executing the git command
Since Python 3.3, the hash value of an object is seeded randomly, making it
change between each call. As a consequence, the `dict` type relying on the hash
value for the order of the items upon iterating on it, and the parameters
passed to `git` being passed as `kwargs` to the `execute()` method, the order
of parameters will change randomly between calls.
For example, when you call `git.remote.pull()` in a code, two consecutives run
will generate:
1. git pull --progress -v origin master
2. git pull -v --progress origin master
Within the `transform_kwargs()` method, I'm promoting `kwargs` into an
`collections.OrderedDict` being built with `kwargs` sorted on the keys.
Then it will ensure that each subsequent calls will execute the
parameters in the same order.
Diffstat (limited to 'git/cmd.py')
-rw-r--r-- | git/cmd.py | 3 |
1 files changed, 3 insertions, 0 deletions
@@ -13,6 +13,8 @@ import threading import errno import mmap +from collections import OrderedDict + from contextlib import contextmanager import signal from subprocess import ( @@ -783,6 +785,7 @@ class Git(LazyMixin): def transform_kwargs(self, split_single_char_options=True, **kwargs): """Transforms Python style kwargs into git command line options.""" args = list() + kwargs = OrderedDict(sorted(kwargs.items(), key=lambda x: x[0])) for k, v in kwargs.items(): if isinstance(v, (list, tuple)): for value in v: |