Skip to content

Commit b214edd

Browse files
daleworleygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a3bc3d0 commit b214edd

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Documentation/git-diff.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ two blob objects, or changes between two files on disk.
3131
+
3232
If exactly two paths are given and at least one points outside
3333
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.
3536

3637
'git diff' [--options] --cached [<commit>] [--] [<path>...]::
3738

diff-no-index.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,21 @@ void diff_no_index(struct rev_info *revs,
215215
path_inside_repo(prefix, argv[i+1])))
216216
return;
217217
}
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. */
219230
usagef("git diff %s <path> <path>",
220231
no_index ? "--no-index" : "[--no-index]");
232+
}
221233

222234
diff_setup(&revs->diffopt);
223235
for (i = 1; i < argc - 2; ) {

0 commit comments

Comments
 (0)