Skip to content

Commit 87b8035

Browse files
authored
Merge pull request #1832 from can-taslicukur/can.1828
Make sure diff always uses the default diff driver when `create_patch=True`
2 parents fe1934c + 5d6c86a commit 87b8035

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

git/diff.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def diff(
155155

156156
if create_patch:
157157
args.append("-p")
158+
args.append("--no-ext-diff")
158159
else:
159160
args.append("--raw")
160161
args.append("-z")

test/test_diff.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,45 @@ def test_rename_override(self, rw_dir):
473473
self.assertEqual(True, diff.renamed_file)
474474
self.assertEqual("file_a.txt", diff.rename_from)
475475
self.assertEqual("file_b.txt", diff.rename_to)
476+
477+
@with_rw_directory
478+
def test_diff_patch_with_external_engine(self, rw_dir):
479+
repo = Repo.init(rw_dir)
480+
gitignore = osp.join(rw_dir, ".gitignore")
481+
482+
# First commit
483+
with open(gitignore, "w") as f:
484+
f.write("first_line\n")
485+
repo.git.add(".gitignore")
486+
repo.index.commit("first commit")
487+
488+
# Adding second line and committing
489+
with open(gitignore, "a") as f:
490+
f.write("second_line\n")
491+
repo.git.add(".gitignore")
492+
repo.index.commit("second commit")
493+
494+
# Adding third line and staging
495+
with open(gitignore, "a") as f:
496+
f.write("third_line\n")
497+
repo.git.add(".gitignore")
498+
499+
# Adding fourth line
500+
with open(gitignore, "a") as f:
501+
f.write("fourth_line\n")
502+
503+
# Set the external diff engine
504+
with repo.config_writer(config_level="repository") as writer:
505+
writer.set_value("diff", "external", "bogus_diff_engine")
506+
507+
head_against_head = repo.head.commit.diff("HEAD^", create_patch=True)
508+
self.assertEqual(len(head_against_head), 1)
509+
head_against_index = repo.head.commit.diff(create_patch=True)
510+
self.assertEqual(len(head_against_index), 1)
511+
head_against_working_tree = repo.head.commit.diff(None, create_patch=True)
512+
self.assertEqual(len(head_against_working_tree), 1)
513+
514+
index_against_head = repo.index.diff("HEAD", create_patch=True)
515+
self.assertEqual(len(index_against_head), 1)
516+
index_against_working_tree = repo.index.diff(None, create_patch=True)
517+
self.assertEqual(len(index_against_working_tree), 1)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy