Closed
Description
The result of git.Git.show (...) misses newlines ("\n") at the end of a file.
Reproduction
- setup git repo / use existing
- add empty textfile "foo.txt", commit file
- modify file by inserting string "foo\r\n", commit changes
- run git cmd "show [commit sha]:foo.txt"
- ... via GitPython, example:
# commits = ...
repo.git.show(f"{commits[0].hexsha}:{testfile}")
- ... from Git terminal, pipe through cat etc. to see control characters, example:
git show 74e70e7:foo.txt | cat -vet | less
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"
# commits = ... p = subprocess.Popen(["git", "show", f"{commits[0].hexsha}:{testfile}"], stdout=subprocess.PIPE) out, err = p.communicate() print(repr(out))