From 5df76d451ff0fde14ab71b38030b6c3e6bc79c08 Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Thu, 11 Mar 2021 16:35:24 +0100 Subject: [PATCH] Restore order of operators before executing the git command only for < py3.6 Since Python 3.6 kwargs order will be preserved and thus provide a stable order, therefore we can make 89ade7bfff534ae799d7dd693b206931d5ed3d4f conditional based on the Python. Thus make it able to pass ordered options to Git commands. See: https://www.python.org/dev/peps/pep-0468/ --- git/cmd.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/git/cmd.py b/git/cmd.py index 050efaedf..46d809c74 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -19,6 +19,7 @@ import threading from collections import OrderedDict from textwrap import dedent +import warnings from git.compat import ( defenc, @@ -902,8 +903,14 @@ def transform_kwarg(self, name, value, split_single_char_options): def transform_kwargs(self, split_single_char_options=True, **kwargs): """Transforms Python style kwargs into git command line options.""" + # Python 3.6 preserves the order of kwargs and thus has a stable + # order. For older versions sort the kwargs by the key to get a stable + # order. + if sys.version_info[:2] < (3, 6): + kwargs = OrderedDict(sorted(kwargs.items(), key=lambda x: x[0])) + warnings.warn("Python 3.5 support is deprecated. It does not preserve the order\n" + + "for key-word arguments. Thus they will be sorted!!") args = [] - 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: