Repository: gitpython-developers/GitPython
Pull request #785 (2018-07-27 00:26:30)

Exclude kwarg when None
Resolves https://github.com/gitpython-developers/GitPython/issues/784


Patch:
diff --git a/git/cmd.py b/git/cmd.py
index 54537a41..b6305176 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -794,7 +794,7 @@ class Git(LazyMixin):
             else:
                 max_chunk_size = max_chunk_size if max_chunk_size and max_chunk_size > 0 else io.DEFAULT_BUFFER_SIZE
                 stream_copy(proc.stdout, output_stream, max_chunk_size)
-                stdout_value = output_stream
+                stdout_value = proc.stdout.read()
                 stderr_value = proc.stderr.read()
                 # strip trailing "\n"
                 if stderr_value.endswith(b"\n"):
@@ -885,7 +885,7 @@ class Git(LazyMixin):
         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:
@@ -893,7 +893,7 @@ class Git(LazyMixin):
         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 []
 


Test patch:
diff --git a/git/test/test_git.py b/git/test/test_git.py
index c6180f7c..30a6a335 100644
--- a/git/test/test_git.py
+++ b/git/test/test_git.py
@@ -7,6 +7,7 @@
 import os
 import subprocess
 import sys
+from tempfile import TemporaryFile
 
 from git import (
     Git,
@@ -81,13 +82,15 @@ class TestGit(TestBase):
     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})
@@ -108,6 +111,11 @@ class TestGit(TestBase):
         self.git.version(pass_this_kwarg=False)
         assert_true("pass_this_kwarg" not in git.call_args[1])
 
+    @raises(GitCommandError)
+    def test_it_raises_proper_exception_with_output_stream(self):
+        tmp_file = TemporaryFile()
+        self.git.checkout('non-existent-branch', output_stream=tmp_file)
+
     def test_it_accepts_environment_variables(self):
         filename = fixture_path("ls_tree_empty")
         with open(filename, 'r') as fh: