@matheusbsbs / matheus-bagliano / commits / 804c7174c9
Fork 0

revert/cherry-pick: Allow overriding the help text by the calling Porcelain

A Porcelain command that uses cherry-pick or revert may make a commit out of resolved index itself, in which case telling the user to commit the result is not appropriate at all. This allows GIT_CHERRY_PICK_HELP environment variable to be set by the calling Porcelain in order to override the built-in help text. [jc: this is heavily modified from the original but should be equivalent in spirit] Signed-off-by: Junio C Hamano <gitster@pobox.com>

Wincent Colaiuta committed Nov 28, 2007 at 00:06 UTC 804c7174c9d7c81b5215bcd9002f3bd600ecb6e4
2 files changed +28 -10
builtin-revert.c
+23 -10
@@ -224,6 +224,27 @@ static int merge_recursive(const char *base_sha1,
224 return run_command_v_opt(argv, RUN_COMMAND_NO_STDIN | RUN_GIT_CMD);
225 }
226
227 +static char *help_msg(const unsigned char *sha1)
228 +{
229 + static char helpbuf[1024];
230 + char *msg = getenv("GIT_CHERRY_PICK_HELP");
231 +
232 + if (msg)
233 + return msg;
234 +
235 + strcpy(helpbuf, " After resolving the conflicts,\n"
236 + "mark the corrected paths with 'git add <paths>' "
237 + "and commit the result.");
238 +
239 + if (action == CHERRY_PICK) {
240 + sprintf(helpbuf + strlen(helpbuf),
241 + "\nWhen commiting, use the option "
242 + "'-c %s' to retain authorship and message.",
243 + find_unique_abbrev(sha1, DEFAULT_ABBREV));
244 + }
245 + return helpbuf;
246 +}
247 +
248 static int revert_or_cherry_pick(int argc, const char **argv)
249 {
250 unsigned char head[20];
@@ -352,16 +373,8 @@ static int revert_or_cherry_pick(int argc, const char **argv)
373 }
374 if (close(msg_fd) || commit_lock_file(&msg_file) < 0)
375 die ("Error wrapping up %s", defmsg);
355 - fprintf(stderr, "Automatic %s failed. "
356 - "After resolving the conflicts,\n"
357 - "mark the corrected paths with 'git add <paths>' "
358 - "and commit the result.\n", me);
359 - if (action == CHERRY_PICK) {
360 - fprintf(stderr, "When commiting, use the option "
361 - "'-c %s' to retain authorship and message.\n",
362 - find_unique_abbrev(commit->object.sha1,
363 - DEFAULT_ABBREV));
364 - }
376 + fprintf(stderr, "Automatic %s failed.%s\n",
377 + me, help_msg(commit->object.sha1));
378 exit(1);
379 }
380 if (close(msg_fd) || commit_lock_file(&msg_file) < 0)
git-rebase--interactive.sh
+5
@@ -30,6 +30,11 @@ test -d "$REWRITTEN" && PRESERVE_MERGES=t
30 test -f "$DOTEST"/strategy && STRATEGY="$(cat "$DOTEST"/strategy)"
31 test -f "$DOTEST"/verbose && VERBOSE=t
32
33 +GIT_CHERRY_PICK_HELP=" After resolving the conflicts,
34 +mark the corrected paths with 'git add <paths>', and
35 +run 'git rebase --continue'"
36 +export GIT_CHERRY_PICK_HELP
37 +
38 warn () {
39 echo "$*" >&2
40 }