Skip to content

Commit f23477c

Browse files
committed
commit: display advice hints when commit fails
Display hints to the user when trying to commit without staging the modified files first (when advice.statusHints is set to true). Change the output of the unsuccessful commit from e.g: # [...] # Changes not staged for commit: # modified: builtin/commit.c # # no changes added to commit to: # [...] # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: ../builtin/commit.c # # no changes added to commit (use "git add" and/or "git commit -a") In ea9882b (commit: disable status hints when writing to COMMIT_EDITMSG, 2013-09-12) the intent was to disable status hints when writing to COMMIT_EDITMSG, but in fact the implementation disabled status messages in more locations, e.g in case the commit wasn't successful, status hints will still be disabled and no hints will be displayed to the user although advice.statusHints is set to true. Signed-off-by: Heba Waly <[email protected]>
1 parent ad05a3d commit f23477c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

builtin/commit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
961961
*/
962962
if (!committable && whence != FROM_MERGE && !allow_empty &&
963963
!(amend && is_a_merge(current_head))) {
964+
s->hints = advice_status_hints;
964965
s->display_comment_prefix = old_display_comment_prefix;
965966
run_status(stdout, index_file, prefix, 0, s);
966967
if (amend)

t/t7500-commit-template-squash-signoff.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,4 +382,13 @@ test_expect_success 'check commit with unstaged rename and copy' '
382382
)
383383
'
384384

385+
test_expect_success 'commit without staging files fails and displays hints' '
386+
echo "initial" >>file &&
387+
git add file &&
388+
git commit -m initial &&
389+
echo "changes" >>file &&
390+
test_must_fail git commit -m initial >actual &&
391+
test_i18ngrep "no changes added to commit (use \"git add\" and/or \"git commit -a\")" actual
392+
'
393+
385394
test_done

0 commit comments

Comments
 (0)