Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd5cee4a

Browse files
authored
Merge pull request#1423 from toku-sa-n/strip_newline_option
feat(cmd): add the `strip_newline` flag
2 parents0b33576 +17b2b12 commitd5cee4a

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

‎AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ Contributors are:
4545
-Alba Mendez <me _at_ alba.sh>
4646
-Robert Westman <robert _at_ byteflux.io>
4747
-Hugo van Kemenade
48+
-Hiroki Tokunaga <tokusan441 _at_ gmail.com>
4849
Portions derived from other open source works and are clearly marked.

‎git/cmd.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
execute_kwargs= {'istream','with_extended_output',
5656
'with_exceptions','as_process','stdout_as_string',
5757
'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'}
5959

6060
log=logging.getLogger(__name__)
6161
log.addHandler(logging.NullHandler())
@@ -738,6 +738,7 @@ def execute(self,
738738
shell:Union[None,bool]=None,
739739
env:Union[None,Mapping[str,str]]=None,
740740
max_chunk_size:int=io.DEFAULT_BUFFER_SIZE,
741+
strip_newline_in_stdout:bool=True,
741742
**subprocess_kwargs:Any
742743
)->Union[str,bytes,Tuple[int,Union[str,bytes],str],AutoInterrupt]:
743744
"""Handles executing the command on the shell and consumes and returns
@@ -810,7 +811,8 @@ def execute(self,
810811
effects on a repository. For example, stale locks in case of git gc could
811812
render the repository incapable of accepting changes until the lock is manually
812813
removed.
813-
814+
:param strip_newline_in_stdout:
815+
Whether to strip the trailing `\n` of the command stdout.
814816
:return:
815817
* str(output) if extended_output = False (Default)
816818
* tuple(int(status), str(stdout), str(stderr)) if extended_output = True
@@ -944,7 +946,7 @@ def _kill_process(pid: int) -> None:
944946
ifnotuniversal_newlines:
945947
stderr_value=stderr_value.encode(defenc)
946948
# strip trailing "\n"
947-
ifstdout_value.endswith(newline):# type: ignore
949+
ifstdout_value.endswith(newline)andstrip_newline_in_stdout:# type: ignore
948950
stdout_value=stdout_value[:-1]
949951
ifstderr_value.endswith(newline):# type: ignore
950952
stderr_value=stderr_value[:-1]

‎test/test_repo.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,3 +1098,13 @@ def test_rebasing(self, rw_dir):
10981098
exceptGitCommandError:
10991099
pass
11001100
self.assertEqual(r.currently_rebasing_on(),commitSpanish)
1101+
1102+
@with_rw_directory
1103+
deftest_do_not_strip_newline_in_stdout(self,rw_dir):
1104+
r=Repo.init(rw_dir)
1105+
fp=osp.join(rw_dir,'hello.txt')
1106+
withopen(fp,'w')asfs:
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')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp