diff --no-index: clarify operation when not inside a repository
authorDale R. Worley <worley@alum.mit.edu>
Thu, 22 Aug 2013 20:31:21 +0000 (16:31 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Aug 2013 20:55:28 +0000 (13:55 -0700)
Clarify documentation for "diff --no-index". State that when not
inside a repository, --no-index is implied and two arguments are
mandatory.

Clarify error message from diff-no-index to inform user that CWD is
not inside a repository and thus two arguments are mandatory.

Signed-off-by: Dale Worley <worley@ariadne.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-diff.txt
diff-no-index.c
index 78d6d50489502638013509fbf72c811b50bfee86..b1630ba2b752f9acfc52405ea46b5318748702c7 100644 (file)
@@ -31,7 +31,8 @@ two blob objects, or changes between two files on disk.
 +
 If exactly two paths are given and at least one points outside
 the current repository, 'git diff' will compare the two files /
-directories. This behavior can be forced by --no-index.
+directories. This behavior can be forced by --no-index or by
+executing 'git diff' outside of a working tree.
 
 'git diff' [--options] --cached [<commit>] [--] [<path>...]::
 
index 74da659368e4db67715a9c81dc7a5e0edcd3bcce..014d20a2bd9cfd2db662a4664855473b559d945c 100644 (file)
@@ -215,9 +215,21 @@ void diff_no_index(struct rev_info *revs,
                     path_inside_repo(prefix, argv[i+1])))
                        return;
        }
-       if (argc != i + 2)
+       if (argc != i + 2) {
+               if (!no_index) {
+                       /*
+                        * 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 ? "--no-index" : "[--no-index]");
+       }
 
        diff_setup(&revs->diffopt);
        for (i = 1; i < argc - 2; ) {