cherry-pick: No advice to commit if --no-commit

When cherry-pick fails it offers a helpful hint about how to proceed. The hint tells the user how to do the cleanup needed by the conflicted cherry-pick and finish the job after conflict resolution. In case of cherry-pick --no-commit, the hint goes too far. It tells the user to finish up with 'git commit'. That is not what this git-cherry-pick was trying to do in the first place. Restrict the hint in case of --no-commit to avoid giving this extra advice. Also, add a test verifying the reduced hint for the --no-commit version of cherry-pick. Signed-off-by: Phil Hord <hordp@cisco.com> Acked-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phil Hord committed Feb 21, 2012 at 19:44 UTC ed727b192bb3506ee7904c1c9e8370d6b4ecaf5d
2 files changed +25 -6
sequencer.c
+11 -6
@@ -123,7 +123,7 @@ static void write_cherry_pick_head(struct commit *commit, const char *pseudoref)
123 strbuf_release(&buf);
124 }
125
126 -static void print_advice(int show_hint)
126 +static void print_advice(int show_hint, struct replay_opts *opts)
127 {
128 char *msg = getenv("GIT_CHERRY_PICK_HELP");
129
@@ -138,10 +138,15 @@ static void print_advice(int show_hint)
138 return;
139 }
140
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 + }
150 }
151
152 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)
428 : _("could not apply %s... %s"),
429 find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV),
430 msg.subject);
426 - print_advice(res == 1);
431 + print_advice(res == 1, opts);
432 rerere(opts->allow_rerere_auto);
433 } else {
434 if (!opts->no_commit)
t/t3507-cherry-pick-conflict.sh
+14
@@ -59,6 +59,20 @@ test_expect_success 'advice from failed cherry-pick' "
59 test_i18ncmp expected actual
60 "
61
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 +
76 test_expect_success 'failed cherry-pick sets CHERRY_PICK_HEAD' '
77 pristine_detach initial &&
78 test_must_fail git cherry-pick picked &&