Skip to content

Commit 853e10c

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 0202c41 commit 853e10c

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
@@ -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)