|
55 | 55 | execute_kwargs = {'istream', 'with_extended_output',
|
56 | 56 | 'with_exceptions', 'as_process', 'stdout_as_string',
|
57 | 57 | 'output_stream', 'with_stdout', 'kill_after_timeout',
|
58 |
| - 'universal_newlines', 'shell', 'env', 'max_chunk_size'} |
| 58 | + 'universal_newlines', 'shell', 'env', 'max_chunk_size', 'strip_newline_in_stdout'} |
59 | 59 |
|
60 | 60 | log = logging.getLogger(__name__)
|
61 | 61 | log.addHandler(logging.NullHandler())
|
@@ -738,6 +738,7 @@ def execute(self,
|
738 | 738 | shell: Union[None, bool] = None,
|
739 | 739 | env: Union[None, Mapping[str, str]] = None,
|
740 | 740 | max_chunk_size: int = io.DEFAULT_BUFFER_SIZE,
|
| 741 | + strip_newline_in_stdout: bool = True, |
741 | 742 | **subprocess_kwargs: Any
|
742 | 743 | ) -> Union[str, bytes, Tuple[int, Union[str, bytes], str], AutoInterrupt]:
|
743 | 744 | """Handles executing the command on the shell and consumes and returns
|
@@ -810,7 +811,8 @@ def execute(self,
|
810 | 811 | effects on a repository. For example, stale locks in case of git gc could
|
811 | 812 | render the repository incapable of accepting changes until the lock is manually
|
812 | 813 | removed.
|
813 |
| -
|
| 814 | + :param strip_newline_in_stdout: |
| 815 | + Whether to strip the trailing `\n` of the command stdout. |
814 | 816 | :return:
|
815 | 817 | * str(output) if extended_output = False (Default)
|
816 | 818 | * tuple(int(status), str(stdout), str(stderr)) if extended_output = True
|
@@ -944,7 +946,7 @@ def _kill_process(pid: int) -> None:
|
944 | 946 | if not universal_newlines:
|
945 | 947 | stderr_value = stderr_value.encode(defenc)
|
946 | 948 | # strip trailing "\n"
|
947 |
| - if stdout_value.endswith(newline): # type: ignore |
| 949 | + if stdout_value.endswith(newline) and strip_newline_in_stdout: # type: ignore |
948 | 950 | stdout_value = stdout_value[:-1]
|
949 | 951 | if stderr_value.endswith(newline): # type: ignore
|
950 | 952 | stderr_value = stderr_value[:-1]
|
|
0 commit comments