Skip to content

Commit 389c328

Browse files
committed
Merge branch 'da/difftool' into maint
"git difftool" learned to handle unmerged paths correctly in dir-diff mode. * da/difftool: difftool: handle unmerged files in dir-diff mode difftool: initialize variables for readability
2 parents 7dcbf89 + 366f9ce commit 389c328

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

git-difftool.perl

+7-2
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) {
@@ -273,7 +278,7 @@ sub setup_dir_diff
273278
# temporary file to both the left and right directories to show the
274279
# change in the recorded SHA1 for the submodule.
275280
for my $path (keys %submodule) {
276-
my $ok;
281+
my $ok = 0;
277282
if (defined($submodule{$path}{left})) {
278283
$ok = write_to_file("$ldir/$path",
279284
"Subproject commit $submodule{$path}{left}");
@@ -289,7 +294,7 @@ sub setup_dir_diff
289294
# shows only the link itself, not the contents of the link target.
290295
# This loop replicates that behavior.
291296
for my $path (keys %symlink) {
292-
my $ok;
297+
my $ok = 0;
293298
if (defined($symlink{$path}{left})) {
294299
$ok = write_to_file("$ldir/$path",
295300
$symlink{$path}{left});

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)