Skip to contentSkip to conversation

difftool -d not populating left correctly when not in git root

DISCUSSION Frank Becker 3 participants 3 messages Dec 2, 2016 – Dec 5, 2016

lore
Share & tools
lore
#0 lore raw

Hi,

looks like this broke between 2.9.2 and 2.9.3

cat ~/.gitconfig
[difftool "diff"]

    cmd = ls -l ${LOCAL}/* ${REMOTE}/*
    #cmd = diff -r ${LOCAL} ${REMOTE} | less

~/stuff/gittest> ls -l *
d1:
total 8
-rw-r--r-- 1 frank staff 16 2 Dec 14:30 test.txt

d2:
total 8
-rw-r--r-- 1 frank staff 18 2 Dec 14:30 anothertest.tst

~/stuff/gittest> git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)

modified: d1/test.txt
modified: d2/anothertest.tst

~/stuff/gittest> ~/stuff/git_tmp/bin/git --version git version 2.11.0

~/stuff/gittest> ~/stuff/git_tmp/bin/git difftool -d -t diff /var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.0oGRF/left/d1:
total 8
-rw-r--r-- 1 frank staff 6 2 Dec 14:52 test.txt

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.0oGRF/left/d2:
total 8
-rw-r--r-- 1 frank staff 7 2 Dec 14:52 anothertest.tst

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.0oGRF/right/d1:
total 8
lrwxr-xr-x 1 frank staff 38 2 Dec 14:52 test.txt -> /Users/frank/stuff/gittest/d1/test.txt

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.0oGRF/right/d2:
total 8
lrwxr-xr-x 1 frank staff 45 2 Dec 14:52 anothertest.tst -> /Users/frank/stuff/gittest/d2/anothertest.tst

cd d2
~/stuff/gittest/d2> ~/stuff/git_tmp/bin/git difftool -d -t diff /var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.eRXhB/left/d2:
total 8
-rw-r--r-- 1 frank staff 7 2 Dec 14:52 anothertest.tst

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.eRXhB/right/d1:
total 8
lrwxr-xr-x 1 frank staff 38 2 Dec 14:52 test.txt -> /Users/frank/stuff/gittest/d1/test.txt

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.eRXhB/right/d2:
total 8
lrwxr-xr-x 1 frank staff 45 2 Dec 14:52 anothertest.tst -> /Users/frank/stuff/gittest/d2/anothertest.tst

Note that left does not contain d1

~/stuff/gittest/d2> ~/stuff/git_tmp/bin/git --version
git version 2.9.2
~/stuff/gittest/d2> ~/stuff/git_tmp/bin/git difftool -d -t diff /var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.YxtVw/left/d1:
total 8
-rw-r--r-- 1 frank staff 6 2 Dec 15:02 test.txt

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.YxtVw/left/d2:
total 8
-rw-r--r-- 1 frank staff 7 2 Dec 15:02 anothertest.tst

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.YxtVw/right/d1:
total 8
lrwxr-xr-x 1 frank staff 38 2 Dec 15:02 test.txt -> /Users/frank/stuff/gittest/d1/test.txt

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.YxtVw/right/d2:
total 8
lrwxr-xr-x 1 frank staff 45 2 Dec 15:02 anothertest.tst -> /Users/frank/stuff/gittest/d2/anothertest.tst

~/stuff/gittest/d2> ~/stuff/git_tmp/bin/git --version
git version 2.9.3
~/stuff/gittest/d2> ~/stuff/git_tmp/bin/git difftool -d -t diff /var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.TpJ5u/left/d2:
total 8
-rw-r--r-- 1 frank staff 7 2 Dec 15:01 anothertest.tst

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.TpJ5u/right/d1:
total 8
lrwxr-xr-x 1 frank staff 38 2 Dec 15:01 test.txt -> /Users/frank/stuff/gittest/d1/test.txt

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.TpJ5u/right/d2:
total 8
lrwxr-xr-x 1 frank staff 45 2 Dec 15:01 anothertest.tst -> /Users/frank/stuff/gittest/d2/anothertest.tst

Cheers,
Frank.

#1 lore raw
Quoted 108 lines · Frank Becker

Hi,

looks like this broke between 2.9.2 and 2.9.3

cat ~/.gitconfig
[difftool "diff"]

    cmd = ls -l ${LOCAL}/* ${REMOTE}/*
    #cmd = diff -r ${LOCAL} ${REMOTE} | less

~/stuff/gittest> ls -l *
d1:
total 8
-rw-r--r-- 1 frank staff 16 2 Dec 14:30 test.txt

d2:
total 8
-rw-r--r-- 1 frank staff 18 2 Dec 14:30 anothertest.tst

~/stuff/gittest> git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)

modified: d1/test.txt
modified: d2/anothertest.tst

~/stuff/gittest> ~/stuff/git_tmp/bin/git --version git version 2.11.0

~/stuff/gittest> ~/stuff/git_tmp/bin/git difftool -d -t diff /var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.0oGRF/left/d1:
total 8
-rw-r--r-- 1 frank staff 6 2 Dec 14:52 test.txt

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.0oGRF/left/d2:
total 8
-rw-r--r-- 1 frank staff 7 2 Dec 14:52 anothertest.tst

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.0oGRF/right/d1:
total 8
lrwxr-xr-x 1 frank staff 38 2 Dec 14:52 test.txt -> /Users/frank/stuff/gittest/d1/test.txt

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.0oGRF/right/d2:
total 8
lrwxr-xr-x 1 frank staff 45 2 Dec 14:52 anothertest.tst -> /Users/frank/stuff/gittest/d2/anothertest.tst

cd d2
~/stuff/gittest/d2> ~/stuff/git_tmp/bin/git difftool -d -t diff /var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.eRXhB/left/d2:
total 8
-rw-r--r-- 1 frank staff 7 2 Dec 14:52 anothertest.tst

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.eRXhB/right/d1:
total 8
lrwxr-xr-x 1 frank staff 38 2 Dec 14:52 test.txt -> /Users/frank/stuff/gittest/d1/test.txt

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.eRXhB/right/d2:
total 8
lrwxr-xr-x 1 frank staff 45 2 Dec 14:52 anothertest.tst -> /Users/frank/stuff/gittest/d2/anothertest.tst

Note that left does not contain d1

~/stuff/gittest/d2> ~/stuff/git_tmp/bin/git --version
git version 2.9.2
~/stuff/gittest/d2> ~/stuff/git_tmp/bin/git difftool -d -t diff /var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.YxtVw/left/d1:
total 8
-rw-r--r-- 1 frank staff 6 2 Dec 15:02 test.txt

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.YxtVw/left/d2:
total 8
-rw-r--r-- 1 frank staff 7 2 Dec 15:02 anothertest.tst

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.YxtVw/right/d1:
total 8
lrwxr-xr-x 1 frank staff 38 2 Dec 15:02 test.txt -> /Users/frank/stuff/gittest/d1/test.txt

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.YxtVw/right/d2:
total 8
lrwxr-xr-x 1 frank staff 45 2 Dec 15:02 anothertest.tst -> /Users/frank/stuff/gittest/d2/anothertest.tst

~/stuff/gittest/d2> ~/stuff/git_tmp/bin/git --version
git version 2.9.3
~/stuff/gittest/d2> ~/stuff/git_tmp/bin/git difftool -d -t diff /var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.TpJ5u/left/d2:
total 8
-rw-r--r-- 1 frank staff 7 2 Dec 15:01 anothertest.tst

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.TpJ5u/right/d1:
total 8
lrwxr-xr-x 1 frank staff 38 2 Dec 15:01 test.txt -> /Users/frank/stuff/gittest/d1/test.txt

Quoted 4 lines

/var/folders/0j/3pk3pdsx7rzb9_njdpyjwm000000gn/T/git-difftool.TpJ5u/right/d2:
total 8
lrwxr-xr-x 1 frank staff 45 2 Dec 15:01 anothertest.tst -> /Users/frank/stuff/gittest/d2/anothertest.tst

This regression was not caught by our test suite.

This looks like it's an edge case not handled by:
9ec26e797781 "difftool: fix argument handling in subdirs" The current "rewrite difftool in C" topic may need a similar adjustment.

The problem:

When preparing the right-side of the diff we only construct the parts that changed. When constructing the left side we construct a full index, but we were constructing it relative to the subdirectory, and thus it ends up empty because we are in a subdirectory and the paths are incorrect.

The fix seems simple -- when preparing the index files we need to chdir to the toplevel to ensure that the index construction steps find the correct toplevel-relative paths.

Thanks for the heads-up,
David

--- 8< ---
Date: Sun, 4 Dec 2016 14:27:17 -0800
Subject: [PATCH] difftool: properly handle being launched from a subdirectory

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 the dir-diff.

When preparing the right-side of the diff we only construct the parts that changed.

When constructing the left side we construct an index, but we were constructing it relative to the subdirectory, and thus it ends up empty because we are in a subdirectory and the paths are incorrect.

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 a test case to exercise this use case.

---
 git-difftool.perl   | 4 ++++
 t/t7800-difftool.sh | 7 +++++--
 2 files changed, 9 insertions(+), 2 deletions(-)
git-difftool.perl +4 -0
index a5790d03a..959822d5f 100755
@@ -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";
t/t7800-difftool.sh +5 -2
index 70a2de461..caab4b5ca 100755
@@ -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)
 	)
 '
 
Signature · 1 line
2.11.0.dirty
#2 lore raw

Hi David,

Quoted 14 lines · David Aguilar

Date: Sun, 4 Dec 2016 14:27:17 -0800
Subject: [PATCH] difftool: properly handle being launched from a subdirectory

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 the dir-diff.

When preparing the right-side of the diff we only construct the parts that changed.

When constructing the left side we construct an index, but we were constructing it relative to the subdirectory, and thus it ends up empty because we are in a subdirectory and the paths are incorrect.

Quoted 8 lines

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 a test case to exercise this use case.

I applied this to my builtin-difftool branch (which, as per Peff's suggestion, runs t7800 both with and without the builtin difftool) and the tests pass:

https://github.com/dscho/git/commit/9b9a69c5ee975a4a2565343ae0a9199a6ac89609

Which means that the builtin difftool already had fixed the bug, more by coincidence than by design, I have to admit.

Ciao,
Johannes