diff options
-rw-r--r-- | git/cmd.py | 10 | ||||
-rw-r--r-- | git/test/test_git.py | 12 |
2 files changed, 19 insertions, 3 deletions
@@ -388,7 +388,7 @@ class Git(LazyMixin): else: return stdout_value - def transform_kwargs(self, **kwargs): + def transform_kwargs(self, split_single_char_options=False, **kwargs): """Transforms Python style kwargs into git command line options.""" args = list() for k, v in kwargs.items(): @@ -396,7 +396,10 @@ class Git(LazyMixin): if v is True: args.append("-%s" % k) elif type(v) is not bool: - args.append("-%s%s" % (k, v)) + if split_single_char_options: + args.extend(["-%s" % k, "%s" % v]) + else: + args.append("-%s%s" % (k, v)) else: if v is True: args.append("--%s" % dashify(k)) @@ -431,7 +434,8 @@ class Git(LazyMixin): ``Examples``:: git(work_tree='/tmp').difftool()""" - self._git_options = self.transform_kwargs(**kwargs) + self._git_options = self.transform_kwargs( + split_single_char_options=True, **kwargs) return self def _call_process(self, method, *args, **kwargs): diff --git a/git/test/test_git.py b/git/test/test_git.py index b61a0eea..e39c9575 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -107,3 +107,15 @@ class TestGit(TestBase): finally: type(self.git).GIT_PYTHON_GIT_EXECUTABLE = prev_cmd #END undo adjustment + + def test_options_are_passed_to_git(self): + # This work because any command after git --version is ignored + git_version = self.git(version=True).NoOp() + git_command_version = self.git.version() + self.assertEquals(git_version, git_command_version) + + def test_single_char_git_options_are_passed_to_git(self): + input_value='TestValue' + output_value = self.git(c='user.name={}'.format(input_value)).config('--get', 'user.name') + self.assertEquals(input_value, output_value) + |