Skip to content

git show result misses newline at end of diff #1377

Closed
@markhh80

Description

@markhh80

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))
    

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions