@@ -759,7 +759,7 @@ async def test_git_show_commit_with_parent(repo: git.Repo):
759759 )
760760 assert show_text (result ) == (
761761 show_header (commit )
762- + "\n --- test.txt\n +++ test.txt\n "
762+ + "\n --- a/ test.txt\n +++ b/ test.txt\n "
763763 + "@@ -1,5 +1,5 @@\n line 1\n line 2\n -line 3\n +SHOWN\n line 4\n line 5\n "
764764 )
765765 text = show_text (result )
@@ -779,7 +779,7 @@ async def test_git_show_multiline_message_is_indented(repo: git.Repo):
779779 result = await call (None , "git_show" , {"repo_path" : str (root ), "revision" : "HEAD" })
780780 text = show_text (result )
781781 assert text .startswith (show_header (commit ))
782- assert "\n \n subject\n \n body line\n \n --- test.txt\n " in text
782+ assert "\n \n subject\n \n body line\n \n --- a/ test.txt\n " in text
783783
784784
785785async def test_git_show_initial_commit_diffs_against_empty_tree (repo : git .Repo ):
@@ -791,7 +791,7 @@ async def test_git_show_initial_commit_diffs_against_empty_tree(repo: git.Repo):
791791 )
792792 assert show_text (result ) == (
793793 show_header (initial )
794- + "\n --- /dev/null\n +++ test.txt\n "
794+ + "\n --- /dev/null\n +++ b/ test.txt\n "
795795 + "@@ -0,0 +1,5 @@\n +line 1\n +line 2\n +line 3\n +line 4\n +line 5\n "
796796 )
797797
@@ -804,11 +804,35 @@ async def test_git_show_deleted_file_diffs_to_dev_null(repo: git.Repo):
804804 )
805805 assert show_text (result ) == (
806806 show_header (commit )
807- + "\n --- test.txt\n +++ /dev/null\n "
807+ + "\n --- a/ test.txt\n +++ /dev/null\n "
808808 + "@@ -1,5 +0,0 @@\n -line 1\n -line 2\n -line 3\n -line 4\n -line 5\n "
809809 )
810810
811811
812+ async def test_git_show_patch_applies_with_git_apply (repo : git .Repo ):
813+ # The a/ and b/ prefixes make the output a patch `git apply` accepts as
814+ # is: without them its default -p1 strips `logic/` from a nested path
815+ # (#5107). Reverse-applying the commit's own patch must check clean.
816+ root = root_of (repo )
817+ (root / "logic" ).mkdir ()
818+ (root / "logic" / "a.py" ).write_bytes (b"x = 1\n " )
819+ repo .index .add (["logic/a.py" ])
820+ repo .index .commit ("add logic/a.py" )
821+ (root / "logic" / "a.py" ).write_bytes (b"x = 2\n " )
822+ repo .index .add (["logic/a.py" ])
823+ commit = repo .index .commit ("change logic/a.py" )
824+ result = await call (None , "git_show" , {"repo_path" : str (root ), "revision" : "HEAD" })
825+ text = show_text (result )
826+ assert text == (
827+ show_header (commit )
828+ + "\n --- a/logic/a.py\n +++ b/logic/a.py\n "
829+ + "@@ -1 +1 @@\n -x = 1\n +x = 2\n "
830+ )
831+ patch_file = root .parent / "show.patch"
832+ patch_file .write_bytes (text .encode ())
833+ repo .git .apply ("-R" , "--check" , str (patch_file ))
834+
835+
812836async def test_git_show_rename_only_commit_has_header_and_no_patch (repo : git .Repo ):
813837 # A pure rename yields a diff entry whose patch is empty bytes.
814838 repo .index .move (["test.txt" , "renamed.txt" ])
@@ -817,7 +841,7 @@ async def test_git_show_rename_only_commit_has_header_and_no_patch(repo: git.Rep
817841 None , "git_show" , {"repo_path" : str (root_of (repo )), "revision" : "HEAD" }
818842 )
819843 assert show_text (result ) == (
820- show_header (commit ) + "\n --- test.txt\n +++ renamed.txt\n "
844+ show_header (commit ) + "\n --- a/ test.txt\n +++ b/ renamed.txt\n "
821845 )
822846
823847
@@ -829,7 +853,7 @@ async def test_git_show_binary_commit(repo: git.Repo):
829853 result = await call (None , "git_show" , {"repo_path" : str (root ), "revision" : "HEAD" })
830854 assert show_text (result ) == (
831855 show_header (commit )
832- + "\n --- /dev/null\n +++ blob.bin\n "
856+ + "\n --- /dev/null\n +++ b/ blob.bin\n "
833857 + "Binary files /dev/null and b/blob.bin differ\n "
834858 )
835859
@@ -844,7 +868,7 @@ async def test_git_show_non_utf8_patch_is_decoded_with_replacement(repo: git.Rep
844868 result = await call (None , "git_show" , {"repo_path" : str (root ), "revision" : "HEAD" })
845869 assert show_text (result ) == (
846870 show_header (commit )
847- + "\n --- /dev/null\n +++ latin.txt\n "
871+ + "\n --- /dev/null\n +++ b/ latin.txt\n "
848872 + "@@ -0,0 +1 @@\n +caf\ufffd \n "
849873 )
850874
0 commit comments