aboutsummaryrefslogtreecommitdiff
path: root/builtin/revert.c
diff options
context:
space:
mode:
authorJay Soffian <jaysoffian@gmail.com>2011-02-19 23:12:27 -0500
committerJunio C Hamano <gitster@pobox.com>2011-02-21 22:58:02 -0800
commitd7e5c0cbfb0421d8a609f1125267dbad73069410 (patch)
tree7b19c3c4182cdbf42d260f4da024c2774718c6b0 /builtin/revert.c
parent2161da103950704a92993702696c9b573dcbccae (diff)
downloadgit-d7e5c0cbfb0421d8a609f1125267dbad73069410.tar.gz
git-d7e5c0cbfb0421d8a609f1125267dbad73069410.tar.xz
Introduce CHERRY_PICK_HEAD
When a cherry-pick conflicts git advises: $ git commit -c <original commit id> to preserve the original commit message and authorship. Instead, let's record the original commit id in CHERRY_PICK_HEAD and advise: $ git commit -c CHERRY_PICK_HEAD A later patch teaches git to handle the '-c CHERRY_PICK_HEAD' part. Note that we record CHERRY_PICK_HEAD even in the case where there are no conflicts so that we may use it to communicate authorship to commit; this will then allow us to remove set_author_ident_env from revert.c. However, we do not record CHERRY_PICK_HEAD when --no-commit is used, as presumably the user intends to further edit the commit and possibly even cherry-pick additional commits on top. Tests and documentation contributed by Jonathan Nieder. Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/revert.c')
-rw-r--r--builtin/revert.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/builtin/revert.c b/builtin/revert.c
index bb6e9e83b..e716a1b00 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -231,6 +231,22 @@ static void set_author_ident_env(const char *message)
sha1_to_hex(commit->object.sha1));
}
+static void write_cherry_pick_head(void)
+{
+ int fd;
+ struct strbuf buf = STRBUF_INIT;
+
+ strbuf_addf(&buf, "%s\n", sha1_to_hex(commit->object.sha1));
+
+ fd = open(git_path("CHERRY_PICK_HEAD"), O_WRONLY | O_CREAT, 0666);
+ if (fd < 0)
+ die_errno("Could not open '%s' for writing",
+ git_path("CHERRY_PICK_HEAD"));
+ if (write_in_full(fd, buf.buf, buf.len) != buf.len || close(fd))
+ die_errno("Could not write to '%s'", git_path("CHERRY_PICK_HEAD"));
+ strbuf_release(&buf);
+}
+
static void advise(const char *advice, ...)
{
va_list params;
@@ -246,6 +262,12 @@ static void print_advice(void)
if (msg) {
fprintf(stderr, "%s\n", msg);
+ /*
+ * A conflict has occured but the porcelain
+ * (typically rebase --interactive) wants to take care
+ * of the commit itself so remove CHERRY_PICK_HEAD
+ */
+ unlink(git_path("CHERRY_PICK_HEAD"));
return;
}
@@ -253,8 +275,7 @@ static void print_advice(void)
advise("with 'git add <paths>' or 'git rm <paths>'");
if (action == CHERRY_PICK)
- advise("and commit the result with 'git commit -c %s'",
- find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
+ advise("and commit the result with 'git commit -c CHERRY_PICK_HEAD'");
}
static void write_message(struct strbuf *msgbuf, const char *filename)
@@ -489,6 +510,8 @@ static int do_pick_commit(void)
strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
strbuf_addstr(&msgbuf, ")\n");
}
+ if (!no_commit)
+ write_cherry_pick_head();
}
if (!strategy || !strcmp(strategy, "recursive") || action == REVERT) {