From: Junio C Hamano Date: Fri, 21 May 2010 11:02:23 +0000 (-0700) Subject: Merge branch 'mg/advice-statushints' X-Git-Url: https://rtime.felk.cvut.cz/gitweb/git.git/commitdiff_plain/82e7ee7351d6e328294016d3b99825d8001abd24?hp=-c Merge branch 'mg/advice-statushints' * mg/advice-statushints: wt-status: take advice.statusHints seriously t7508: test advice.statusHints Conflicts: wt-status.c --- 82e7ee7351d6e328294016d3b99825d8001abd24 diff --combined t/t7508-status.sh index a9df7ff7b,1301ec87e..008d5711b --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@@ -68,6 -68,34 +68,34 @@@ test_expect_success 'status (2)' ' + cat >expect <<\EOF + # On branch master + # Changes to be committed: + # new file: dir2/added + # + # Changed but not updated: + # modified: dir1/modified + # + # Untracked files: + # dir1/untracked + # dir2/modified + # dir2/untracked + # expect + # output + # untracked + EOF + + git config advice.statusHints false + + test_expect_success 'status (advice.statusHints false)' ' + + git status >output && + test_cmp expect output + + ' + + git config --unset advice.statusHints + cat >expect <<\EOF M dir1/modified A dir2/added @@@ -115,6 -143,23 +143,23 @@@ test_expect_success 'status (status.sho test_cmp expect output ' + cat >expect <output && + test_cmp expect output + ' + git config --unset advice.statusHints + cat >expect << EOF M dir1/modified A dir2/added @@@ -496,16 -541,6 +541,16 @@@ test_expect_success 'dry-run of partia test_cmp expect output ' +cat >expect <output && + test_cmp expect output +' + test_expect_success 'setup status submodule summary' ' test_create_repo sm && ( cd sm && @@@ -703,19 -738,4 +748,19 @@@ test_expect_success 'commit --dry-run s test_cmp expect output ' +test_expect_success POSIXPERM 'status succeeds in a read-only repository' ' + ( + chmod a-w .git && + # make dir1/tracked stat-dirty + >dir1/tracked1 && mv -f dir1/tracked1 dir1/tracked && + git status -s >output && + ! grep dir1/tracked output && + # make sure "status" succeeded without writing index out + git diff-files | grep dir1/tracked + ) + status=$? + chmod 775 .git + (exit $status) +' + test_done diff --combined wt-status.c index 84a9002b8,d44486c82..14e0acce8 --- a/wt-status.c +++ b/wt-status.c @@@ -42,7 -42,6 +42,7 @@@ void wt_status_prepare(struct wt_statu s->index_file = get_index_file(); s->change.strdup_strings = 1; s->untracked.strdup_strings = 1; + s->ignored.strdup_strings = 1; } static void wt_status_print_unmerged_header(struct wt_status *s) @@@ -97,15 -96,13 +97,15 @@@ static void wt_status_print_dirty_heade color_fprintf_ln(s->fp, c, "#"); } -static void wt_status_print_untracked_header(struct wt_status *s) +static void wt_status_print_other_header(struct wt_status *s, + const char *what, + const char *how) { const char *c = color(WT_STATUS_HEADER, s); - color_fprintf_ln(s->fp, c, "# Untracked files:"); + color_fprintf_ln(s->fp, c, "# %s files:", what); if (!advice_status_hints) return; - color_fprintf_ln(s->fp, c, "# (use \"git add ...\" to include in what will be committed)"); + color_fprintf_ln(s->fp, c, "# (use \"git %s ...\" to include in what will be committed)", how); color_fprintf_ln(s->fp, c, "#"); } @@@ -381,26 -378,9 +381,26 @@@ static void wt_status_collect_untracked continue; if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL)) continue; - s->workdir_untracked = 1; string_list_insert(ent->name, &s->untracked); + free(ent); } + + if (s->show_ignored_files) { + dir.nr = 0; + dir.flags = DIR_SHOW_IGNORED | DIR_SHOW_OTHER_DIRECTORIES; + fill_directory(&dir, s->pathspec); + for (i = 0; i < dir.nr; i++) { + struct dir_entry *ent = dir.entries[i]; + if (!cache_name_is_other(ent->name, ent->len)) + continue; + if (!match_pathspec(s->pathspec, ent->name, ent->len, 0, NULL)) + continue; + string_list_insert(ent->name, &s->ignored); + free(ent); + } + } + + free(dir.entries); } void wt_status_collect(struct wt_status *s) @@@ -543,10 -523,7 +543,10 @@@ static void wt_status_print_submodule_s run_command(&sm_summary); } -static void wt_status_print_untracked(struct wt_status *s) +static void wt_status_print_other(struct wt_status *s, + struct string_list *l, + const char *what, + const char *how) { int i; struct strbuf buf = STRBUF_INIT; @@@ -554,11 -531,10 +554,11 @@@ if (!s->untracked.nr) return; - wt_status_print_untracked_header(s); - for (i = 0; i < s->untracked.nr; i++) { + wt_status_print_other_header(s, what, how); + + for (i = 0; i < l->nr; i++) { struct string_list_item *it; - it = &(s->untracked.items[i]); + it = &(l->items[i]); color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t"); color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", quote_path(it->string, strlen(it->string), @@@ -646,12 -622,12 +646,14 @@@ void wt_status_print(struct wt_status * wt_status_print_submodule_summary(s, 0); /* staged */ wt_status_print_submodule_summary(s, 1); /* unstaged */ } - if (s->show_untracked_files) - wt_status_print_untracked(s); - else if (s->commitable) + if (s->show_untracked_files) { + wt_status_print_other(s, &s->untracked, "Untracked", "add"); + if (s->show_ignored_files) + wt_status_print_other(s, &s->ignored, "Ignored", "add -f"); + } else if (s->commitable) - fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n"); + fprintf(s->fp, "# Untracked files not listed%s\n", + advice_status_hints + ? " (use -u option to show untracked files)" : ""); if (s->verbose) wt_status_print_verbose(s); @@@ -661,15 -637,22 +663,22 @@@ else if (s->nowarn) ; /* nothing */ else if (s->workdir_dirty) - printf("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n"); + printf("no changes added to commit%s\n", + advice_status_hints + ? " (use \"git add\" and/or \"git commit -a\")" : ""); else if (s->untracked.nr) - printf("nothing added to commit but untracked files present (use \"git add\" to track)\n"); + printf("nothing added to commit but untracked files present%s\n", + advice_status_hints + ? " (use \"git add\" to track)" : ""); else if (s->is_initial) - printf("nothing to commit (create/copy files and use \"git add\" to track)\n"); + printf("nothing to commit%s\n", advice_status_hints + ? " (create/copy files and use \"git add\" to track)" : ""); else if (!s->show_untracked_files) - printf("nothing to commit (use -u to show untracked files)\n"); + printf("nothing to commit%s\n", advice_status_hints + ? " (use -u to show untracked files)" : ""); else - printf("nothing to commit (working directory clean)\n"); + printf("nothing to commit%s\n", advice_status_hints + ? " (working directory clean)" : ""); } } @@@ -732,16 -715,16 +741,16 @@@ static void wt_shortstatus_status(int n } } -static void wt_shortstatus_untracked(int null_termination, struct string_list_item *it, - struct wt_status *s) +static void wt_shortstatus_other(int null_termination, struct string_list_item *it, + struct wt_status *s, const char *sign) { if (null_termination) { - fprintf(stdout, "?? %s%c", it->string, 0); + fprintf(stdout, "%s %s%c", sign, it->string, 0); } else { struct strbuf onebuf = STRBUF_INIT; const char *one; one = quote_path(it->string, -1, &onebuf, s->prefix); - color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "??"); + color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign); printf(" %s\n", one); strbuf_release(&onebuf); } @@@ -765,13 -748,7 +774,13 @@@ void wt_shortstatus_print(struct wt_sta struct string_list_item *it; it = &(s->untracked.items[i]); - wt_shortstatus_untracked(null_termination, it, s); + wt_shortstatus_other(null_termination, it, s, "??"); + } + for (i = 0; i < s->ignored.nr; i++) { + struct string_list_item *it; + + it = &(s->ignored.items[i]); + wt_shortstatus_other(null_termination, it, s, "!!"); } }