Skip to content

Commit

Permalink
difftool: fix dir-diff index creation when in a subdirectory
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
davvid authored and gitster committed Dec 8, 2016
1 parent 0202c41 commit 853e10c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
4 changes: 4 additions & 0 deletions git-difftool.perl
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ sub setup_dir_diff
}
}

# Go to the root of the worktree so that the left index files
# are properly setup -- the index is toplevel-relative.
chdir($workdir);

# Setup temp directories
my $tmpdir = tempdir('git-difftool.XXXXX', CLEANUP => 0, TMPDIR => 1);
my $ldir = "$tmpdir/left";
Expand Down
44 changes: 41 additions & 3 deletions t/t7800-difftool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ test_expect_success PERL 'setup change in subdirectory' '
echo master >sub/sub &&
git add sub/sub &&
git commit -m "added sub/sub" &&
git tag v1 &&
echo test >>file &&
echo test >>sub/sub &&
git add file sub/sub &&
Expand Down Expand Up @@ -409,12 +410,49 @@ run_dir_diff_test 'difftool --dir-diff ignores --prompt' '
grep file output
'

run_dir_diff_test 'difftool --dir-diff from subdirectory' '
run_dir_diff_test 'difftool --dir-diff branch from subdirectory' '
(
cd sub &&
git difftool --dir-diff $symlinks --extcmd ls branch >output &&
grep sub output &&
grep file output
# "sub" must only exist in "right"
# "file" and "file2" must be listed in both "left" and "right"
test "1" = $(grep sub output | wc -l) &&
test "2" = $(grep file"$" output | wc -l) &&
test "2" = $(grep file2 output | wc -l)
)
'

run_dir_diff_test 'difftool --dir-diff v1 from subdirectory' '
(
cd sub &&
git difftool --dir-diff $symlinks --extcmd ls v1 >output &&
# "sub" and "file" exist in both v1 and HEAD.
# "file2" is unchanged.
test "2" = $(grep sub output | wc -l) &&
test "2" = $(grep file output | wc -l) &&
test "0" = $(grep file2 output | wc -l)
)
'

run_dir_diff_test 'difftool --dir-diff branch from subdirectory w/ pathspec' '
(
cd sub &&
git difftool --dir-diff $symlinks --extcmd ls branch -- .>output &&
# "sub" only exists in "right"
# "file" and "file2" must not be listed
test "1" = $(grep sub output | wc -l) &&
test "0" = $(grep file output | wc -l)
)
'

run_dir_diff_test 'difftool --dir-diff v1 from subdirectory w/ pathspec' '
(
cd sub &&
git difftool --dir-diff $symlinks --extcmd ls v1 -- .>output &&
# "sub" exists in v1 and HEAD
# "file" is filtered out by the pathspec
test "2" = $(grep sub output | wc -l) &&
test "0" = $(grep file output | wc -l)
)
'

Expand Down

0 comments on commit 853e10c

Please sign in to comment.