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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions 32 git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,23 +764,31 @@ def custom_environment(self, **kwargs):
finally:
self.update_environment(**old_env)

def transform_kwarg(self, name, value, split_single_char_options):
if len(name) == 1:
if value is True:
return ["-%s" % name]
elif type(value) is not bool:
if split_single_char_options:
return ["-%s" % name, "%s" % value]
else:
return ["-%s%s" % (name, value)]
else:
if value is True:
return ["--%s" % dashify(name)]
elif type(value) is not bool:
return ["--%s=%s" % (dashify(name), value)]
return []

def transform_kwargs(self, split_single_char_options=True, **kwargs):
"""Transforms Python style kwargs into git command line options."""
args = list()
for k, v in kwargs.items():
if len(k) == 1:
if v is True:
args.append("-%s" % k)
elif type(v) is not bool:
if split_single_char_options:
args.extend(["-%s" % k, "%s" % v])
else:
args.append("-%s%s" % (k, v))
if isinstance(v, (list, tuple)):
for value in v:
args += self.transform_kwarg(k, value, split_single_char_options)
else:
if v is True:
args.append("--%s" % dashify(k))
elif type(v) is not bool:
args.append("--%s=%s" % (dashify(k), v))
args += self.transform_kwarg(k, v, split_single_char_options)
return args

@classmethod
Expand Down
4 changes: 4 additions & 0 deletions 4 git/test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def test_it_transforms_kwargs_into_git_command_arguments(self):
assert_equal(["--max-count"], self.git.transform_kwargs(**{'max_count': True}))
assert_equal(["--max-count=5"], self.git.transform_kwargs(**{'max_count': 5}))

# Multiple args are supported by using lists/tuples
assert_equal(["-L", "1-3", "-L", "12-18"], self.git.transform_kwargs(**{'L': ('1-3', '12-18')}))
assert_equal(["-C", "-C"], self.git.transform_kwargs(**{'C': [True, True]}))

# order is undefined
res = self.git.transform_kwargs(**{'s': True, 't': True})
assert ['-s', '-t'] == res or ['-t', '-s'] == res
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.