Skip to content

Commit

Permalink
diff --no-index: clarify operation when not inside a repository
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Dale R. Worley authored and Junio C Hamano committed Aug 22, 2013
1 parent a3bc3d0 commit b214edd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Documentation/git-diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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>...]::

Expand Down
14 changes: 13 additions & 1 deletion diff-no-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; ) {
Expand Down

0 comments on commit b214edd

Please sign in to comment.