git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: David Aguilar <davvid@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git ML <git@vger.kernel.org>, Frank Becker <fb@mooflu.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	John Keeping <john@keeping.me.uk>
Subject: [PATCH v2] difftool: fix dir-diff index creation when in a subdirectory
Date: Wed,  7 Dec 2016 02:16:08 -0800	[thread overview]
Message-ID: <20161207101608.16058-1-davvid@gmail.com> (raw)

9ec26e7977 (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 <fb@mooflu.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
---
Changes since v1:

- Improved commit message thanks to Johannes Schindelin
  ("git whatis" was used to describe the referenced commit)

- Add more tests for edge cases that are properly handled
  but were not being tested.

 git-difftool.perl   |  4 ++++
 t/t7800-difftool.sh | 44 +++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/git-difftool.perl b/git-difftool.perl
index a5790d03a0..959822d5f3 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 70a2de461a..99d4123461 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -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 &&
@@ -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)
 	)
 '
 
-- 
2.11.0.1.g7697df0


             reply	other threads:[~2016-12-07 10:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-07 10:16 David Aguilar [this message]
2016-12-12 21:35 ` [PATCH v2] difftool: fix dir-diff index creation when in a subdirectory Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161207101608.16058-1-davvid@gmail.com \
    --to=davvid@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=fb@mooflu.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=john@keeping.me.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).