| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,4 +45,5 @@ Contributors are: | |||
| 45 | 45 | -Alba Mendez <me _at_ alba.sh> | |
| 46 | 46 | -Robert Westman <robert _at_ byteflux.io> | |
| 47 | 47 | -Hugo van Kemenade | |
| 48 | + -Hiroki Tokunaga <tokusan441 _at_ gmail.com> | ||
| 48 | 49 | Portions derived from other open source works and are clearly marked. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,7 +55,7 @@ | |||
| 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] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1098,3 +1098,13 @@ def test_rebasing(self, rw_dir): | |||
| 1098 | 1098 | except GitCommandError: | |
| 1099 | 1099 | pass | |
| 1100 | 1100 | self.assertEqual(r.currently_rebasing_on(), commitSpanish) | |
| 1101 | + | ||
| 1102 | + @with_rw_directory | ||
| 1103 | + def test_do_not_strip_newline_in_stdout(self, rw_dir): | ||
| 1104 | + r = Repo.init(rw_dir) | ||
| 1105 | + fp = osp.join(rw_dir, 'hello.txt') | ||
| 1106 | + with open(fp, 'w') as fs: | ||
| 1107 | + fs.write("hello\n") | ||
| 1108 | + r.git.add(Git.polish_url(fp)) | ||
| 1109 | + r.git.commit(message="init") | ||
| 1110 | + self.assertEqual(r.git.show("HEAD:hello.txt", strip_newline_in_stdout=False), 'hello\n') | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments