Skip to content

Commit 89ade7b

Browse files
committed
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.
1 parent fb577c8 commit 89ade7b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

‎git/cmd.py

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import errno
1414
import mmap
1515

16+
from collections import OrderedDict
17+
1618
from contextlib import contextmanager
1719
import signal
1820
from subprocess import (
@@ -783,6 +785,7 @@ def transform_kwarg(self, name, value, split_single_char_options):
783785
def transform_kwargs(self, split_single_char_options=True, **kwargs):
784786
"""Transforms Python style kwargs into git command line options."""
785787
args = list()
788+
kwargs = OrderedDict(sorted(kwargs.items(), key=lambda x: x[0]))
786789
for k, v in kwargs.items():
787790
if isinstance(v, (list, tuple)):
788791
for value in v:

0 commit comments

Comments
 (0)