Skip to content

Add an output_nostrip kwarg to Git.execute #76

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

Closed
wants to merge 1 commit into from
Closed
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
Add an output_nostrip kwarg to Git.execute
The last line of the output normally is stripped if it is empty. If
output_nostrip is True, this behavior is disabled. This can be important
when constructing patches e.g. using the diff command.
  • Loading branch information
znerol committed Oct 12, 2012
commit 2d992711acc33911c779c799e3acf9ca582b9913
10 changes: 8 additions & 2 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output',
'with_exceptions', 'as_process',
'output_stream' )
'output_stream', 'output_nostrip' )

__all__ = ('Git', )

Expand Down Expand Up @@ -267,6 +267,7 @@ def execute(self, command,
with_exceptions=True,
as_process=False,
output_stream=None,
output_nostrip=False,
**subprocess_kwargs
):
"""Handles executing the command on the shell and consumes and returns
Expand Down Expand Up @@ -309,6 +310,11 @@ def execute(self, command,
This merely is a workaround as data will be copied from the
output pipe to the given output stream directly.

:param output_nostrip:
The last line of the output normally is stripped if it is empty. If
output_nostrip is True, this behavior is disabled. This can be important
when constructing patches e.g. using the diff command.

:param subprocess_kwargs:
Keyword arguments to be passed to subprocess.Popen. Please note that
some of the valid kwargs are already set by this method, the ones you
Expand Down Expand Up @@ -359,7 +365,7 @@ def execute(self, command,
if output_stream is None:
stdout_value, stderr_value = proc.communicate()
# strip trailing "\n"
if stdout_value.endswith("\n"):
if stdout_value.endswith("\n") and not output_nostrip:
stdout_value = stdout_value[:-1]
if stderr_value.endswith("\n"):
stderr_value = stderr_value[:-1]
Expand Down