Browse Source

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>
maint
Kaartic Sivaraam 8 years ago committed by Junio C Hamano
parent
commit
4ddb1354e8
  1. 1
      builtin/commit.c
  2. 2
      t/t7501-commit.sh
  3. 30
      t/t7508-status.sh
  4. 7
      wt-status.c
  5. 1
      wt-status.h

1
builtin/commit.c

@ -1648,6 +1648,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) @@ -1648,6 +1648,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
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;


2
t/t7501-commit.sh

@ -18,7 +18,7 @@ test_expect_success 'initial status' ' @@ -18,7 +18,7 @@ test_expect_success 'initial status' '
echo bongo bongo >file &&
git add file &&
git status >actual &&
test_i18ngrep "Initial commit" actual
test_i18ngrep "No commits yet" actual
'

test_expect_success 'fail initial amend' '

30
t/t7508-status.sh

@ -1499,4 +1499,34 @@ test_expect_success 'git commit -m will commit a staged but ignored submodule' ' @@ -1499,4 +1499,34 @@ test_expect_success 'git commit -m will commit a staged but ignored submodule' '
git config -f .gitmodules --remove-section submodule.subname
'

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

7
wt-status.c

@ -1578,7 +1578,10 @@ static void wt_longstatus_print(struct wt_status *s) @@ -1578,7 +1578,10 @@ static void wt_longstatus_print(struct wt_status *s)

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", "");
}

@ -1748,7 +1751,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s) @@ -1748,7 +1751,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
#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",

1
wt-status.h

@ -76,6 +76,7 @@ struct wt_status { @@ -76,6 +76,7 @@ struct wt_status {
char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
unsigned colopts;
int null_termination;
int commit_template;
int show_branch;
int hints;


Loading…
Cancel
Save