Skip to content

Commit afe0e2a

Browse files
committed
Merge branch 'da/difftool-dir-diff-fix'
"git difftool --dir-diff" had a minor regression when started from a subdirectory, which has been fixed. * da/difftool-dir-diff-fix: difftool: fix dir-diff index creation when in a subdirectory
2 parents c89606f + 853e10c commit afe0e2a

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

git-difftool.perl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ sub setup_dir_diff
182182
}
183183
}
184184

185+
# Go to the root of the worktree so that the left index files
186+
# are properly setup -- the index is toplevel-relative.
187+
chdir($workdir);
188+
185189
# Setup temp directories
186190
my $tmpdir = tempdir('git-difftool.XXXXX', CLEANUP => 0, TMPDIR => 1);
187191
my $ldir = "$tmpdir/left";

t/t7800-difftool.sh

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ test_expect_success PERL 'setup change in subdirectory' '
374374
echo master >sub/sub &&
375375
git add sub/sub &&
376376
git commit -m "added sub/sub" &&
377+
git tag v1 &&
377378
echo test >>file &&
378379
echo test >>sub/sub &&
379380
git add file sub/sub &&
@@ -409,12 +410,49 @@ run_dir_diff_test 'difftool --dir-diff ignores --prompt' '
409410
grep file output
410411
'
411412

412-
run_dir_diff_test 'difftool --dir-diff from subdirectory' '
413+
run_dir_diff_test 'difftool --dir-diff branch from subdirectory' '
413414
(
414415
cd sub &&
415416
git difftool --dir-diff $symlinks --extcmd ls branch >output &&
416-
grep sub output &&
417-
grep file output
417+
# "sub" must only exist in "right"
418+
# "file" and "file2" must be listed in both "left" and "right"
419+
test "1" = $(grep sub output | wc -l) &&
420+
test "2" = $(grep file"$" output | wc -l) &&
421+
test "2" = $(grep file2 output | wc -l)
422+
)
423+
'
424+
425+
run_dir_diff_test 'difftool --dir-diff v1 from subdirectory' '
426+
(
427+
cd sub &&
428+
git difftool --dir-diff $symlinks --extcmd ls v1 >output &&
429+
# "sub" and "file" exist in both v1 and HEAD.
430+
# "file2" is unchanged.
431+
test "2" = $(grep sub output | wc -l) &&
432+
test "2" = $(grep file output | wc -l) &&
433+
test "0" = $(grep file2 output | wc -l)
434+
)
435+
'
436+
437+
run_dir_diff_test 'difftool --dir-diff branch from subdirectory w/ pathspec' '
438+
(
439+
cd sub &&
440+
git difftool --dir-diff $symlinks --extcmd ls branch -- .>output &&
441+
# "sub" only exists in "right"
442+
# "file" and "file2" must not be listed
443+
test "1" = $(grep sub output | wc -l) &&
444+
test "0" = $(grep file output | wc -l)
445+
)
446+
'
447+
448+
run_dir_diff_test 'difftool --dir-diff v1 from subdirectory w/ pathspec' '
449+
(
450+
cd sub &&
451+
git difftool --dir-diff $symlinks --extcmd ls v1 -- .>output &&
452+
# "sub" exists in v1 and HEAD
453+
# "file" is filtered out by the pathspec
454+
test "2" = $(grep sub output | wc -l) &&
455+
test "0" = $(grep file output | wc -l)
418456
)
419457
'
420458

0 commit comments

Comments
 (0)