summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-09-17 18:42:44 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-09-17 18:42:44 (GMT)
commitcd8c891b7403754cc7f4b5ace0f799adb83d3218 (patch)
tree6e2e6b048303471b81b45647043d1e995b690314
parent8fbb07e3f37ab53febd0b2fc0f64811c68cd2492 (diff)
parent286bc123cdabed76a1da25a32e97d392b37d51a2 (diff)
downloadgit-cd8c891b7403754cc7f4b5ace0f799adb83d3218.zip
git-cd8c891b7403754cc7f4b5ace0f799adb83d3218.tar.gz
git-cd8c891b7403754cc7f4b5ace0f799adb83d3218.tar.bz2
Merge branch 'dw/diff-no-index-doc'
When the user types "git diff" outside a working tree, thinking he is inside one, the current error message that is a single-liner "usage: git diff --no-index <path> <path>" may not be sufficient to make him realize the mistake. Add "Not a git repository" to the error message when we fell into the "--no-index" mode without an explicit command line option to instruct us to do so. * dw/diff-no-index-doc: diff --no-index: describe in a separate paragraph diff --no-index: clarify operation when not inside a repository
-rw-r--r--Documentation/git-diff.txt13
-rw-r--r--diff-no-index.c14
2 files changed, 22 insertions, 5 deletions
diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt
index 78d6d50..33fbd8c 100644
--- a/Documentation/git-diff.txt
+++ b/Documentation/git-diff.txt
@@ -28,10 +28,15 @@ two blob objects, or changes between two files on disk.
words, the differences are what you _could_ tell Git to
further add to the index but you still haven't. You can
stage these changes by using linkgit:git-add[1].
-+
-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.
+
+'git diff' --no-index [--options] [--] [<path>...]::
+
+ This form is to compare the given two paths on the
+ filesystem. You can omit the `--no-index` option when
+ running the command in a working tree controlled by Git and
+ at least one of the paths points outside the working tree,
+ or when running the command outside a working tree
+ controlled by Git.
'git diff' [--options] --cached [<commit>] [--] [<path>...]::
diff --git a/diff-no-index.c b/diff-no-index.c
index e301aaf..00a8eef 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -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; ) {