git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] diff: add test for --no-index executed outside repo
       [not found] <xmqqob4goa4t.fsf@gitster.dls.corp.google.co>
@ 2013-12-16 20:19 ` Thomas Gummerer
  2013-12-16 20:19   ` [PATCH v2 2/2] diff: avoid some nesting Thomas Gummerer
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Gummerer @ 2013-12-16 20:19 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Jonathan Nieder, Jens Lehmann, Torsten Bögershausen,
	Eric Sunshine, Thomas Gummerer

470faf9 diff: move no-index detection to builtin/diff.c breaks the error
message for "git diff --no-index", when the command is executed outside
of a git repository and the wrong number of arguments are given. 6df5762
diff: don't read index when --no-index is given fixes the problem.

Add a test to guard against similar breakages in the future.

Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
---

> Perhaps use CEILING, like this (untested)?

Thanks, this makes sense, here is the new version.

 t/t4053-diff-no-index.sh | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh
index 077c775..2ab3c48 100755
--- a/t/t4053-diff-no-index.sh
+++ b/t/t4053-diff-no-index.sh
@@ -44,4 +44,15 @@ test_expect_success 'git diff outside repo with broken index' '
 	)
 '
 
+test_expect_success 'git diff --no-index executed outside repo gives correct error message' '
+	(
+		GIT_CEILING_DIRECTORIES=$TRASH_DIRECTORY/non &&
+		export GIT_CEILING_DIRECTORIES &&
+		cd non/git &&
+		test_must_fail git diff --no-index a 2>actual.err &&
+		echo "usage: git diff --no-index <path> <path>" >expect.err &&
+		test_cmp expect.err actual.err
+	)
+'
+
 test_done
-- 
1.8.5.4.g8639e57

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH v2 2/2] diff: avoid some nesting
  2013-12-16 20:19 ` [PATCH v2 1/2] diff: add test for --no-index executed outside repo Thomas Gummerer
@ 2013-12-16 20:19   ` Thomas Gummerer
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Gummerer @ 2013-12-16 20:19 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, Jonathan Nieder, Jens Lehmann, Torsten Bögershausen,
	Eric Sunshine, Thomas Gummerer

Avoid some nesting in builtin/diff.c, to make the code easier to read.
There are no functional changes.

Helped-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
---
 builtin/diff.c | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/builtin/diff.c b/builtin/diff.c
index ea1dd65..24d6271 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -319,27 +319,26 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 
 	init_revisions(&rev, prefix);
 
-	if (no_index) {
-		if (argc != i + 2) {
-			if (no_index == DIFF_NO_INDEX_IMPLICIT) {
-				/*
-				 * There was no --no-index and there were not two
-				 * paths. It is possible that the user intended
-				 * to do an inside-repository operation.
-				 */
-				fprintf(stderr, "Not a git repository\n");
-				fprintf(stderr,
-					"To compare two paths outside a working tree:\n");
-			}
-			/* Give the usage message for non-repository usage and exit. */
-			usagef("git diff %s <path> <path>",
-			       no_index == DIFF_NO_INDEX_EXPLICIT ?
-					"--no-index" : "[--no-index]");
-
+	if (no_index && argc != i + 2) {
+		if (no_index == DIFF_NO_INDEX_IMPLICIT) {
+			/*
+			 * There was no --no-index and there were not two
+			 * paths. It is possible that the user intended
+			 * to do an inside-repository operation.
+			 */
+			fprintf(stderr, "Not a git repository\n");
+			fprintf(stderr,
+				"To compare two paths outside a working tree:\n");
 		}
+		/* Give the usage message for non-repository usage and exit. */
+		usagef("git diff %s <path> <path>",
+		       no_index == DIFF_NO_INDEX_EXPLICIT ?
+		       "--no-index" : "[--no-index]");
+
+	}
+	if (no_index)
 		/* If this is a no-index diff, just run it and exit there. */
 		diff_no_index(&rev, argc, argv, prefix);
-	}
 
 	/* Otherwise, we are doing the usual "git" diff */
 	rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
-- 
1.8.5.4.g8639e57

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-12-16 20:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <xmqqob4goa4t.fsf@gitster.dls.corp.google.co>
2013-12-16 20:19 ` [PATCH v2 1/2] diff: add test for --no-index executed outside repo Thomas Gummerer
2013-12-16 20:19   ` [PATCH v2 2/2] diff: avoid some nesting Thomas Gummerer

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 NNTP newsgroup(s).