From: Junio C Hamano Date: Fri, 30 Jun 2017 20:45:22 +0000 (-0700) Subject: Merge branch 'ks/status-initial-commit' X-Git-Tag: v2.14.0-rc0~45 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/7e46f19a105f3798b03ac3887f45034fbfdff676?ds=inline;hp=-c Merge branch 'ks/status-initial-commit' "git status" has long shown essentially the same message as "git commit"; the message it gives while preparing for the root commit, i.e. "Initial commit", was hard to understand for some new users. Now it says "No commits yet" to stress more on the current status (rather than the commit the user is preparing for, which is more in line with the focus of "git commit"). * ks/status-initial-commit: status: contextually notify user about an initial commit --- 7e46f19a105f3798b03ac3887f45034fbfdff676 diff --combined builtin/commit.c index 00a01f07c3,3d614a2ace..03b97c6449 --- a/builtin/commit.c +++ b/builtin/commit.c @@@ -6,7 -6,6 +6,7 @@@ */ #include "cache.h" +#include "config.h" #include "lockfile.h" #include "cache-tree.h" #include "color.h" @@@ -254,8 -253,7 +254,8 @@@ static int list_paths(struct string_lis if (with_tree) { char *max_prefix = common_prefix(pattern); - overlay_tree_on_cache(with_tree, max_prefix ? max_prefix : prefix); + overlay_tree_on_index(&the_index, with_tree, + max_prefix ? max_prefix : prefix); free(max_prefix); } @@@ -315,7 -313,7 +315,7 @@@ static void create_base_index(const str opts.dst_index = &the_index; opts.fn = oneway_merge; - tree = parse_tree_indirect(current_head->object.oid.hash); + tree = parse_tree_indirect(¤t_head->object.oid); if (!tree) die(_("failed to unpack HEAD tree object")); parse_tree(tree); @@@ -1265,10 -1263,6 +1265,10 @@@ static int parse_status_slot(const cha return WT_STATUS_NOBRANCH; if (!strcasecmp(slot, "unmerged")) return WT_STATUS_UNMERGED; + if (!strcasecmp(slot, "localBranch")) + return WT_STATUS_LOCAL_BRANCH; + if (!strcasecmp(slot, "remoteBranch")) + return WT_STATUS_REMOTE_BRANCH; return -1; } @@@ -1297,10 -1291,6 +1297,10 @@@ static int git_status_config(const cha status_deferred_config.show_branch = git_config_bool(k, v); return 0; } + if (!strcmp(k, "status.showstash")) { + s->show_stash = git_config_bool(k, v); + return 0; + } if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) { s->use_color = git_config_colorbool(k, v); return 0; @@@ -1349,8 -1339,6 +1349,8 @@@ int cmd_status(int argc, const char **a N_("show status concisely"), STATUS_FORMAT_SHORT), OPT_BOOL('b', "branch", &s.show_branch, N_("show branch information")), + OPT_BOOL(0, "show-stash", &s.show_stash, + N_("show stash information")), { OPTION_CALLBACK, 0, "porcelain", &status_format, N_("version"), N_("machine-readable output"), PARSE_OPT_OPTARG, opt_parse_porcelain }, @@@ -1442,7 -1430,7 +1442,7 @@@ static void print_summary(const char *p struct strbuf author_ident = STRBUF_INIT; struct strbuf committer_ident = STRBUF_INIT; - commit = lookup_commit(oid->hash); + commit = lookup_commit(oid); if (!commit) die(_("couldn't look up newly created commit")); if (parse_commit(commit)) @@@ -1660,13 -1648,14 +1660,14 @@@ int cmd_commit(int argc, const char **a usage_with_options(builtin_commit_usage, builtin_commit_options); status_init_config(&s, git_commit_config); + s.commit_template = 1; status_format = STATUS_FORMAT_NONE; /* Ignore status.short */ s.colopts = 0; if (get_sha1("HEAD", oid.hash)) current_head = NULL; else { - current_head = lookup_commit_or_die(oid.hash, "HEAD"); + current_head = lookup_commit_or_die(&oid, "HEAD"); if (parse_commit(current_head)) die(_("could not parse HEAD commit")); } @@@ -1707,7 -1696,10 +1708,7 @@@ if (!reflog_msg) reflog_msg = "commit (merge)"; pptr = commit_list_append(current_head, pptr); - fp = fopen(git_path_merge_head(), "r"); - if (fp == NULL) - die_errno(_("could not open '%s' for reading"), - git_path_merge_head()); + fp = xfopen(git_path_merge_head(), "r"); while (strbuf_getline_lf(&m, fp) != EOF) { struct commit *parent; @@@ -1767,7 -1759,7 +1768,7 @@@ append_merge_tag_headers(parents, &tail); } - if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->sha1, + if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->oid.hash, parents, oid.hash, author_ident.buf, sign_commit, extra)) { rollback_index_files(); die(_("failed to write commit object")); @@@ -1814,7 -1806,7 +1815,7 @@@ cfg = init_copy_notes_for_rewrite("amend"); if (cfg) { /* we are amending, so current_head is not NULL */ - copy_note_for_rewrite(cfg, current_head->object.oid.hash, oid.hash); + copy_note_for_rewrite(cfg, ¤t_head->object.oid, &oid); finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'"); } run_rewrite_hook(¤t_head->object.oid, &oid); diff --combined t/t7508-status.sh index f7fe22a195,db709048c2..43d19a9b22 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@@ -32,17 -32,6 +32,17 @@@ test_expect_success 'commit -h in broke test_i18ngrep "[Uu]sage" broken/usage ' +test_expect_success 'create upstream branch' ' + git checkout -b upstream && + test_commit upstream1 && + test_commit upstream2 && + # leave the first commit on master as root because several + # tests depend on this case; for our upstream we only + # care about commit counts anyway, so a totally divergent + # history is OK + git checkout --orphan master +' + test_expect_success 'setup' ' : >tracked && : >modified && @@@ -64,9 -53,7 +64,9 @@@ echo 1 >dir1/modified && echo 2 >dir2/modified && echo 3 >dir2/added && - git add dir2/added + git add dir2/added && + + git branch --set-upstream-to=upstream ' test_expect_success 'status (1)' ' @@@ -88,10 -75,6 +88,10 @@@ EO test_expect_success 'status --column' ' cat >expect <<\EOF && # On branch master +# Your branch and '\''upstream'\'' have diverged, +# and have 1 and 2 different commits each, respectively. +# (use "git pull" to merge the remote branch into yours) +# # Changes to be committed: # (use "git reset HEAD ..." to unstage) # @@@ -122,10 -105,6 +122,10 @@@ test_expect_success 'status --column st cat >expect <<\EOF # On branch master +# Your branch and 'upstream' have diverged, +# and have 1 and 2 different commits each, respectively. +# (use "git pull" to merge the remote branch into yours) +# # Changes to be committed: # (use "git reset HEAD ..." to unstage) # @@@ -199,9 -178,6 +199,9 @@@ test_expect_success 'commit ignores sta cat >expect <<\EOF On branch master +Your branch and 'upstream' have diverged, +and have 1 and 2 different commits each, respectively. + Changes to be committed: new file: dir2/added @@@ -272,10 -248,6 +272,10 @@@ test_expect_success 'status with gitign cat >expect <<\EOF && On branch master +Your branch and '\''upstream'\'' have diverged, +and have 1 and 2 different commits each, respectively. + (use "git pull" to merge the remote branch into yours) + Changes to be committed: (use "git reset HEAD ..." to unstage) @@@ -341,10 -313,6 +341,10 @@@ test_expect_success 'status with gitign cat >expect <<\EOF && On branch master +Your branch and '\''upstream'\'' have diverged, +and have 1 and 2 different commits each, respectively. + (use "git pull" to merge the remote branch into yours) + Changes to be committed: (use "git reset HEAD ..." to unstage) @@@ -380,7 -348,7 +380,7 @@@ output EOF cat >expect <<\EOF -## master +## master...upstream [ahead 1, behind 2] M dir1/modified A dir2/added ?? dir1/untracked @@@ -414,10 -382,6 +414,10 @@@ test_expect_success 'setup dir3' test_expect_success 'status -uno' ' cat >expect <..." to unstage) @@@ -444,9 -408,6 +444,9 @@@ test_expect_success 'status (status.sho test_expect_success 'status -uno (advice.statusHints false)' ' cat >expect <expect <..." to unstage) @@@ -536,10 -493,6 +536,10 @@@ test_expect_success 'status -s (status. test_expect_success 'status -uall' ' cat >expect <..." to unstage) @@@ -599,10 -552,6 +599,10 @@@ test_expect_success 'status -s (status. test_expect_success 'status with relative paths' ' cat >expect <<\EOF && On branch master +Your branch and '\''upstream'\'' have diverged, +and have 1 and 2 different commits each, respectively. + (use "git pull" to merge the remote branch into yours) + Changes to be committed: (use "git reset HEAD ..." to unstage) @@@ -661,19 -610,13 +661,19 @@@ test_expect_success 'status --porcelai test_expect_success 'setup unique colors' ' git config status.color.untracked blue && - git config status.color.branch green + git config status.color.branch green && + git config status.color.localBranch yellow && + git config status.color.remoteBranch cyan ' test_expect_success 'status with color.ui' ' cat >expect <<\EOF && On branch master +Your branch and '\''upstream'\'' have diverged, +and have 1 and 2 different commits each, respectively. + (use "git pull" to merge the remote branch into yours) + Changes to be committed: (use "git reset HEAD ..." to unstage) @@@ -732,7 -675,7 +732,7 @@@ test_expect_success 'status -s with col ' cat >expect <<\EOF -## master +## master...upstream [ahead 1, behind 2] M dir1/modified A dir2/added ?? dir1/untracked @@@ -783,7 -726,7 +783,7 @@@ test_expect_success 'status --porcelai git status --porcelain -b >output && { - echo "## master" && + echo "## master...upstream [ahead 1, behind 2]" && cat expect } >tmp && mv tmp expect && @@@ -796,10 -739,6 +796,10 @@@ test_expect_success 'status without relative paths' ' cat >expect <<\EOF && On branch master +Your branch and '\''upstream'\'' have diverged, +and have 1 and 2 different commits each, respectively. + (use "git pull" to merge the remote branch into yours) + Changes to be committed: (use "git reset HEAD ..." to unstage) @@@ -846,10 -785,6 +846,10 @@@ test_expect_success 'status -s without test_expect_success 'dry-run of partial commit excluding new file in index' ' cat >expect <..." to unstage) @@@ -890,10 -825,6 +890,10 @@@ test_expect_success 'setup status submo test_expect_success 'status submodule summary is disabled by default' ' cat >expect <..." to unstage) @@@ -950,10 -881,6 +950,10 @@@ head=$(cd sm && git rev-parse --short= test_expect_success 'status submodule summary' ' cat >expect <..." to unstage) @@@ -1012,10 -939,6 +1012,10 @@@ test_expect_success 'status -s submodul test_expect_success 'status submodule summary (clean submodule): commit' ' cat >expect <..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) @@@ -1062,10 -985,6 +1062,10 @@@ test_expect_success 'status -z implies test_expect_success 'commit --dry-run submodule summary (--amend)' ' cat >expect <..." to unstage) @@@ -1119,10 -1038,6 +1119,10 @@@ touch .gitmodule test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' ' cat > expect << EOF && On branch master +Your branch and '\''upstream'\'' have diverged, +and have 2 and 2 different commits each, respectively. + (use "git pull" to merge the remote branch into yours) + Changes to be committed: (use "git reset HEAD ..." to unstage) @@@ -1231,10 -1146,6 +1231,10 @@@ test_expect_success '.git/config ignore test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" ' cat > expect << EOF && On branch master +Your branch and '\''upstream'\'' have diverged, +and have 2 and 2 different commits each, respectively. + (use "git pull" to merge the remote branch into yours) + Changes to be committed: (use "git reset HEAD ..." to unstage) @@@ -1291,10 -1202,6 +1291,10 @@@ head2=$(cd sm && git commit -q -m "2nd test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" ' cat > expect << EOF && On branch master +Your branch and '\''upstream'\'' have diverged, +and have 2 and 2 different commits each, respectively. + (use "git pull" to merge the remote branch into yours) + Changes to be committed: (use "git reset HEAD ..." to unstage) @@@ -1375,10 -1282,6 +1375,10 @@@ test_expect_success ".git/config ignore cat > expect << EOF ; On branch master +; Your branch and 'upstream' have diverged, +; and have 2 and 2 different commits each, respectively. +; (use "git pull" to merge the remote branch into yours) +; ; Changes to be committed: ; (use "git reset HEAD ..." to unstage) ; @@@ -1426,10 -1329,6 +1426,10 @@@ test_expect_success "status (core.comme test_expect_success "--ignore-submodules=all suppresses submodule summary" ' cat > expect << EOF && On branch master +Your branch and '\''upstream'\'' have diverged, +and have 2 and 2 different commits each, respectively. + (use "git pull" to merge the remote branch into yours) + Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) @@@ -1454,10 -1353,6 +1454,10 @@@ EO test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' ' cat > expect << EOF && On branch master +Your branch and '\''upstream'\'' have diverged, +and have 2 and 2 different commits each, respectively. + (use "git pull" to merge the remote branch into yours) + Changes to be committed: (use "git reset HEAD ..." to unstage) @@@ -1577,10 -1472,6 +1577,10 @@@ test_expect_success 'git commit --dry-r git add sm && cat >expect << EOF && On branch master +Your branch and '\''upstream'\'' have diverged, +and have 2 and 2 different commits each, respectively. + (use "git pull" to merge the remote branch into yours) + Changes to be committed: (use "git reset HEAD ..." to unstage) @@@ -1603,41 -1494,39 +1603,71 @@@ EO test_expect_success 'git commit -m will commit a staged but ignored submodule' ' git commit -uno -m message && git status -s --ignore-submodules=dirty >output && - test_i18ngrep ! "^M. sm" output && + test_i18ngrep ! "^M. sm" output && git config --remove-section submodule.subname && git config -f .gitmodules --remove-section submodule.subname ' +test_expect_success 'show stash info with "--show-stash"' ' + git reset --hard && + git stash clear && + echo 1 >file && + git add file && + git stash && + git status >expected_default && + git status --show-stash >expected_with_stash && + test_i18ngrep "^Your stash currently has 1 entry$" expected_with_stash +' + +test_expect_success 'no stash info with "--show-stash --no-show-stash"' ' + git status --show-stash --no-show-stash >expected_without_stash && + test_cmp expected_default expected_without_stash +' + +test_expect_success '"status.showStash=false" weaker than "--show-stash"' ' + git -c status.showStash=false status --show-stash >actual && + test_cmp expected_with_stash actual +' + +test_expect_success '"status.showStash=true" weaker than "--no-show-stash"' ' + git -c status.showStash=true status --no-show-stash >actual && + test_cmp expected_without_stash actual +' + +test_expect_success 'no additionnal info if no stash entries' ' + git stash clear && + git -c status.showStash=true status >actual && + test_cmp expected_without_stash actual +' + + test_expect_success '"No commits yet" should be noted in status output' ' + git checkout --orphan empty-branch-1 && + git status >output && + test_i18ngrep "No commits yet" output + ' + + test_expect_success '"No commits yet" should not be noted in status output' ' + git checkout --orphan empty-branch-2 && + test_commit test-commit-1 && + git status >output && + test_i18ngrep ! "No commits yet" output + ' + + test_expect_success '"Initial commit" should be noted in commit template' ' + git checkout --orphan empty-branch-3 && + touch to_be_committed_1 && + git add to_be_committed_1 && + git commit --dry-run >output && + test_i18ngrep "Initial commit" output + ' + + test_expect_success '"Initial commit" should not be noted in commit template' ' + git checkout --orphan empty-branch-4 && + test_commit test-commit-2 && + touch to_be_committed_2 && + git add to_be_committed_2 && + git commit --dry-run >output && + test_i18ngrep ! "Initial commit" output + ' + test_done diff --combined wt-status.c index 7992a73902,c711ef86e2..8d2fb35b08 --- a/wt-status.c +++ b/wt-status.c @@@ -137,7 -137,6 +137,7 @@@ void wt_status_prepare(struct wt_statu s->untracked.strdup_strings = 1; s->ignored.strdup_strings = 1; s->show_branch = -1; /* unspecified */ + s->show_stash = 0; s->display_comment_prefix = 0; } @@@ -666,7 -665,7 +666,7 @@@ static void wt_status_collect_untracked dir.untracked = the_index.untracked; setup_standard_excludes(&dir); - fill_directory(&dir, &s->pathspec); + fill_directory(&dir, &the_index, &s->pathspec); for (i = 0; i < dir.nr; i++) { struct dir_entry *ent = dir.entries[i]; @@@ -802,27 -801,6 +802,27 @@@ static void wt_longstatus_print_changed wt_longstatus_print_trailer(s); } +static int stash_count_refs(struct object_id *ooid, struct object_id *noid, + const char *email, timestamp_t timestamp, int tz, + const char *message, void *cb_data) +{ + int *c = cb_data; + (*c)++; + return 0; +} + +static void wt_longstatus_print_stash_summary(struct wt_status *s) +{ + int stash_count = 0; + + for_each_reflog_ent("refs/stash", stash_count_refs, &stash_count); + if (stash_count > 0) + status_printf_ln(s, GIT_COLOR_NORMAL, + Q_("Your stash currently has %d entry", + "Your stash currently has %d entries", stash_count), + stash_count); +} + static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncommitted) { struct child_process sm_summary = CHILD_PROCESS_INIT; @@@ -1025,7 -1003,7 +1025,7 @@@ static void wt_longstatus_print_trackin color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c", comment_line_char); else - fputs("", s->fp); + fputs("\n", s->fp); } static int has_unmerged(struct wt_status *s) @@@ -1088,8 -1066,7 +1088,8 @@@ static void show_am_in_progress(struct static char *read_line_from_git_path(const char *filename) { struct strbuf buf = STRBUF_INIT; - FILE *fp = fopen(git_path("%s", filename), "r"); + FILE *fp = fopen_or_warn(git_path("%s", filename), "r"); + if (!fp) { strbuf_release(&buf); return NULL; @@@ -1412,7 -1389,7 +1412,7 @@@ struct grab_1st_switch_cbdata }; static int grab_1st_switch(struct object_id *ooid, struct object_id *noid, - const char *email, unsigned long timestamp, int tz, + const char *email, timestamp_t timestamp, int tz, const char *message, void *cb_data) { struct grab_1st_switch_cbdata *cb = cb_data; @@@ -1453,7 -1430,7 +1453,7 @@@ static void wt_status_get_detached_from /* sha1 is a commit? match without further lookup */ (!oidcmp(&cb.noid, &oid) || /* perhaps sha1 is a tag, try to dereference to a commit */ - ((commit = lookup_commit_reference_gently(oid.hash, 1)) != NULL && + ((commit = lookup_commit_reference_gently(&oid, 1)) != NULL && !oidcmp(&cb.noid, &commit->object.oid)))) { const char *from = ref; if (!skip_prefix(from, "refs/tags/", &from)) @@@ -1601,7 -1578,10 +1601,10 @@@ static void wt_longstatus_print(struct if (s->is_initial) { status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", ""); - status_printf_ln(s, color(WT_STATUS_HEADER, s), _("Initial commit")); + status_printf_ln(s, color(WT_STATUS_HEADER, s), + s->commit_template + ? _("Initial commit") + : _("No commits yet")); status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", ""); } @@@ -1664,8 -1644,6 +1667,8 @@@ } else printf(_("nothing to commit, working tree clean\n")); } + if(s->show_stash) + wt_longstatus_print_stash_summary(s); } static void wt_shortstatus_unmerged(struct string_list_item *it, @@@ -1773,7 -1751,7 +1776,7 @@@ static void wt_shortstatus_print_tracki #define LABEL(string) (s->no_gettext ? (string) : _(string)) if (s->is_initial) - color_fprintf(s->fp, header_color, LABEL(N_("Initial commit on "))); + color_fprintf(s->fp, header_color, LABEL(N_("No commits yet on "))); if (!strcmp(s->branch, "HEAD")) { color_fprintf(s->fp, color(WT_STATUS_NOBRANCH, s), "%s", diff --combined wt-status.h index d8ae2e590d,2389f08390..64f4d33ea1 --- a/wt-status.h +++ b/wt-status.h @@@ -76,8 -76,8 +76,9 @@@ struct wt_status char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN]; unsigned colopts; int null_termination; + int commit_template; int show_branch; + int show_stash; int hints; enum wt_status_format status_format;