Skip to content

Commit 366f9ce

Browse files
davvidgitster
authored andcommitted
difftool: handle unmerged files in dir-diff mode
When files are unmerged they can show up as both unmerged and modified in the output of `git diff --raw`. This causes difftool's dir-diff to create filesystem entries for the same path twice, which fails when it encounters a duplicate path. Ensure that each worktree path is only processed once. Add a test to demonstrate the breakage. Reported-by: Jan Smets <[email protected]> Signed-off-by: David Aguilar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 951b551 commit 366f9ce

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

git-difftool.perl

+5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ sub setup_dir_diff
138138
my %submodule;
139139
my %symlink;
140140
my @working_tree = ();
141+
my %working_tree_dups = ();
141142
my @rawdiff = split('\0', $diffrtn);
142143

143144
my $i = 0;
@@ -188,6 +189,10 @@ sub setup_dir_diff
188189
}
189190

190191
if ($rmode ne $null_mode) {
192+
# Avoid duplicate working_tree entries
193+
if ($working_tree_dups{$dst_path}++) {
194+
next;
195+
}
191196
my ($use, $wt_sha1) = use_wt_file($repo, $workdir,
192197
$dst_path, $rsha1);
193198
if ($use) {

t/t7800-difftool.sh

+23
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,29 @@ run_dir_diff_test 'difftool --dir-diff when worktree file is missing' '
419419
grep file2 output
420420
'
421421

422+
run_dir_diff_test 'difftool --dir-diff with unmerged files' '
423+
test_when_finished git reset --hard &&
424+
test_config difftool.echo.cmd "echo ok" &&
425+
git checkout -B conflict-a &&
426+
git checkout -B conflict-b &&
427+
git checkout conflict-a &&
428+
echo a >>file &&
429+
git add file &&
430+
git commit -m conflict-a &&
431+
git checkout conflict-b &&
432+
echo b >>file &&
433+
git add file &&
434+
git commit -m conflict-b &&
435+
git checkout master &&
436+
git merge conflict-a &&
437+
test_must_fail git merge conflict-b &&
438+
cat >expect <<-EOF &&
439+
ok
440+
EOF
441+
git difftool --dir-diff $symlinks -t echo >actual &&
442+
test_cmp expect actual
443+
'
444+
422445
write_script .git/CHECK_SYMLINKS <<\EOF
423446
for f in file file2 sub/sub
424447
do

0 commit comments

Comments
 (0)