Skip to content

Commit c17592a

Browse files
peffgitster
authored andcommitted
commit: tweak empty cherry pick advice for sequencer
When we refuse to make an empty commit, we check whether we are in a cherry-pick in order to give better advice on how to proceed. We instruct the user to repeat the commit with "--allow-empty" to force the commit, or to use "git reset" to skip it and abort the cherry-pick. In the case of a single cherry-pick, the distinction between skipping and aborting is not important, as there is no more work to be done afterwards. When we are using the sequencer to cherry pick a series of commits, though, the instruction is confusing: does it skip this commit, or does it abort the rest of the cherry-pick? It does skip, after which the user can continue the cherry-pick. This is the right thing to be advising the user to do, but let's make it more clear what will happen, both by using the word "skip", and by mentioning that the rest of the sequence can be continued via "cherry-pick --continue" (whether we skip or take the commit). Noticed-by: Ramkumar Ramachandra <[email protected]> Helped-by: Jonathan Nieder <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1599999 commit c17592a

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

builtin/commit.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,18 @@ N_("The previous cherry-pick is now empty, possibly due to conflict resolution.\
6262
"If you wish to commit it anyway, use:\n"
6363
"\n"
6464
" git commit --allow-empty\n"
65+
"\n");
66+
67+
static const char empty_cherry_pick_advice_single[] =
68+
N_("Otherwise, please use 'git reset'\n");
69+
70+
static const char empty_cherry_pick_advice_multi[] =
71+
N_("If you wish to skip this commit, use:\n"
6572
"\n"
66-
"Otherwise, please use 'git reset'\n");
73+
" git reset\n"
74+
"\n"
75+
"Then \"git cherry-pick --continue\" will resume cherry-picking\n"
76+
"the remaining commits.\n");
6777

6878
static const char *use_message_buffer;
6979
static const char commit_editmsg[] = "COMMIT_EDITMSG";
@@ -106,6 +116,7 @@ static enum {
106116
static char *cleanup_arg;
107117

108118
static enum commit_whence whence;
119+
static int sequencer_in_use;
109120
static int use_editor = 1, include_status = 1;
110121
static int show_ignored_in_status;
111122
static const char *only_include_assumed;
@@ -133,8 +144,11 @@ static void determine_whence(struct wt_status *s)
133144
{
134145
if (file_exists(git_path("MERGE_HEAD")))
135146
whence = FROM_MERGE;
136-
else if (file_exists(git_path("CHERRY_PICK_HEAD")))
147+
else if (file_exists(git_path("CHERRY_PICK_HEAD"))) {
137148
whence = FROM_CHERRY_PICK;
149+
if (file_exists(git_path("sequencer")))
150+
sequencer_in_use = 1;
151+
}
138152
else
139153
whence = FROM_COMMIT;
140154
if (s)
@@ -799,8 +813,13 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
799813
run_status(stdout, index_file, prefix, 0, s);
800814
if (amend)
801815
fputs(_(empty_amend_advice), stderr);
802-
else if (whence == FROM_CHERRY_PICK)
816+
else if (whence == FROM_CHERRY_PICK) {
803817
fputs(_(empty_cherry_pick_advice), stderr);
818+
if (!sequencer_in_use)
819+
fputs(_(empty_cherry_pick_advice_single), stderr);
820+
else
821+
fputs(_(empty_cherry_pick_advice_multi), stderr);
822+
}
804823
return 0;
805824
}
806825

0 commit comments

Comments
 (0)