From b214eddfb2d57e318a3f5b88da1cafcf19184b4d Mon Sep 17 00:00:00 2001 From: "Dale R. Worley" Date: Thu, 22 Aug 2013 16:31:21 -0400 Subject: 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 Signed-off-by: Junio C Hamano diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index 78d6d50..b1630ba 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -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 [] [--] [...]:: diff --git a/diff-no-index.c b/diff-no-index.c index 74da659..014d20a 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 ", no_index ? "--no-index" : "[--no-index]"); + } diff_setup(&revs->diffopt); for (i = 1; i < argc - 2; ) { -- cgit v0.10.2-6-g49f6 From 286bc123cdabed76a1da25a32e97d392b37d51a2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 28 Aug 2013 15:17:18 -0700 Subject: diff --no-index: describe in a separate paragraph The documentation for "diff-files" mode of "git diff" primarily talks about how changes in the files in the working tree are shown relative to the contents previously added to that index, and tucks explanation on how "--no-index" mode, which works in a quite different way, may be implicitly used instead. Instead, add a separate paragraph to explain what "--no-index" mode does, and also mention when "--no-index" can be omitted from the command line (essentially, when it is obvious from the context). Signed-off-by: Junio C Hamano diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index b1630ba..33fbd8c 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -28,11 +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 or by -executing 'git diff' outside of a working tree. + +'git diff' --no-index [--options] [--] [...]:: + + 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 [] [--] [...]:: -- cgit v0.10.2-6-g49f6