Re: [PATCH/ALMOST FINAL] Contextually notify user about an initial commit
From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2017-06-18 08:35:08
Subsystem:
the rest · Maintainer:
Linus Torvalds
Possibly related (same subject, not in this thread)
- 2017-06-19 · Re: [PATCH/ALMOST FINAL] Contextually notify user about an initial commit · Junio C Hamano <hidden>
On Sun, Jun 18 2017, Kaartic Sivaraam jotted:
quoted hunk ↗ jump to hunk
"git status" indicated "Initial commit" when HEAD points at an unborn branch. This message is shared with the commit log template "git commit" prepares for the user when creating a commit (i.e. "You are about to create the initial commit"), and is OK as long as the reader is aware of the nature of the message (i.e. it guides the user working toward the next commit), but was confusing to new users, especially the ones who do "git commit -m message" without having a chance to pay attention to the commit log template. The "Initial commit" indication wasn't an issue in the commit template. Taking that into consideration, a good solution would be to contextually use different messages to indicate the user that there were no commits in this branch. A few alternatives considered were, * Waiting for initial commit * Your current branch does not have any commits * Current branch waiting for initial commit Patch-by: Junio C Hamano [off-list ref] Signed-off-by: Kaartic Sivaraam <redacted> --- builtin/commit.c | 1 + wt-status.c | 5 ++++- wt-status.h | 1 + 3 files changed, 6 insertions(+), 1 deletion(-)diff --git a/builtin/commit.c b/builtin/commit.c index 1d805f5da..0f36d2ac3 100644 --- a/builtin/commit.c +++ b/builtin/commit.c@@ -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;diff --git a/wt-status.c b/wt-status.c index 037548496..34aa1af66 100644 --- a/wt-status.c +++ b/wt-status.c@@ -1576,7 +1576,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 on the branch"));
Why not simply "No commits yet", saying "on the branch" is needlessy
duplicating information in the context of the status output in which
this is printed, i.e. now you have:
$ ~/g/git/git-status
On branch master
No commits yet on the branch
nothing to commit (create/copy files and use "git add" to track)
But we can just more succinctly say:
$ ~/g/git/git-status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
Since we've already pointed out that the user is on a branch.
Also, if something is worth fixing it's worth testing for, so you can
fix this test into the patch:
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 79427840a4..b9532d201d 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh@@ -1608,4 +1608,15 @@ 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 init initial && + cd initial && + git status >output && + test_i18ngrep "No commits yet" output && + test_commit initial && + git status >output && + test_i18ngrep ! "No commits yet" output && + test_i18ngrep "nothing.*to commit" output +' + test_done
diff --git a/wt-status.c b/wt-status.c
index 7991fd1098..f324ea20a6 100644
--- a/wt-status.c
+++ b/wt-status.c@@ -1582,7 +1582,7 @@ static void wt_longstatus_print(struct wt_status *s) status_printf_ln(s, color(WT_STATUS_HEADER, s), s->commit_template ? _("Initial commit") - : _("No commits yet on the branch")); + : _("No commits yet")); status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", ""); }
quoted hunk ↗ jump to hunk
status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", ""); }diff --git a/wt-status.h b/wt-status.h index 6018c627b..782b2997f 100644 --- a/wt-status.h +++ b/wt-status.h@@ -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;