Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd): add the strip_newline flag #1423

Merged
merged 5 commits into from
Apr 7, 2022

Conversation

toku-sa-n
Copy link
Contributor

@toku-sa-n toku-sa-n commented Apr 6, 2022

This PR adds the strip_newline flag to the Git.execute method. When this flag is set to True, it will trim the trailing \n. The default value is True for backward compatibility. Setting it to False is helpful for, e.g., the git show output, especially with the binary file, as the missing \n may invalidate the file.

Looking at the first some bytes and checking if the output is binary or not is another option to prevent making an invalid binary file. Still, I chose to add a parameter because it is easy to implement, is fully backward compatible, and doesn't add many lines to the source code.

Fixes: #1377

By the way, do we need to handle stderr too?

This commit adds the `strip_newline` flag to the `Git.execute` method.
When this flag is set to `True`, it will trim the trailing `\n`. The
default value is `True` for backward compatibility. Setting it to
`False` is helpful for, e.g., the `git show` output, especially with the binary
file, as the missing `\n` may invalidate the file.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@Byron Byron added this to the v3.1.28 - Bugfixes milestone Apr 7, 2022
Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the fix!

Regarding stdout/stderr: strip_newline might imply a newline is stripped universally, even though it applies to stdout only at the moment.

Maybe it should be called strip_newline_in_stdout to be specific while allowing to add a similar flag for stderr when there is a need?

PS: CI had issues but after restarting it the error now seems 'legit' (as it is upset about whitespace :/)

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@toku-sa-n toku-sa-n requested a review from Byron April 7, 2022 01:25
Copy link
Member

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, looks great to me!

@Byron Byron merged commit d5cee4a into gitpython-developers:main Apr 7, 2022
@toku-sa-n toku-sa-n deleted the strip_newline_option branch April 7, 2022 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

git show result misses newline at end of diff
2 participants