Suggest use of 'git add' when 'nothing to commit' gets shown.
PATCH 1/2 Suggest use of 'git add' when 'nothing to commit' gets shown.
If a user modifies files and runs 'git commit' (without the very useful -a option) and they have not yet updated the index they are probably coming from another SCM-like tool which would perform the same as 'git commit -a' in this case. Showing the user their current status and a final line of "nothing to commit" is not very reassuring, as the user might believe that Git did not recognize their files were modified.
Instead we can suggest as part of the 'nothing to commit' message that the user invoke 'git add' to add files to their next commit.
Suggested by Andy Parkins in his Git 'niggles' list (<[email protected]>).
--- git-commit.sh | 2 +- wt-status.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-)
git-commit.sh +1 -1
@@ -515,7 +515,7 @@ then current="$(git-rev-parse --verify HEAD)" else if [ -z "$(git-ls-files)" ]; then - echo >&2 Nothing to commit + echo >&2 "Nothing to commit (use \"git add\" include for commit)" exit 1 fi PARENTS=""
wt-status.c +4 -3
@@ -163,7 +163,7 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,int i;if (q->nr)wt_status_print_header ("Changed but not updated" , -"use git-add on files to include for commit" ); +"use \"git add\" on files to include for commit" );for (i =0 ; i < q->nr; i++)wt_status_print_filepair (WT_STATUS_CHANGED , q->queue[i]);if (q->nr)
@@ -250,7 +250,7 @@ static void wt_status_print_untracked(const struct wt_status *s) }if (!shown_header) {wt_status_print_header ("Untracked files" , -"use \"git add\" to add to commit" ); +"use \"git add\" on files to include for commit" ); shown_header =1 ; }color_printf (color (WT_STATUS_HEADER ),"#\t" );
@@ -292,7 +292,8 @@ void wt_status_print(struct wt_status *s)if (s->verbose && !s->is_initial)wt_status_print_verbose (s);if (!s->commitable) -printf ("%s\n" , s->amend ?"# No changes" :"nothing to commit" ); +printf ("%s (use \"git add\" include for commit)\n" , + s->amend ?"# No changes" :"Nothing to commit" ); }int git_status_config (const char *k,const char *v)
Signature · 1 line
1.4.4.2.g72f5
git-commit.sh then · line 518
Quoted 4 lines · Shawn O. Pearce
else
git-commit.sh +1
-1if [ -z "$(git-ls-files)" ]; then - echo >&2 Nothing to commit + echo >&2 "Nothing to commit (use \"git add\" include for commit)"
s/git add include/git add to include/
wt-status.c static void wt_status_print_changed_cb(struct diff_queue_struct *q, · line 166
Quoted 13 lines
git-commit.sh +0
-0exit 1 fi PARENTS=""wt-status.c +1
-1@@ -163,7 +163,7 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,int i;if (q->nr)wt_status_print_header ("Changed but not updated" , -"use git-add on files to include for commit" ); +"use \"git add\" on files to include for commit" );
Here it's "on files", whereas in other threads people have stated that git add adds content, so perhaps
use \"git add file1 file2\" to include for commit
which also gives a nice "simplest-possible-usage" message.
wt-status.c static void wt_status_print_untracked(const struct wt_status *s) · line 253
Quoted 4 lines
wt-status.c +1
-1if (!shown_header) {wt_status_print_header ("Untracked files" , -"use \"git add\" to add to commit" ); +"use \"git add\" on files to include for commit" );
Same here.
wt-status.c void wt_status_print(struct wt_status *s) · line 297
Quoted 5 lines
wt-status.c +2
-1if (!s->commitable) -printf ("%s\n" , s->amend ?"# No changes" :"nothing to commit" ); +printf ("%s (use \"git add\" include for commit)\n" , + s->amend ?"# No changes" :"Nothing to commit" ); }
This is same as first one (missing "to " before "include").
It would probably be nice to use one and the same message everywhere though.
Signature · 2 lines
Andreas Ericsson [email protected] OP5 AB www.op5.se
Quoted 8 lines · Andreas Ericsson
Quoted 5 lines · Shawn O. Pearce
else
if [ -z "$(git-ls-files)" ]; then(quoted diff) +1
-1- echo >&2 Nothing to commit + echo >&2 "Nothing to commit (use \"git add\" include forcommit)"
s/git add
include/gitadd toinclude/
Thanks! I'm going to rewrite this patch series as I clearly fumbled a few items, which you were kind enough to take the time to point out for me.
Quoted 1 line
It would probably be nice to use one and the same message everywhere though.
That was my intent. My fingers failed me somehow. ;-)