|
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'} |
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: 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,6 +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. |
| 814 | + :param strip_newline: |
| 815 | + Whether to strip the trailing '\n' of the command output. |
813 | 816 |
|
814 | 817 | :return: |
815 | 818 | * str(output) if extended_output = False (Default) |
@@ -944,7 +947,7 @@ def _kill_process(pid: int) -> None: |
944 | 947 | if not universal_newlines: |
945 | 948 | stderr_value = stderr_value.encode(defenc) |
946 | 949 | # strip trailing "\n" |
947 | | - if stdout_value.endswith(newline): # type: ignore |
| 950 | + if stdout_value.endswith(newline) and strip_newline: # type: ignore |
948 | 951 | stdout_value = stdout_value[:-1] |
949 | 952 | if stderr_value.endswith(newline): # type: ignore |
950 | 953 | stderr_value = stderr_value[:-1] |
|
0 commit comments