Skip to content

Commit 86defcb

Browse files
davvidgitster
authored andcommitted
difftool: fix dir-diff index creation when in a subdirectory
9ec26e7 (difftool: fix argument handling in subdirs, 2016-07-18) corrected how path arguments are handled in a subdirectory, but it introduced a regression in how entries outside of the subdirectory are handled by dir-diff. When preparing the right-side of the diff we only include the changed paths in the temporary area. The left side of the diff is constructed from a temporary index that is built from the same set of changed files, but it was being constructed from within the subdirectory. This is a problem because the indexed paths are toplevel-relative, and thus they were not getting added to the index. Teach difftool to chdir to the toplevel of the repository before preparing its temporary indexes. This ensures that all of the toplevel-relative paths are valid. Add test cases to more thoroughly exercise this scenario. Reported-by: Frank Becker <[email protected]> Signed-off-by: David Aguilar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 32b8c58 commit 86defcb

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

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
@@ -368,6 +368,7 @@ test_expect_success PERL 'setup change in subdirectory' '
368368
echo master >sub/sub &&
369369
git add sub/sub &&
370370
git commit -m "added sub/sub" &&
371+
git tag v1 &&
371372
echo test >>file &&
372373
echo test >>sub/sub &&
373374
git add file sub/sub &&
@@ -403,12 +404,49 @@ run_dir_diff_test 'difftool --dir-diff ignores --prompt' '
403404
grep file output
404405
'
405406

406-
run_dir_diff_test 'difftool --dir-diff from subdirectory' '
407+
run_dir_diff_test 'difftool --dir-diff branch from subdirectory' '
407408
(
408409
cd sub &&
409410
git difftool --dir-diff $symlinks --extcmd ls branch >output &&
410-
grep sub output &&
411-
grep file output
411+
# "sub" must only exist in "right"
412+
# "file" and "file2" must be listed in both "left" and "right"
413+
test "1" = $(grep sub output | wc -l) &&
414+
test "2" = $(grep file"$" output | wc -l) &&
415+
test "2" = $(grep file2 output | wc -l)
416+
)
417+
'
418+
419+
run_dir_diff_test 'difftool --dir-diff v1 from subdirectory' '
420+
(
421+
cd sub &&
422+
git difftool --dir-diff $symlinks --extcmd ls v1 >output &&
423+
# "sub" and "file" exist in both v1 and HEAD.
424+
# "file2" is unchanged.
425+
test "2" = $(grep sub output | wc -l) &&
426+
test "2" = $(grep file output | wc -l) &&
427+
test "0" = $(grep file2 output | wc -l)
428+
)
429+
'
430+
431+
run_dir_diff_test 'difftool --dir-diff branch from subdirectory w/ pathspec' '
432+
(
433+
cd sub &&
434+
git difftool --dir-diff $symlinks --extcmd ls branch -- .>output &&
435+
# "sub" only exists in "right"
436+
# "file" and "file2" must not be listed
437+
test "1" = $(grep sub output | wc -l) &&
438+
test "0" = $(grep file output | wc -l)
439+
)
440+
'
441+
442+
run_dir_diff_test 'difftool --dir-diff v1 from subdirectory w/ pathspec' '
443+
(
444+
cd sub &&
445+
git difftool --dir-diff $symlinks --extcmd ls v1 -- .>output &&
446+
# "sub" exists in v1 and HEAD
447+
# "file" is filtered out by the pathspec
448+
test "2" = $(grep sub output | wc -l) &&
449+
test "0" = $(grep file output | wc -l)
412450
)
413451
'
414452

0 commit comments

Comments
 (0)