Skip to content

Fix TypeError in git.execute(..., output_stream=file) #782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2018
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
2 changes: 1 addition & 1 deletion git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ def _kill_process(pid):
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably the only way to do this properly, even though it seems funky. Ideally stdout_value should be the value read, but in this case, it will always be an empty string as read() is called right after stream_copy(...).
However, looking at it, the whole implementations seems to have gotten somewhat convoluted over the years, so it's probably alright after all.

stderr_value = proc.stderr.read()
# strip trailing "\n"
if stderr_value.endswith(b"\n"):
Expand Down
6 changes: 6 additions & 0 deletions git/test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import subprocess
import sys
from tempfile import TemporaryFile

from git import (
Git,
Expand Down Expand Up @@ -108,6 +109,11 @@ def test_it_ignores_false_kwargs(self, git):
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:
Expand Down