Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ def diff(
# END paths handling

kwargs["as_process"] = True
proc = diff_cmd(*self._process_diff_args(args), **kwargs)
args = self._process_diff_args(args)
if create_patch:
self.repo.git(c="diff.mnemonicPrefix=false")
proc = diff_cmd(*args, **kwargs)

diff_method = Diff._index_from_patch_format if create_patch else Diff._index_from_raw_format
index = diff_method(self.repo, proc)
Expand Down
2 changes: 2 additions & 0 deletions git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,8 @@ def diff(
args.extend(paths)

kwargs["as_process"] = True
if create_patch:
self.repo.git(c="diff.mnemonicPrefix=false")
proc = self.repo.git.diff(*args, **kwargs)

diff_method = (
Expand Down
20 changes: 20 additions & 0 deletions test/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ def test_diff_with_staged_file(self, rw_dir):
"This should work, but doesn't right now ... it's OK",
)

@with_rw_directory
def test_patch_diff_ignores_mnemonic_prefix(self, rw_dir):
repo = Repo.init(rw_dir)
filepath = osp.join(rw_dir, "file.txt")
with open(filepath, "w") as stream:
stream.write("initial\n")
repo.index.add([filepath])
repo.index.commit("initial")

with open(filepath, "w") as stream:
stream.write("changed\n")
repo.git.config("diff.mnemonicPrefix", "true")

self.assertEqual(len(repo.head.commit.diff(None, create_patch=True)), 1)
self.assertEqual(len(repo.index.diff(None, create_patch=True)), 1)

repo.index.add([filepath])
self.assertEqual(len(repo.index.diff(NULL_TREE, create_patch=True)), 1)
self.assertEqual(repo.git.config("--get", "diff.mnemonicPrefix"), "true")

def test_list_from_string_new_mode(self):
output = StringProcessAdapter(fixture("diff_new_mode"))
diffs = Diff._index_from_patch_format(self.rorepo, output)
Expand Down
Loading