aboutsummaryrefslogtreecommitdiff
path: root/builtin/revert.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2010-08-11 03:37:51 -0500
committerJunio C Hamano <gitster@pobox.com>2010-08-15 19:12:08 -0700
commit314eeb6e483350cc7ef0bee0498ff24a12346495 (patch)
tree2411b1879f3099e75ac5a20af968770f77e6f144 /builtin/revert.c
parent981ff5c37ae20687c98d98c8689d5e89016026d2 (diff)
downloadgit-314eeb6e483350cc7ef0bee0498ff24a12346495.tar.gz
git-314eeb6e483350cc7ef0bee0498ff24a12346495.tar.xz
cherry-pick/revert: Use advise() for hints
When cherry-pick fails after picking a large series of commits, it can be hard to pick out the error message and advice. Prefix the advice with “hint: ” to help. Before: error: could not apply 7ab78c9... foo After resolving the conflicts, mark the corrected paths with 'git add <paths>' or 'git rm <paths>' and commit the result with: git commit -c 7ab78c9a7898b87127365478431289cb98f8d98f After: error: could not apply 7ab78c9... foo hint: after resolving the conflicts, mark the corrected paths hint: with 'git add <paths>' or 'git rm <paths>' hint: and commit the result with 'git commit -c 7ab78c9' Noticed-by: Thomas Rast <trast@student.ethz.ch> Encouraged-by: Sverre Rabbelier <srabbelier@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/revert.c')
-rw-r--r--builtin/revert.c34
1 files changed, 11 insertions, 23 deletions
diff --git a/builtin/revert.c b/builtin/revert.c
index 9a7483b66..7f35cc6e1 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -250,27 +250,21 @@ static void advise(const char *advice, ...)
va_end(params);
}
-static char *help_msg(void)
+static void print_advice(void)
{
- struct strbuf helpbuf = STRBUF_INIT;
char *msg = getenv("GIT_CHERRY_PICK_HELP");
- if (msg)
- return msg;
+ if (msg) {
+ fprintf(stderr, "%s\n", msg);
+ return;
+ }
- strbuf_addstr(&helpbuf, " After resolving the conflicts,\n"
- "mark the corrected paths with 'git add <paths>' or 'git rm <paths>'\n"
- "and commit the result");
+ advise("after resolving the conflicts, mark the corrected paths");
+ advise("with 'git add <paths>' or 'git rm <paths>'");
- if (action == CHERRY_PICK) {
- strbuf_addf(&helpbuf, " with: \n"
- "\n"
- " git commit -c %s\n",
- sha1_to_hex(commit->object.sha1));
- }
- else
- strbuf_addch(&helpbuf, '.');
- return strbuf_detach(&helpbuf, NULL);
+ if (action == CHERRY_PICK)
+ advise("and commit the result with 'git commit -c %s'",
+ find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
}
static void write_message(struct strbuf *msgbuf, const char *filename)
@@ -404,7 +398,6 @@ static int do_pick_commit(void)
struct commit_message msg = { NULL, NULL, NULL, NULL, NULL };
char *defmsg = NULL;
struct strbuf msgbuf = STRBUF_INIT;
- struct strbuf mebuf = STRBUF_INIT;
int res;
if (no_commit) {
@@ -501,9 +494,6 @@ static int do_pick_commit(void)
}
}
- strbuf_addf(&mebuf, "%s of commit %s", me,
- find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
-
if (!strategy || !strcmp(strategy, "recursive") || action == REVERT) {
res = do_recursive_merge(base, next, base_label, next_label,
head, &msgbuf);
@@ -512,7 +502,6 @@ static int do_pick_commit(void)
struct commit_list *common = NULL;
struct commit_list *remotes = NULL;
- strbuf_addf(&mebuf, " with strategy %s", strategy);
write_message(&msgbuf, defmsg);
commit_list_insert(base, &common);
@@ -528,14 +517,13 @@ static int do_pick_commit(void)
action == REVERT ? "revert" : "apply",
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV),
msg.subject);
- fprintf(stderr, help_msg());
+ print_advice();
rerere(allow_rerere_auto);
} else {
if (!no_commit)
res = run_git_commit(defmsg);
}
- strbuf_release(&mebuf);
free_message(&msg);
free(defmsg);