diff options
author | Jonathan Nieder <jrnieder@gmail.com> | 2011-11-22 15:17:36 +0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-11-23 01:34:44 +0400 |
commit | 82433cdf4d888639cecddeca162d619cf370417e (patch) | |
tree | f079ee84d7364d734bfeb24ffc17b1451a26893c /builtin | |
parent | b8c74690b20b7c4dd405f71d63bab325447356da (diff) |
revert: write REVERT_HEAD pseudoref during conflicted revert
When conflicts are encountered while reverting a commit, it can be
handy to have the name of that commit easily available. For example,
to produce a copy of the patch to refer to while resolving conflicts:
$ git revert 2eceb2a8
error: could not revert 2eceb2a8... awesome, buggy feature
$ git show -R REVERT_HEAD >the-patch
$ edit $(git diff --name-only)
Set a REVERT_HEAD pseudoref when "git revert" does not make a commit,
for cases like this. This also makes it possible for scripts to
distinguish between a revert that encountered conflicts and other
sources of an unmerged index.
After successfully committing, resetting with "git reset", or moving
to another commit with "git checkout" or "git reset", the pseudoref is
no longer useful, so remove it.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/commit.c | 1 | ||||
-rw-r--r-- | builtin/revert.c | 8 |
2 files changed, 6 insertions, 3 deletions
diff --git a/builtin/commit.c b/builtin/commit.c index c46f2d18e1..8f2bebecf3 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1514,6 +1514,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) } unlink(git_path("CHERRY_PICK_HEAD")); + unlink(git_path("REVERT_HEAD")); unlink(git_path("MERGE_HEAD")); unlink(git_path("MERGE_MSG")); unlink(git_path("MERGE_MODE")); diff --git a/builtin/revert.c b/builtin/revert.c index 1d112e4ce4..f5ba67a505 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -289,7 +289,7 @@ static char *get_encoding(const char *message) return NULL; } -static void write_cherry_pick_head(struct commit *commit) +static void write_cherry_pick_head(struct commit *commit, const char *pseudoref) { const char *filename; int fd; @@ -297,7 +297,7 @@ static void write_cherry_pick_head(struct commit *commit) strbuf_addf(&buf, "%s\n", sha1_to_hex(commit->object.sha1)); - filename = git_path("CHERRY_PICK_HEAD"); + filename = git_path(pseudoref); fd = open(filename, O_WRONLY | O_CREAT, 0666); if (fd < 0) die_errno(_("Could not open '%s' for writing"), filename); @@ -597,7 +597,9 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts) * write it at all. */ if (opts->action == CHERRY_PICK && !opts->no_commit && (res == 0 || res == 1)) - write_cherry_pick_head(commit); + write_cherry_pick_head(commit, "CHERRY_PICK_HEAD"); + if (opts->action == REVERT && ((opts->no_commit && res == 0) || res == 1)) + write_cherry_pick_head(commit, "REVERT_HEAD"); if (res) { error(opts->action == REVERT |