diff --no-index: clarify operation when not inside a repository
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>
Dale R. Worley committed
Aug 22, 2013 at 16:31 UTC
b214eddfb2d57e318a3f5b88da1cafcf19184b4d
2 files changed
+15
-2
Documentation/git-diff.txt
+2
-1
@@ -31,7 +31,8 @@ two blob objects, or changes between two files on disk.
31
+
32
If exactly two paths are given and at least one points outside
33
the current repository, 'git diff' will compare the two files /
34
-directories. This behavior can be forced by --no-index.
34
+directories. This behavior can be forced by --no-index or by
35
+executing 'git diff' outside of a working tree.
36
37
'git diff' [--options] --cached [<commit>] [--] [<path>...]::
38
diff-no-index.c
+13
-1
@@ -215,9 +215,21 @@ void diff_no_index(struct rev_info *revs,
215
path_inside_repo(prefix, argv[i+1])))
216
return;
217
}
218
- if (argc != i + 2)
218
+ if (argc != i + 2) {
219
+ if (!no_index) {
220
+ /*
221
+ * There was no --no-index and there were not two
222
+ * paths. It is possible that the user intended
223
+ * to do an inside-repository operation.
224
+ */
225
+ fprintf(stderr, "Not a git repository\n");
226
+ fprintf(stderr,
227
+ "To compare two paths outside a working tree:\n");
228
+ }
229
+ /* Give the usage message for non-repository usage and exit. */
230
usagef("git diff %s <path> <path>",
231
no_index ? "--no-index" : "[--no-index]");
232
+ }
233
234
diff_setup(&revs->diffopt);
235
for (i = 1; i < argc - 2; ) {