From: Junio C Hamano Date: Tue, 17 Sep 2013 18:42:44 +0000 (-0700) Subject: Merge branch 'dw/diff-no-index-doc' X-Git-Tag: v1.8.5-rc0~124 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/cd8c891b7403754cc7f4b5ace0f799adb83d3218?hp=-c Merge branch 'dw/diff-no-index-doc' 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 " 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 --- cd8c891b7403754cc7f4b5ace0f799adb83d3218 diff --combined diff-no-index.c index e301aafff9,014d20a2bd..00a8eefde9 --- a/diff-no-index.c +++ b/diff-no-index.c @@@ -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? */ @@@ -215,9 -215,21 +215,21 @@@ 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; ) { @@@ -225,7 -237,7 +237,7 @@@ 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], "--")) @@@ -260,9 -272,6 +272,9 @@@ 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);