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

git show result misses newline at end of diff #1377

Open
markhh80 opened this issue Nov 12, 2021 · 1 comment
Open

git show result misses newline at end of diff #1377

markhh80 opened this issue Nov 12, 2021 · 1 comment

Comments

@markhh80
Copy link

@markhh80 markhh80 commented Nov 12, 2021

The result of git.Git.show (...) misses newlines ("\n") at the end of a file.

Reproduction

  1. setup git repo / use existing
  2. add empty textfile "foo.txt", commit file
  3. modify file by inserting string "foo\r\n", commit changes
  4. run git cmd "show [commit sha]:foo.txt"
  5. ... via GitPython, example:
# commits = ...
repo.git.show(f"{commits[0].hexsha}:{testfile}")
  1. ... 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))
    
@Byron
Copy link
Member

@Byron Byron commented Nov 13, 2021

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 git output somewhere in its command execution machinery, and I wonder why it was added in the first place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants