@@ -302,7 +302,7 @@ static void write_cherry_pick_head(struct commit *commit)
302
302
strbuf_release (& buf );
303
303
}
304
304
305
- static void print_advice (void )
305
+ static void print_advice (int show_hint )
306
306
{
307
307
char * msg = getenv ("GIT_CHERRY_PICK_HELP" );
308
308
@@ -317,9 +317,11 @@ static void print_advice(void)
317
317
return ;
318
318
}
319
319
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
+ }
323
325
}
324
326
325
327
static 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)
564
566
strbuf_addstr (& msgbuf , sha1_to_hex (commit -> object .sha1 ));
565
567
strbuf_addstr (& msgbuf , ")\n" );
566
568
}
567
- if (!opts -> no_commit )
568
- write_cherry_pick_head (commit );
569
569
}
570
570
571
571
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)
586
586
free_commit_list (remotes );
587
587
}
588
588
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
+
589
598
if (res ) {
590
599
error (opts -> action == REVERT
591
600
? _ ("could not revert %s... %s" )
592
601
: _ ("could not apply %s... %s" ),
593
602
find_unique_abbrev (commit -> object .sha1 , DEFAULT_ABBREV ),
594
603
msg .subject );
595
- print_advice ();
604
+ print_advice (res == 1 );
596
605
rerere (opts -> allow_rerere_auto );
597
606
} else {
598
607
if (!opts -> no_commit )
0 commit comments