Skip to content

Commit

Permalink
Exclude kwarg when None
Browse files Browse the repository at this point in the history
  • Loading branch information
nvllsvm authored and Byron committed Aug 5, 2018
1 parent b3d9b8d commit a8591a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions git/cmd.py
Expand Up @@ -885,15 +885,15 @@ 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:
elif value not in (False, None):
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:
elif value not in (False, None):
return ["--%s=%s" % (dashify(name), value)]
return []

Expand Down
4 changes: 3 additions & 1 deletion git/test/test_git.py
Expand Up @@ -82,13 +82,15 @@ def test_it_raises_errors(self):
def test_it_transforms_kwargs_into_git_command_arguments(self):
assert_equal(["-s"], self.git.transform_kwargs(**{'s': True}))
assert_equal(["-s", "5"], self.git.transform_kwargs(**{'s': 5}))
assert_equal([], self.git.transform_kwargs(**{'s': None}))

assert_equal(["--max-count"], self.git.transform_kwargs(**{'max_count': True}))
assert_equal(["--max-count=5"], self.git.transform_kwargs(**{'max_count': 5}))
assert_equal([], self.git.transform_kwargs(**{'max_count': None}))

# 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]}))
assert_equal(["-C", "-C"], self.git.transform_kwargs(**{'C': [True, True, None, False]}))

# order is undefined
res = self.git.transform_kwargs(**{'s': True, 't': True})
Expand Down

0 comments on commit a8591a0

Please sign in to comment.