Skip to content

Commit a83c2d2

Browse files
committed
Merge branch 'da/difftool-dir-diff-fix' into da/t7800-cleanup
* da/difftool-dir-diff-fix: difftool: fix dir-diff index creation when in a subdirectory
2 parents e66adca + 853e10c commit a83c2d2

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

contrib/examples/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
@@ -386,6 +386,7 @@ test_expect_success 'setup change in subdirectory' '
386386
echo master >sub/sub &&
387387
git add sub/sub &&
388388
git commit -m "added sub/sub" &&
389+
git tag v1 &&
389390
echo test >>file &&
390391
echo test >>sub/sub &&
391392
git add file sub/sub &&
@@ -421,12 +422,49 @@ run_dir_diff_test 'difftool --dir-diff ignores --prompt' '
421422
grep file output
422423
'
423424

424-
run_dir_diff_test 'difftool --dir-diff from subdirectory' '
425+
run_dir_diff_test 'difftool --dir-diff branch from subdirectory' '
425426
(
426427
cd sub &&
427428
git difftool --dir-diff $symlinks --extcmd ls branch >output &&
428-
grep sub output &&
429-
grep file output
429+
# "sub" must only exist in "right"
430+
# "file" and "file2" must be listed in both "left" and "right"
431+
test "1" = $(grep sub output | wc -l) &&
432+
test "2" = $(grep file"$" output | wc -l) &&
433+
test "2" = $(grep file2 output | wc -l)
434+
)
435+
'
436+
437+
run_dir_diff_test 'difftool --dir-diff v1 from subdirectory' '
438+
(
439+
cd sub &&
440+
git difftool --dir-diff $symlinks --extcmd ls v1 >output &&
441+
# "sub" and "file" exist in both v1 and HEAD.
442+
# "file2" is unchanged.
443+
test "2" = $(grep sub output | wc -l) &&
444+
test "2" = $(grep file output | wc -l) &&
445+
test "0" = $(grep file2 output | wc -l)
446+
)
447+
'
448+
449+
run_dir_diff_test 'difftool --dir-diff branch from subdirectory w/ pathspec' '
450+
(
451+
cd sub &&
452+
git difftool --dir-diff $symlinks --extcmd ls branch -- .>output &&
453+
# "sub" only exists in "right"
454+
# "file" and "file2" must not be listed
455+
test "1" = $(grep sub output | wc -l) &&
456+
test "0" = $(grep file output | wc -l)
457+
)
458+
'
459+
460+
run_dir_diff_test 'difftool --dir-diff v1 from subdirectory w/ pathspec' '
461+
(
462+
cd sub &&
463+
git difftool --dir-diff $symlinks --extcmd ls v1 -- .>output &&
464+
# "sub" exists in v1 and HEAD
465+
# "file" is filtered out by the pathspec
466+
test "2" = $(grep sub output | wc -l) &&
467+
test "0" = $(grep file output | wc -l)
430468
)
431469
'
432470

0 commit comments

Comments
 (0)