threads / patch / 44627

patchdifftool: fix dir-diff index creation when in a subdirectory

Subject: [PATCH] difftool: fix dir-diff index creation when in a subdirectory

## tl;dr

2 messages between Dec 5, 2016 and Dec 6, 2016. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

David Aguilar· Dec 5, 2016, 22:26 UTC · lore

9ec26e797781239b36ebccb87c590e5778358007 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.

Adjust the test cases to more thoroughly exercise this scenario.
Reported-by: Frank Becker <fb@mooflu.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
---
I figured I'd send this as a proper patch.
The patch contents have not changed since the original in-thread
patch, but the commit message was modified slightly.
 git-difftool.perl   | 4 ++++
 t/t7800-difftool.sh | 7 +++++--
 2 files changed, 9 insertions(+), 2 deletions(-)
Show changes to 2 files +9 −2

git-difftool.perl, t/t7800-difftool.sh

diff --git a/git-difftool.perl b/git-difftool.perl
index a5790d03a..959822d5f 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -182,6 +182,10 @@ EOF
 		}
 	}
 
+	# 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";
diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index 70a2de461..caab4b5ca 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -413,8 +413,11 @@ run_dir_diff_test 'difftool --dir-diff 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)
 	)
 '
 
-- 
2.11.0
Johannes Schindelin· Dec 6, 2016, 13:46 UTC · re: David Aguilar · lore

Re: [PATCH] difftool: fix dir-diff index creation when in a subdirectory

Hi David,
On Mon, 5 Dec 2016, David Aguilar wrote:
> 9ec26e797781239b36ebccb87c590e5778358007 corrected how path arguments

How about using the "whatis" instead, i.e. "9ec26e7977 (difftool: fix argument handling in subdirs, 2016-07-18)"?

Ciao, Dscho

← back to recent threads