-
-
Notifications
You must be signed in to change notification settings - Fork 918
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
git show result misses newline at end of diff #1377
Comments
Thanks a lot for the wonderful description of the issue and for spending the time that undoubtedly when into it. It's likely that GitPython strips |
Hello, I've also encountered this problem (see my SO question and the answer). I found the line where GitPython strips the last Lines 946 to 948 in 0b33576
The test below fails for the current main branch, and succeeds after removing [:-1] .
@with_rw_directory
def test_git_show_last_newline(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"), 'hello\n') The last
I'd like to send a PR to resolve this issue, so could you tell me your intention toward this? |
Thanks a lot for contributing a test and additional analysis, @toku-sa-n, I'd love to see this culminate in a PR. Here are my thoughts:
This would be a potentially breaking change even though it would certainly be the correct way to do it.
This would require a parameter to be added to Providing a means to alleviate this seems like the minimum action to perform here. If it's never desirable to strip newlines for binary output it might be possible to detect if something is binary by looking at the first 1024 bytes or so of the output and avoid stripping newlines then. There is probably a package for that, similar to the Thanks everyone. |
Adding a flag and keeping the default as Will you accept a PR to toggle the default for Will you accept a PR to fire a deprecation warning if it's I'm speaking fro personal pain here: I just encountered a vendor-provided codebase that failed on some edge case in git show, and examining the issue I noticed they used GitPython for everything except |
Please feel free to submit a PR, ideally with an accompanying test to show what it's doing. Breaking changes can't be done though. |
The result of git.Git.show (...) misses newlines ("\n") at the end of a file.
Reproduction
Observation
The string returned from show via GitPython has a trailing "\r", missing the "\n". The result from terminal execution has a trailing "\r\n".
Expected
Both outputs have the correct trailing "\r\n".
Addendum
run GitPython cmd with option "with_extended_output" -> same result
run GitPython cmd with option "stdout_as_string" -> same result (but in binary format)
crosscheck: run "git show" via subprocess.popen -> output has correct "\r\n"
The text was updated successfully, but these errors were encountered: