Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f2df73b

Browse filesBrowse files
author
Eric Brunson
committed
add git command options
Add __call__ method to Git object to allow passing git command options to the executable requires flag to transform_kwargs add unit test Change-Id: If1bc01008e66d3fd3811c15b56e58f38c95b9887
1 parent e54cd8f commit f2df73b
Copy full SHA for f2df73b

2 files changed

+19-3Lines changed: 19 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎git/cmd.py‎

Copy file name to clipboardExpand all lines: git/cmd.py
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,18 @@ def execute(self, command,
388388
else:
389389
return stdout_value
390390

391-
def transform_kwargs(self, **kwargs):
391+
def transform_kwargs(self, split_single_char_options=False, **kwargs):
392392
"""Transforms Python style kwargs into git command line options."""
393393
args = list()
394394
for k, v in kwargs.items():
395395
if len(k) == 1:
396396
if v is True:
397397
args.append("-%s" % k)
398398
elif type(v) is not bool:
399-
args.append("-%s%s" % (k, v))
399+
if split_single_char_options:
400+
args.extend(["-%s" % k, "%s" % v])
401+
else:
402+
args.append("-%s%s" % (k, v))
400403
else:
401404
if v is True:
402405
args.append("--%s" % dashify(k))
@@ -431,7 +434,8 @@ def __call__(self, **kwargs):
431434
432435
``Examples``::
433436
git(work_tree='/tmp').difftool()"""
434-
self._git_options = self.transform_kwargs(**kwargs)
437+
self._git_options = self.transform_kwargs(
438+
split_single_char_options=True, **kwargs)
435439
return self
436440

437441
def _call_process(self, method, *args, **kwargs):
Collapse file

‎git/test/test_git.py‎

Copy file name to clipboardExpand all lines: git/test/test_git.py
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,15 @@ def test_cmd_override(self):
107107
finally:
108108
type(self.git).GIT_PYTHON_GIT_EXECUTABLE = prev_cmd
109109
#END undo adjustment
110+
111+
def test_options_are_passed_to_git(self):
112+
# This work because any command after git --version is ignored
113+
git_version = self.git(version=True).NoOp()
114+
git_command_version = self.git.version()
115+
self.assertEquals(git_version, git_command_version)
116+
117+
def test_single_char_git_options_are_passed_to_git(self):
118+
input_value='TestValue'
119+
output_value = self.git(c='user.name={}'.format(input_value)).config('--get', 'user.name')
120+
self.assertEquals(input_value, output_value)
121+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.