|
19 | 19 |
|
20 | 20 | execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output',
|
21 | 21 | 'with_exceptions', 'as_process',
|
22 |
| - 'output_stream' ) |
| 22 | + 'output_stream', 'output_strip' ) |
23 | 23 |
|
24 | 24 | __all__ = ('Git', )
|
25 | 25 |
|
@@ -267,6 +267,7 @@ def execute(self, command,
|
267 | 267 | with_exceptions=True,
|
268 | 268 | as_process=False,
|
269 | 269 | output_stream=None,
|
| 270 | + output_strip=True, |
270 | 271 | **subprocess_kwargs
|
271 | 272 | ):
|
272 | 273 | """Handles executing the command on the shell and consumes and returns
|
@@ -309,6 +310,11 @@ def execute(self, command,
|
309 | 310 | This merely is a workaround as data will be copied from the
|
310 | 311 | output pipe to the given output stream directly.
|
311 | 312 |
|
| 313 | + :param output_strip: |
| 314 | + Strip the last line of the output if it is empty (default). Stripping should |
| 315 | + be disabled whenever it is important that the output is not modified in any |
| 316 | + way. For example when retrieving patch files using git-diff. |
| 317 | + |
312 | 318 | :param subprocess_kwargs:
|
313 | 319 | Keyword arguments to be passed to subprocess.Popen. Please note that
|
314 | 320 | some of the valid kwargs are already set by this method, the ones you
|
@@ -359,7 +365,7 @@ def execute(self, command,
|
359 | 365 | if output_stream is None:
|
360 | 366 | stdout_value, stderr_value = proc.communicate()
|
361 | 367 | # strip trailing "\n"
|
362 |
| - if stdout_value.endswith("\n"): |
| 368 | + if stdout_value.endswith("\n") and output_strip: |
363 | 369 | stdout_value = stdout_value[:-1]
|
364 | 370 | if stderr_value.endswith("\n"):
|
365 | 371 | stderr_value = stderr_value[:-1]
|
|
0 commit comments