diff --git a/git/diff.py b/git/diff.py index 24f79681a..3628c815a 100644 --- a/git/diff.py +++ b/git/diff.py @@ -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) diff --git a/git/index/base.py b/git/index/base.py index 8d7dbfc1f..a9b66ad2b 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -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 = ( diff --git a/test/test_diff.py b/test/test_diff.py index a395f4a44..7f2275f55 100644 --- a/test/test_diff.py +++ b/test/test_diff.py @@ -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)