@@ -302,7 +302,7 @@ static void write_cherry_pick_head(struct commit *commit)
302302 strbuf_release (& buf );
303303}
304304
305- static void print_advice (void )
305+ static void print_advice (int show_hint )
306306{
307307 char * msg = getenv ("GIT_CHERRY_PICK_HELP" );
308308
@@ -317,9 +317,11 @@ static void print_advice(void)
317317 return ;
318318 }
319319
320- advise ("after resolving the conflicts, mark the corrected paths" );
321- advise ("with 'git add <paths>' or 'git rm <paths>'" );
322- advise ("and commit the result with 'git commit'" );
320+ if (show_hint ) {
321+ advise ("after resolving the conflicts, mark the corrected paths" );
322+ advise ("with 'git add <paths>' or 'git rm <paths>'" );
323+ advise ("and commit the result with 'git commit'" );
324+ }
323325}
324326
325327static void write_message (struct strbuf * msgbuf , const char * filename )
@@ -564,8 +566,6 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
564566 strbuf_addstr (& msgbuf , sha1_to_hex (commit -> object .sha1 ));
565567 strbuf_addstr (& msgbuf , ")\n" );
566568 }
567- if (!opts -> no_commit )
568- write_cherry_pick_head (commit );
569569 }
570570
571571 if (!opts -> strategy || !strcmp (opts -> strategy , "recursive" ) || opts -> action == REVERT ) {
@@ -586,13 +586,22 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
586586 free_commit_list (remotes );
587587 }
588588
589+ /*
590+ * If the merge was clean or if it failed due to conflict, we write
591+ * CHERRY_PICK_HEAD for the subsequent invocation of commit to use.
592+ * However, if the merge did not even start, then we don't want to
593+ * write it at all.
594+ */
595+ if (opts -> action == CHERRY_PICK && !opts -> no_commit && (res == 0 || res == 1 ))
596+ write_cherry_pick_head (commit );
597+
589598 if (res ) {
590599 error (opts -> action == REVERT
591600 ? _ ("could not revert %s... %s" )
592601 : _ ("could not apply %s... %s" ),
593602 find_unique_abbrev (commit -> object .sha1 , DEFAULT_ABBREV ),
594603 msg .subject );
595- print_advice ();
604+ print_advice (res == 1 );
596605 rerere (opts -> allow_rerere_auto );
597606 } else {
598607 if (!opts -> no_commit )
0 commit comments