diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2022-04-07 10:49:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-07 10:49:02 +0800 |
commit | d5cee4a467a0ab543c0a118cc763ad3a54b8fc69 (patch) | |
tree | baeb3728921f7b2d4b0f5e3e45288870ab242ab8 /git/cmd.py | |
parent | 0b33576f8e7add5671f8927dff228e7f92eec076 (diff) | |
parent | 17b2b128fb6d6f987b47d60ccb1ab09b8fc238ea (diff) | |
download | gitpython-d5cee4a467a0ab543c0a118cc763ad3a54b8fc69.tar.gz |
Merge pull request #1423 from toku-sa-n/strip_newline_option
feat(cmd): add the `strip_newline` flag
Diffstat (limited to 'git/cmd.py')
-rw-r--r-- | git/cmd.py | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -55,7 +55,7 @@ if TYPE_CHECKING: execute_kwargs = {'istream', 'with_extended_output', 'with_exceptions', 'as_process', 'stdout_as_string', 'output_stream', 'with_stdout', 'kill_after_timeout', - 'universal_newlines', 'shell', 'env', 'max_chunk_size'} + 'universal_newlines', 'shell', 'env', 'max_chunk_size', 'strip_newline_in_stdout'} log = logging.getLogger(__name__) log.addHandler(logging.NullHandler()) @@ -738,6 +738,7 @@ class Git(LazyMixin): shell: Union[None, bool] = None, env: Union[None, Mapping[str, str]] = None, max_chunk_size: int = io.DEFAULT_BUFFER_SIZE, + strip_newline_in_stdout: bool = True, **subprocess_kwargs: Any ) -> Union[str, bytes, Tuple[int, Union[str, bytes], str], AutoInterrupt]: """Handles executing the command on the shell and consumes and returns @@ -810,7 +811,8 @@ class Git(LazyMixin): effects on a repository. For example, stale locks in case of git gc could render the repository incapable of accepting changes until the lock is manually removed. - + :param strip_newline_in_stdout: + Whether to strip the trailing `\n` of the command stdout. :return: * str(output) if extended_output = False (Default) * tuple(int(status), str(stdout), str(stderr)) if extended_output = True @@ -944,7 +946,7 @@ class Git(LazyMixin): if not universal_newlines: stderr_value = stderr_value.encode(defenc) # strip trailing "\n" - if stdout_value.endswith(newline): # type: ignore + if stdout_value.endswith(newline) and strip_newline_in_stdout: # type: ignore stdout_value = stdout_value[:-1] if stderr_value.endswith(newline): # type: ignore stderr_value = stderr_value[:-1] |