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

feat(cmd): add thestrip_newline flag#1423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsAUTHORS
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,4 +45,5 @@ Contributors are:
-Alba Mendez <me _at_ alba.sh>
-Robert Westman <robert _at_ byteflux.io>
-Hugo van Kemenade
-Hiroki Tokunaga <tokusan441 _at_ gmail.com>
Portions derived from other open source works and are clearly marked.
8 changes: 5 additions & 3 deletionsgit/cmd.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -55,7 +55,7 @@
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())
Expand DownExpand Up@@ -738,6 +738,7 @@ def execute(self,
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
Expand DownExpand Up@@ -810,7 +811,8 @@ def execute(self,
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
Expand DownExpand Up@@ -944,7 +946,7 @@ def _kill_process(pid: int) -> None:
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]
Expand Down
10 changes: 10 additions & 0 deletionstest/test_repo.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1098,3 +1098,13 @@ def test_rebasing(self, rw_dir):
except GitCommandError:
pass
self.assertEqual(r.currently_rebasing_on(), commitSpanish)

@with_rw_directory
def test_do_not_strip_newline_in_stdout(self, rw_dir):
r = Repo.init(rw_dir)
fp = osp.join(rw_dir, 'hello.txt')
with open(fp, 'w') as fs:
fs.write("hello\n")
r.git.add(Git.polish_url(fp))
r.git.commit(message="init")
self.assertEqual(r.git.show("HEAD:hello.txt", strip_newline_in_stdout=False), 'hello\n')

[8]ページ先頭

©2009-2025 Movatter.jp