Skip to content

Commit fcd35cf

Browse files
authored
Merge pull request #2191 from pick7/codex/disable-mnemonic-prefix
Use standard prefixes for parsed patch diffs
2 parents 56e3f88 + ee854dc commit fcd35cf

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

git/diff.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,10 @@ def diff(
284284
# END paths handling
285285

286286
kwargs["as_process"] = True
287-
proc = diff_cmd(*self._process_diff_args(args), **kwargs)
287+
args = self._process_diff_args(args)
288+
if create_patch:
289+
self.repo.git(c="diff.mnemonicPrefix=false")
290+
proc = diff_cmd(*args, **kwargs)
288291

289292
diff_method = Diff._index_from_patch_format if create_patch else Diff._index_from_raw_format
290293
index = diff_method(self.repo, proc)

git/index/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,8 @@ def diff(
15471547
args.extend(paths)
15481548

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

15521554
diff_method = (

test/test_diff.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@ def test_diff_with_staged_file(self, rw_dir):
9292
"This should work, but doesn't right now ... it's OK",
9393
)
9494

95+
@with_rw_directory
96+
def test_patch_diff_ignores_mnemonic_prefix(self, rw_dir):
97+
repo = Repo.init(rw_dir)
98+
filepath = osp.join(rw_dir, "file.txt")
99+
with open(filepath, "w") as stream:
100+
stream.write("initial\n")
101+
repo.index.add([filepath])
102+
repo.index.commit("initial")
103+
104+
with open(filepath, "w") as stream:
105+
stream.write("changed\n")
106+
repo.git.config("diff.mnemonicPrefix", "true")
107+
108+
self.assertEqual(len(repo.head.commit.diff(None, create_patch=True)), 1)
109+
self.assertEqual(len(repo.index.diff(None, create_patch=True)), 1)
110+
111+
repo.index.add([filepath])
112+
self.assertEqual(len(repo.index.diff(NULL_TREE, create_patch=True)), 1)
113+
self.assertEqual(repo.git.config("--get", "diff.mnemonicPrefix"), "true")
114+
95115
def test_list_from_string_new_mode(self):
96116
output = StringProcessAdapter(fixture("diff_new_mode"))
97117
diffs = Diff._index_from_patch_format(self.rorepo, output)

0 commit comments

Comments
 (0)