Skip to content

Commit 4d50dbc

Browse files
committed
Merge branch 'ph/cherry-pick-advice-refinement'
* ph/cherry-pick-advice-refinement: cherry-pick: No advice to commit if --no-commit
2 parents 524ee67 + ed727b1 commit 4d50dbc

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

sequencer.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static void write_cherry_pick_head(struct commit *commit, const char *pseudoref)
123123
strbuf_release(&buf);
124124
}
125125

126-
static void print_advice(int show_hint)
126+
static void print_advice(int show_hint, struct replay_opts *opts)
127127
{
128128
char *msg = getenv("GIT_CHERRY_PICK_HELP");
129129

@@ -138,10 +138,15 @@ static void print_advice(int show_hint)
138138
return;
139139
}
140140

141-
if (show_hint)
142-
advise(_("after resolving the conflicts, mark the corrected paths\n"
143-
"with 'git add <paths>' or 'git rm <paths>'\n"
144-
"and commit the result with 'git commit'"));
141+
if (show_hint) {
142+
if (opts->no_commit)
143+
advise(_("after resolving the conflicts, mark the corrected paths\n"
144+
"with 'git add <paths>' or 'git rm <paths>'"));
145+
else
146+
advise(_("after resolving the conflicts, mark the corrected paths\n"
147+
"with 'git add <paths>' or 'git rm <paths>'\n"
148+
"and commit the result with 'git commit'"));
149+
}
145150
}
146151

147152
static void write_message(struct strbuf *msgbuf, const char *filename)
@@ -423,7 +428,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
423428
: _("could not apply %s... %s"),
424429
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV),
425430
msg.subject);
426-
print_advice(res == 1);
431+
print_advice(res == 1, opts);
427432
rerere(opts->allow_rerere_auto);
428433
} else {
429434
if (!opts->no_commit)

t/t3507-cherry-pick-conflict.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ test_expect_success 'advice from failed cherry-pick' "
5959
test_i18ncmp expected actual
6060
"
6161

62+
test_expect_success 'advice from failed cherry-pick --no-commit' "
63+
pristine_detach initial &&
64+
65+
picked=\$(git rev-parse --short picked) &&
66+
cat <<-EOF >expected &&
67+
error: could not apply \$picked... picked
68+
hint: after resolving the conflicts, mark the corrected paths
69+
hint: with 'git add <paths>' or 'git rm <paths>'
70+
EOF
71+
test_must_fail git cherry-pick --no-commit picked 2>actual &&
72+
73+
test_i18ncmp expected actual
74+
"
75+
6276
test_expect_success 'failed cherry-pick sets CHERRY_PICK_HEAD' '
6377
pristine_detach initial &&
6478
test_must_fail git cherry-pick picked &&

0 commit comments

Comments
 (0)