Thread (17 messages) flat view 17 messages, 4 authors, 2016-06-15

Re: [PATCH 4/3] revert: write REVERT_HEAD pseudoref during conflicted revert

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:52:33

Hi,

Jonathan Nieder wrote:
[...]
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.
Sounds a lot like CHERRY_PICK_HEAD counterpart.  Let's read ahead and
see if there are any unexpected differences.
quoted hunk ↗ jump to hunk
diff --git a/branch.c b/branch.c
index d8098762..025a97be 100644
--- a/branch.c
+++ b/branch.c
@@ -241,6 +241,7 @@ void create_branch(const char *head,
 void remove_branch_state(void)
 {
       unlink(git_path("CHERRY_PICK_HEAD"));
+       unlink(git_path("REVERT_HEAD"));
       unlink(git_path("MERGE_HEAD"));
       unlink(git_path("MERGE_RR"));
       unlink(git_path("MERGE_MSG"));
diff --git a/builtin/commit.c b/builtin/commit.c
index c46f2d18..8f2bebec 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"));
So far so good.  Behaves exactly like CHERRY_PICK_HEAD.
quoted hunk ↗ jump to hunk
diff --git a/builtin/revert.c b/builtin/revert.c
index 1d112e4c..f5ba67a5 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
Interesting.  This additional symmetry will probably make life much
easier for my pending "New Sequencer Workflow! v2" series.
quoted hunk ↗ jump to hunk
diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh
index cb45574a..ee1659c1 100755
--- a/t/t3507-cherry-pick-conflict.sh
+++ b/t/t3507-cherry-pick-conflict.sh
[...]
And some tests.  Nice.

Thanks.

-- Ram
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help