status: contextually notify user about an initial commit

The existing message, "Initial commit", makes sense for the commit template notifying users that it's their initial commit, but is confusing when merely checking the status of a fresh repository (or orphan branch) without having any commits yet. Change the output of "status" to say "No commits yet" when "git status" is run on a fresh repo (or orphan branch), while retaining the current "Initial commit" message displayed in the template that's displayed in the editor when the initial commit is being authored. Correspondingly change the output of "short status" to "No commits yet on " when "git status -sb" is run on a fresh repo (or orphan branch). A few alternatives considered were, * Waiting for initial commit * Your current branch does not have any commits * Current branch waiting for initial commit The most succint one among the alternatives was chosen. [with help on tests from Ævar] Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kaartic Sivaraam committed Jun 21, 2017 at 23:46 UTC 4ddb1354e8d5daf5671d3d451a67d2d1e82d9b49
5 files changed +38 -3
builtin/commit.c
+1
@@ -1648,6 +1648,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1648 usage_with_options(builtin_commit_usage, builtin_commit_options);
1649
1650 status_init_config(&s, git_commit_config);
1651 + s.commit_template = 1;
1652 status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
1653 s.colopts = 0;
1654
t/t7501-commit.sh
+1 -1
@@ -18,7 +18,7 @@ test_expect_success 'initial status' '
18 echo bongo bongo >file &&
19 git add file &&
20 git status >actual &&
21 - test_i18ngrep "Initial commit" actual
21 + test_i18ngrep "No commits yet" actual
22 '
23
24 test_expect_success 'fail initial amend' '
t/t7508-status.sh
+30
@@ -1499,4 +1499,34 @@ test_expect_success 'git commit -m will commit a staged but ignored submodule' '
1499 git config -f .gitmodules --remove-section submodule.subname
1500 '
1501
1502 +test_expect_success '"No commits yet" should be noted in status output' '
1503 + git checkout --orphan empty-branch-1 &&
1504 + git status >output &&
1505 + test_i18ngrep "No commits yet" output
1506 +'
1507 +
1508 +test_expect_success '"No commits yet" should not be noted in status output' '
1509 + git checkout --orphan empty-branch-2 &&
1510 + test_commit test-commit-1 &&
1511 + git status >output &&
1512 + test_i18ngrep ! "No commits yet" output
1513 +'
1514 +
1515 +test_expect_success '"Initial commit" should be noted in commit template' '
1516 + git checkout --orphan empty-branch-3 &&
1517 + touch to_be_committed_1 &&
1518 + git add to_be_committed_1 &&
1519 + git commit --dry-run >output &&
1520 + test_i18ngrep "Initial commit" output
1521 +'
1522 +
1523 +test_expect_success '"Initial commit" should not be noted in commit template' '
1524 + git checkout --orphan empty-branch-4 &&
1525 + test_commit test-commit-2 &&
1526 + touch to_be_committed_2 &&
1527 + git add to_be_committed_2 &&
1528 + git commit --dry-run >output &&
1529 + test_i18ngrep ! "Initial commit" output
1530 +'
1531 +
1532 test_done
wt-status.c
+5 -2
@@ -1578,7 +1578,10 @@ static void wt_longstatus_print(struct wt_status *s)
1578
1579 if (s->is_initial) {
1580 status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", "");
1581 - status_printf_ln(s, color(WT_STATUS_HEADER, s), _("Initial commit"));
1581 + status_printf_ln(s, color(WT_STATUS_HEADER, s),
1582 + s->commit_template
1583 + ? _("Initial commit")
1584 + : _("No commits yet"));
1585 status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", "");
1586 }
1587
@@ -1748,7 +1751,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
1751 #define LABEL(string) (s->no_gettext ? (string) : _(string))
1752
1753 if (s->is_initial)
1751 - color_fprintf(s->fp, header_color, LABEL(N_("Initial commit on ")));
1754 + color_fprintf(s->fp, header_color, LABEL(N_("No commits yet on ")));
1755
1756 if (!strcmp(s->branch, "HEAD")) {
1757 color_fprintf(s->fp, color(WT_STATUS_NOBRANCH, s), "%s",
wt-status.h
+1
@@ -76,6 +76,7 @@ struct wt_status {
76 char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
77 unsigned colopts;
78 int null_termination;
79 + int commit_template;
80 int show_branch;
81 int hints;
82