Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6ed2285

Browse files
authored
Merge pull requestgitpython-developers#1551 from mellowed100/main
Enable user to override default diff -M arg
2 parents63a60b3 +c0e69a4 commit6ed2285

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

‎git/diff.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ def diff(
144144
args.append("--abbrev=40")# we need full shas
145145
args.append("--full-index")# get full index paths, not only filenames
146146

147-
args.append("-M")# check for renames, in both formats
147+
# remove default '-M' arg (check for renames) if user is overriding it
148+
ifnotany(xinkwargsforxin ('find_renames','no_renames','M')):
149+
args.append("-M")
150+
148151
ifcreate_patch:
149152
args.append("-p")
150153
else:

‎test/test_diff.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,73 @@ def test_diff_interface(self):
411411
cp=c.parents[0]
412412
diff_index=c.diff(cp, ["does/not/exist"])
413413
self.assertEqual(len(diff_index),0)
414+
415+
@with_rw_directory
416+
deftest_rename_override(self,rw_dir):
417+
"""Test disabling of diff rename detection"""
418+
419+
# create and commit file_a.txt
420+
repo=Repo.init(rw_dir)
421+
file_a=osp.join(rw_dir,"file_a.txt")
422+
withopen(file_a,"w",encoding='utf-8')asoutfile:
423+
outfile.write("hello world\n")
424+
repo.git.add(Git.polish_url(file_a))
425+
repo.git.commit(message="Added file_a.txt")
426+
427+
# remove file_a.txt
428+
repo.git.rm(Git.polish_url(file_a))
429+
430+
# create and commit file_b.txt with similarity index of 52
431+
file_b=osp.join(rw_dir,"file_b.txt")
432+
withopen(file_b,"w",encoding='utf-8')asoutfile:
433+
outfile.write("hello world\nhello world")
434+
repo.git.add(Git.polish_url(file_b))
435+
repo.git.commit(message="Removed file_a.txt. Added file_b.txt")
436+
437+
commit_a=repo.commit('HEAD')
438+
commit_b=repo.commit('HEAD~1')
439+
440+
# check default diff command with renamed files enabled
441+
diffs=commit_b.diff(commit_a)
442+
self.assertEqual(1,len(diffs))
443+
diff=diffs[0]
444+
self.assertEqual(True,diff.renamed_file)
445+
self.assertEqual('file_a.txt',diff.rename_from)
446+
self.assertEqual('file_b.txt',diff.rename_to)
447+
448+
# check diff with rename files disabled
449+
diffs=commit_b.diff(commit_a,no_renames=True)
450+
self.assertEqual(2,len(diffs))
451+
452+
# check fileA.txt deleted
453+
diff=diffs[0]
454+
self.assertEqual(True,diff.deleted_file)
455+
self.assertEqual('file_a.txt',diff.a_path)
456+
457+
# check fileB.txt added
458+
diff=diffs[1]
459+
self.assertEqual(True,diff.new_file)
460+
self.assertEqual('file_b.txt',diff.a_path)
461+
462+
# check diff with high similarity index
463+
diffs=commit_b.diff(commit_a,split_single_char_options=False,M='75%')
464+
self.assertEqual(2,len(diffs))
465+
466+
# check fileA.txt deleted
467+
diff=diffs[0]
468+
self.assertEqual(True,diff.deleted_file)
469+
self.assertEqual('file_a.txt',diff.a_path)
470+
471+
# check fileB.txt added
472+
diff=diffs[1]
473+
self.assertEqual(True,diff.new_file)
474+
self.assertEqual('file_b.txt',diff.a_path)
475+
476+
# check diff with low similarity index
477+
diffs=commit_b.diff(commit_a,split_single_char_options=False,M='40%')
478+
self.assertEqual(1,len(diffs))
479+
diff=diffs[0]
480+
self.assertEqual(True,diff.renamed_file)
481+
self.assertEqual('file_a.txt',diff.rename_from)
482+
self.assertEqual('file_b.txt',diff.rename_to)
483+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp