Merge branch 'dw/diff-no-index-doc'
authorJunio C Hamano <gitster@pobox.com>
Tue, 17 Sep 2013 18:42:44 +0000 (11:42 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Sep 2013 18:42:44 +0000 (11:42 -0700)
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

1  2 
diff-no-index.c
diff --combined diff-no-index.c
index e301aafff9ff230313425eea5987b18056b72c98,014d20a2bd9cfd2db662a4664855473b559d945c..00a8eefde9aeb96592f5ed6455dbf5d3b16747c4
@@@ -45,7 -45,7 +45,7 @@@ static int get_mode(const char *path, i
  
        if (!path || !strcmp(path, "/dev/null"))
                *mode = 0;
 -#ifdef _WIN32
 +#ifdef GIT_WINDOWS_NATIVE
        else if (!strcasecmp(path, "nul"))
                *mode = 0;
  #endif
@@@ -187,7 -187,7 +187,7 @@@ void diff_no_index(struct rev_info *rev
  {
        int i, prefixlen;
        int no_index = 0;
 -      unsigned options = 0;
 +      unsigned deprecated_show_diff_q_option_used = 0;
        const char *paths[2];
  
        /* Were we asked to do --no-index explicitly? */
                     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; ) {
                if (!strcmp(argv[i], "--no-index"))
                        i++;
                else if (!strcmp(argv[i], "-q")) {
 -                      options |= DIFF_SILENT_ON_REMOVED;
 +                      deprecated_show_diff_q_option_used = 1;
                        i++;
                }
                else if (!strcmp(argv[i], "--"))
        revs->max_count = -2;
        diff_setup_done(&revs->diffopt);
  
 +      if (deprecated_show_diff_q_option_used)
 +              handle_deprecated_show_diff_q(&revs->diffopt);
 +
        setup_diff_pager(&revs->diffopt);
        DIFF_OPT_SET(&revs->diffopt, EXIT_WITH_STATUS);