Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Add an output_strip kwarg to Git.execute#79

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Byron merged 1 commit intogitpython-developers:masterfromznerol:feature/master/cmd-output-strip
Oct 21, 2012
Merged
Show file tree
Hide file tree
Changes fromall 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
10 changes: 8 additions & 2 deletionsgit/cmd.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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_strip' )

__all__ = ('Git', )

Expand DownExpand Up@@ -267,6 +267,7 @@ def execute(self, command,
with_exceptions=True,
as_process=False,
output_stream=None,
output_strip=True,
**subprocess_kwargs
):
"""Handles executing the command on the shell and consumes and returns
Expand DownExpand 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_strip:
Strip the last line of the output if it is empty (default). Stripping should
be disabled whenever it is important that the output is not modified in any
way. For example when retrieving patch files using git-diff.

: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 DownExpand 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 output_strip:
stdout_value = stdout_value[:-1]
if stderr_value.endswith("\n"):
stderr_value = stderr_value[:-1]
Expand Down
22 changes: 22 additions & 0 deletionsgit/test/test_cmd.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,3 +108,25 @@ def test_cmd_override(self):
finally:
type(self.git).GIT_PYTHON_GIT_EXECUTABLE = prev_cmd
#END undo adjustment

def test_output_strip(self):
import subprocess as sp
hexsha = "b2339455342180c7cc1e9bba3e9f181f7baa5167"

# Verify that a trailing newline is stripped from the output of a git
# command.
content = self.git.cat_file('blob', hexsha)
g = self.git.hash_object(istream=sp.PIPE, as_process=True, stdin=True)
g.stdin.write(content)
g.stdin.close()
newsha = g.stdout.readline().strip()
self.assertNotEquals(newsha, hexsha)

# Verify that output of a git command which ends with an empty
# line is not modified when the output_strip flag is cleared.
content = self.git.cat_file('blob', hexsha, output_strip=False)
g = self.git.hash_object(istream=sp.PIPE, as_process=True, stdin=True)
g.stdin.write(content)
g.stdin.close()
newsha = g.stdout.readline().strip()
self.assertEquals(newsha, hexsha)

[8]ページ先頭

©2009-2025 Movatter.jp