git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/2] A couple of cherry-pick related fixes
@ 2019-03-29 16:30 Phillip Wood
  2019-03-29 16:30 ` [PATCH 1/2] commit/reset: try to clean up sequencer state Phillip Wood
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Phillip Wood @ 2019-03-29 16:30 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Johannes Schindelin, Junio C Hamano, Elijah Newren, Duy Nguyen,
	Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

See the actual patches for a description of the fixes, I'm not sure
about the second one, see the notes on it. I'm going to be mostly
off-line for the next couple of weeks so it might take me a while to
respond to any comments.

Phillip Wood (2):
  commit/reset: try to clean up sequencer state
  fix cherry-pick/revert status after commit

 branch.c                        |  7 ++--
 builtin/commit.c                |  7 ++--
 sequencer.c                     | 60 +++++++++++++++++++++++++++++++++
 sequencer.h                     |  3 ++
 t/t3507-cherry-pick-conflict.sh | 19 +++++++++++
 t/t7512-status-help.sh          | 19 +++++++++++
 wt-status.c                     | 12 ++++++-
 7 files changed, 122 insertions(+), 5 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH 1/2] commit/reset: try to clean up sequencer state
  2019-03-29 16:30 [PATCH 0/2] A couple of cherry-pick related fixes Phillip Wood
@ 2019-03-29 16:30 ` Phillip Wood
  2019-04-01  8:28   ` Junio C Hamano
  2019-04-01 10:09   ` Duy Nguyen
  2019-03-29 16:30 ` [PATCH 2/2] fix cherry-pick/revert status after commit Phillip Wood
  2019-04-16 10:18 ` [PATCH v2 0/2] A couple of cherry-pick related fixes Phillip Wood
  2 siblings, 2 replies; 15+ messages in thread
From: Phillip Wood @ 2019-03-29 16:30 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Johannes Schindelin, Junio C Hamano, Elijah Newren, Duy Nguyen,
	Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

When cherry-picking or reverting a sequence of commits and if the final
pick/revert has conflicts and the user uses `git commit` to commit the
conflict resolution and does not run `git cherry-pick --continue` then
the sequencer state is left behind. This can cause problems later. In my
case I cherry-picked a sequence of commits the last one of which I
committed with `git commit` after resolving some conflicts, then a while
later, on a different branch I aborted a revert which rewound my HEAD to
the end of the cherry-pick sequence on the previous branch. Avoid this
potential problem by removing the sequencer state if we're committing or
resetting the final pick in a sequence.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 branch.c                        |  7 +++++--
 builtin/commit.c                |  7 +++++--
 sequencer.c                     | 23 +++++++++++++++++++++++
 sequencer.h                     |  1 +
 t/t3507-cherry-pick-conflict.sh | 19 +++++++++++++++++++
 5 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/branch.c b/branch.c
index 28b81a7e02..9ed60081c1 100644
--- a/branch.c
+++ b/branch.c
@@ -5,6 +5,7 @@
 #include "refs.h"
 #include "refspec.h"
 #include "remote.h"
+#include "sequencer.h"
 #include "commit.h"
 #include "worktree.h"
 
@@ -339,8 +340,10 @@ void create_branch(struct repository *r,
 
 void remove_branch_state(struct repository *r)
 {
-	unlink(git_path_cherry_pick_head(r));
-	unlink(git_path_revert_head(r));
+	if (!unlink(git_path_cherry_pick_head(r)))
+		sequencer_post_commit_cleanup();
+	if (!unlink(git_path_revert_head(r)))
+		sequencer_post_commit_cleanup();
 	unlink(git_path_merge_head(r));
 	unlink(git_path_merge_rr(r));
 	unlink(git_path_merge_msg(r));
diff --git a/builtin/commit.c b/builtin/commit.c
index 2986553d5f..422b7d62a5 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1657,8 +1657,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		die("%s", err.buf);
 	}
 
-	unlink(git_path_cherry_pick_head(the_repository));
-	unlink(git_path_revert_head(the_repository));
+	if (!unlink(git_path_cherry_pick_head(the_repository)))
+		sequencer_post_commit_cleanup();
+	if (!unlink(git_path_revert_head(the_repository)))
+		sequencer_post_commit_cleanup();
 	unlink(git_path_merge_head(the_repository));
 	unlink(git_path_merge_msg(the_repository));
 	unlink(git_path_merge_mode(the_repository));
@@ -1678,6 +1680,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	if (amend && !no_post_rewrite) {
 		commit_post_rewrite(the_repository, current_head, &oid);
 	}
+
 	if (!quiet) {
 		unsigned int flags = 0;
 
diff --git a/sequencer.c b/sequencer.c
index 0db410d590..028699209f 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2220,6 +2220,29 @@ static ssize_t strbuf_read_file_or_whine(struct strbuf *sb, const char *path)
 	return len;
 }
 
+void sequencer_post_commit_cleanup(void)
+{
+	struct replay_opts opts = REPLAY_OPTS_INIT;
+	struct strbuf buf = STRBUF_INIT;
+	const char *eol;
+	const char *todo_path = git_path_todo_file();
+
+	if (strbuf_read_file(&buf, todo_path, 0) < 0) {
+		if (errno == ENOENT) {
+			return;
+		} else {
+			error_errno("unable to open '%s'", todo_path);
+			return;
+		}
+	}
+	/* If there is only one line then we are done */
+	eol = strchr(buf.buf, '\n');
+	if (!eol || !eol[1])
+		sequencer_remove_state(&opts);
+
+	strbuf_release(&buf);
+}
+
 static int read_populate_todo(struct repository *r,
 			      struct todo_list *todo_list,
 			      struct replay_opts *opts)
diff --git a/sequencer.h b/sequencer.h
index 4d505b3590..43548295a1 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -144,3 +144,4 @@ int read_author_script(const char *path, char **name, char **email, char **date,
 void parse_strategy_opts(struct replay_opts *opts, char *raw_opts);
 int write_basic_state(struct replay_opts *opts, const char *head_name,
 		      const char *onto, const char *orig_head);
+void sequencer_post_commit_cleanup(void);
diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh
index 0db166152a..69e6389e69 100755
--- a/t/t3507-cherry-pick-conflict.sh
+++ b/t/t3507-cherry-pick-conflict.sh
@@ -156,6 +156,25 @@ test_expect_success 'successful commit clears CHERRY_PICK_HEAD' '
 
 	test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
 '
+test_expect_success 'successful final commit clears sequencer state' '
+	pristine_detach initial &&
+
+	test_must_fail git cherry-pick base picked-signed &&
+	echo resolved >foo &&
+	test_path_is_file .git/sequencer/todo &&
+	git commit -a &&
+	test_must_fail test_path_exists .git/sequencer
+'
+
+test_expect_success 'reset after final pick clears sequencer state' '
+	pristine_detach initial &&
+
+	test_must_fail git cherry-pick base picked-signed &&
+	echo resolved >foo &&
+	test_path_is_file .git/sequencer/todo &&
+	git reset &&
+	test_must_fail test_path_exists .git/sequencer
+'
 
 test_expect_success 'failed cherry-pick produces dirty index' '
 	pristine_detach initial &&
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH 2/2] fix cherry-pick/revert status after commit
  2019-03-29 16:30 [PATCH 0/2] A couple of cherry-pick related fixes Phillip Wood
  2019-03-29 16:30 ` [PATCH 1/2] commit/reset: try to clean up sequencer state Phillip Wood
@ 2019-03-29 16:30 ` Phillip Wood
  2019-04-01  8:34   ` Junio C Hamano
  2019-04-16 10:18 ` [PATCH v2 0/2] A couple of cherry-pick related fixes Phillip Wood
  2 siblings, 1 reply; 15+ messages in thread
From: Phillip Wood @ 2019-03-29 16:30 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Johannes Schindelin, Junio C Hamano, Elijah Newren, Duy Nguyen,
	Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

If the user commits a conflict resolution using 'git commit' during a
sequence of picks then 'git status' missed the fact that a
cherry-pick/revert is still in progress.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---

Notes:
    I'm not user about printing the oid of the commit that was just picked,
    maybe we should just say that a cherry-pick/revert is in progress. That
    will mean auditing all the consumers of wt_status_get_state() to ensure
    they can cope with a null oid.

sequencer.c            | 37 +++++++++++++++++++++++++++++++++++++
 sequencer.h            |  2 ++
 t/t7512-status-help.sh | 19 +++++++++++++++++++
 wt-status.c            | 12 +++++++++++-
 4 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/sequencer.c b/sequencer.c
index 028699209f..5595cc786f 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2142,6 +2142,43 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
 	return !item->commit;
 }
 
+int sequencer_get_last_command(struct repository *r, enum replay_action *action,
+			       struct object_id *oid)
+{
+	struct todo_item item;
+	char *eol;
+	const char *todo_file;
+	struct strbuf buf = STRBUF_INIT;
+	int ret = -1;
+
+	todo_file = git_path_todo_file();
+	if (strbuf_read_file(&buf, todo_file, 0) < 0) {
+		if (errno == ENOENT)
+			return -1;
+		else
+			return error_errno("unable to open '%s'", todo_file);
+	}
+	eol = strchrnul(buf.buf, '\n');
+	if (buf.buf != eol && eol[-1] == '\r')
+		eol--; /* strip Carriage Return */
+	if (parse_insn_line(r, &item, buf.buf, eol))
+		goto fail;
+	if (item.command == TODO_PICK)
+		*action = REPLAY_PICK;
+	else if (item.command == TODO_REVERT)
+		*action = REPLAY_REVERT;
+	else
+		goto fail;
+
+	oidcpy(oid, &item.commit->object.oid);
+	ret = 0;
+
+ fail:
+	strbuf_release(&buf);
+
+	return ret;
+}
+
 static int parse_insn_buffer(struct repository *r, char *buf,
 			     struct todo_list *todo_list)
 {
diff --git a/sequencer.h b/sequencer.h
index 43548295a1..815c68c4a3 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -145,3 +145,5 @@ void parse_strategy_opts(struct replay_opts *opts, char *raw_opts);
 int write_basic_state(struct replay_opts *opts, const char *head_name,
 		      const char *onto, const char *orig_head);
 void sequencer_post_commit_cleanup(void);
+int sequencer_get_last_command(struct repository* r, enum replay_action *action,
+			       struct object_id *oid);
diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
index 458608cc1e..71d28a50f7 100755
--- a/t/t7512-status-help.sh
+++ b/t/t7512-status-help.sh
@@ -780,6 +780,25 @@ EOF
 	test_i18ncmp expected actual
 '
 
+test_expect_success 'status when cherry-picking after committing conflict resolution' '
+	git reset --hard cherry_branch &&
+	test_when_finished "git cherry-pick --abort" &&
+	test_must_fail git cherry-pick cherry_branch_second one_cherry &&
+	TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) &&
+	echo end >main.txt &&
+	git commit -a &&
+	cat >expected <<EOF &&
+On branch cherry_branch
+You are currently cherry-picking commit $TO_CHERRY_PICK.
+  (all conflicts fixed: run "git cherry-pick --continue")
+  (use "git cherry-pick --abort" to cancel the cherry-pick operation)
+
+nothing to commit (use -u to show untracked files)
+EOF
+	git status --untracked-files=no >actual &&
+	test_i18ncmp expected actual
+'
+
 test_expect_success 'status showing detached at and from a tag' '
 	test_commit atag tagging &&
 	git checkout atag &&
diff --git a/wt-status.c b/wt-status.c
index 1f564b12d2..355e4cd03d 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -17,6 +17,7 @@
 #include "utf8.h"
 #include "worktree.h"
 #include "lockfile.h"
+#include "sequencer.h"
 
 static const char cut_line[] =
 "------------------------ >8 ------------------------\n";
@@ -1563,6 +1564,7 @@ void wt_status_get_state(struct repository *r,
 {
 	struct stat st;
 	struct object_id oid;
+	enum replay_action action;
 
 	if (!stat(git_path_merge_head(r), &st)) {
 		wt_status_check_rebase(NULL, state);
@@ -1580,7 +1582,15 @@ void wt_status_get_state(struct repository *r,
 		state->revert_in_progress = 1;
 		oidcpy(&state->revert_head_oid, &oid);
 	}
-
+	if (!sequencer_get_last_command(r, &action, &oid)) {
+		if (action == REPLAY_PICK) {
+			state->cherry_pick_in_progress = 1;
+			oidcpy(&state->cherry_pick_head_oid, &oid);
+		} else {
+			state->revert_in_progress = 1;
+			oidcpy(&state->revert_head_oid, &oid);
+		}
+	}
 	if (get_detached_from)
 		wt_status_get_detached_from(r, state);
 }
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/2] commit/reset: try to clean up sequencer state
  2019-03-29 16:30 ` [PATCH 1/2] commit/reset: try to clean up sequencer state Phillip Wood
@ 2019-04-01  8:28   ` Junio C Hamano
  2019-04-08 14:15     ` Phillip Wood
  2019-04-01 10:09   ` Duy Nguyen
  1 sibling, 1 reply; 15+ messages in thread
From: Junio C Hamano @ 2019-04-01  8:28 UTC (permalink / raw)
  To: Phillip Wood
  Cc: Git Mailing List, Johannes Schindelin, Elijah Newren, Duy Nguyen,
	Phillip Wood

Phillip Wood <phillip.wood123@gmail.com> writes:

> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> When cherry-picking or reverting a sequence of commits and if the final
> pick/revert has conflicts and the user uses `git commit` to commit the
> conflict resolution and does not run `git cherry-pick --continue` then
> the sequencer state is left behind. This can cause problems later. In my
> case I cherry-picked a sequence of commits the last one of which I
> committed with `git commit` after resolving some conflicts, then a while
> later, on a different branch I aborted a revert which rewound my HEAD to
> the end of the cherry-pick sequence on the previous branch.

I've certainly seen this myself.  Do you use command line prompt
support to remind you of the operation in progress?  I do, and I
have a suspicion that it did not help me in this situation by
ceasing to tell me that I have leftover state files after a manual
commit of the final step that conflicted and gave control back to
me.

And detecting that we are finishing the last step and making sure
that the state files are removed does sound like the right approach
to fix it.

> diff --git a/branch.c b/branch.c
> index 28b81a7e02..9ed60081c1 100644
> --- a/branch.c
> +++ b/branch.c
> @@ -5,6 +5,7 @@
>  #include "refs.h"
>  #include "refspec.h"
>  #include "remote.h"
> +#include "sequencer.h"
>  #include "commit.h"
>  #include "worktree.h"
>  
> @@ -339,8 +340,10 @@ void create_branch(struct repository *r,
>  
>  void remove_branch_state(struct repository *r)
>  {
> -	unlink(git_path_cherry_pick_head(r));
> -	unlink(git_path_revert_head(r));
> +	if (!unlink(git_path_cherry_pick_head(r)))
> +		sequencer_post_commit_cleanup();
> +	if (!unlink(git_path_revert_head(r)))
> +		sequencer_post_commit_cleanup();

This and the same one in builtin/commit.c feels a bit iffy.  If we
had CHERRY_PICK_HEAD or REVERT_HEAD and attempted to remove one or
the other, whether the removal succeeds or fails (perhaps a virus
scanner on Windows had the file open while we tried to unlink it,
causing the unlink() to fail), don't we want the clean-up to happen?

> @@ -1678,6 +1680,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>  	if (amend && !no_post_rewrite) {
>  		commit_post_rewrite(the_repository, current_head, &oid);
>  	}
> +

This is an unrelated change.

>  	if (!quiet) {
>  		unsigned int flags = 0;
>  
> diff --git a/sequencer.c b/sequencer.c
> index 0db410d590..028699209f 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -2220,6 +2220,29 @@ static ssize_t strbuf_read_file_or_whine(struct strbuf *sb, const char *path)
>  	return len;
>  }
>  
> +void sequencer_post_commit_cleanup(void)
> +{
> +	struct replay_opts opts = REPLAY_OPTS_INIT;
> +	struct strbuf buf = STRBUF_INIT;
> +	const char *eol;
> +	const char *todo_path = git_path_todo_file();
> +
> +	if (strbuf_read_file(&buf, todo_path, 0) < 0) {
> +		if (errno == ENOENT) {
> +			return;
> +		} else {
> +			error_errno("unable to open '%s'", todo_path);
> +			return;
> +		}
> +	}
> +	/* If there is only one line then we are done */
> +	eol = strchr(buf.buf, '\n');
> +	if (!eol || !eol[1])
> +		sequencer_remove_state(&opts);
> +
> +	strbuf_release(&buf);
> +}

I find this helper doing a bit too much and a bit too little at the
same time.  To reduce the iffiness I mentioned earlier, the callers
would behefit to have a helper that

 - notices the need to remove CHERRY_PICK_HEAD or REVERT_HEAD, and
   returns without doing anything if there is no need;

 - remove the *_HEAD file.

 - detect if we have dealt with the last step, and returns without
   doing any more thing if there are more to do;

 - remove the state files.

IOW, replace the existing series of two unlink() calls with a single
call to the helper.

On the other hand, the bulk of hand-rolled logic to determine if we
have processed the last step is better done in another helper
function that helps this helper, i.e.

	void sequencer_post_commit_cleanup(struct repo *r)
	{
		int need_cleanup = 0;

		if (file_exists(git_path_cherry_pick_head(r)) {
			unlink(git_path_cherry_pick_head(r));
			need_cleanup = 1;
		}
		if (file_exists(git_path_revert_head(r)) {
			unlink(git_path_revert_head(r));
			need_cleanup = 1;
		}
		if (!need_cleanup)
			return;
		if (!have_finished_the_last_pick())
			return;
		sequencer_remove_state(&opts);
	}

as that makes it easier to follow the logic of what is going on at
this level, while at the same time making the logic in the
have_finished_the_last_pick() helper easier to read by giving it a
meaningful name.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 2/2] fix cherry-pick/revert status after commit
  2019-03-29 16:30 ` [PATCH 2/2] fix cherry-pick/revert status after commit Phillip Wood
@ 2019-04-01  8:34   ` Junio C Hamano
  2019-04-08 14:17     ` Phillip Wood
  0 siblings, 1 reply; 15+ messages in thread
From: Junio C Hamano @ 2019-04-01  8:34 UTC (permalink / raw)
  To: Phillip Wood
  Cc: Git Mailing List, Johannes Schindelin, Elijah Newren, Duy Nguyen,
	Phillip Wood

Phillip Wood <phillip.wood123@gmail.com> writes:

> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> If the user commits a conflict resolution using 'git commit' during a
> sequence of picks then 'git status' missed the fact that a
> cherry-pick/revert is still in progress.

How well would this play with the previous step?  Didn't the change
to builtin/commit.c made in [1/2] mean that after 'git commit' that
concludes the last step, there is nothing 'git status' to notice?



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/2] commit/reset: try to clean up sequencer state
  2019-03-29 16:30 ` [PATCH 1/2] commit/reset: try to clean up sequencer state Phillip Wood
  2019-04-01  8:28   ` Junio C Hamano
@ 2019-04-01 10:09   ` Duy Nguyen
  2019-04-08 15:47     ` Phillip Wood
  1 sibling, 1 reply; 15+ messages in thread
From: Duy Nguyen @ 2019-04-01 10:09 UTC (permalink / raw)
  To: Phillip Wood
  Cc: Git Mailing List, Johannes Schindelin, Junio C Hamano,
	Elijah Newren

On Fri, Mar 29, 2019 at 11:32 PM Phillip Wood <phillip.wood123@gmail.com> wrote:
>
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> When cherry-picking or reverting a sequence of commits and if the final
> pick/revert has conflicts and the user uses `git commit` to commit the
> conflict resolution and does not run `git cherry-pick --continue` then
> the sequencer state is left behind. This can cause problems later. In my
> case I cherry-picked a sequence of commits the last one of which I
> committed with `git commit` after resolving some conflicts, then a while
> later, on a different branch I aborted a revert which rewound my HEAD to
> the end of the cherry-pick sequence on the previous branch. Avoid this
> potential problem by removing the sequencer state if we're committing or
> resetting the final pick in a sequence.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  branch.c                        |  7 +++++--
>  builtin/commit.c                |  7 +++++--
>  sequencer.c                     | 23 +++++++++++++++++++++++
>  sequencer.h                     |  1 +
>  t/t3507-cherry-pick-conflict.sh | 19 +++++++++++++++++++
>  5 files changed, 53 insertions(+), 4 deletions(-)
>
> diff --git a/branch.c b/branch.c
> index 28b81a7e02..9ed60081c1 100644
> --- a/branch.c
> +++ b/branch.c
> @@ -5,6 +5,7 @@
>  #include "refs.h"
>  #include "refspec.h"
>  #include "remote.h"
> +#include "sequencer.h"
>  #include "commit.h"
>  #include "worktree.h"
>
> @@ -339,8 +340,10 @@ void create_branch(struct repository *r,
>
>  void remove_branch_state(struct repository *r)

This function is also called in git-am, git-rebase and git-checkout.
While the first two should not be affected, git-checkout can be
executed while we're in the middle of a cherry-pick or revert. I guess
that's ok because git-checkout is basically the same as git-reset in
this case?

>  {
> -       unlink(git_path_cherry_pick_head(r));
> -       unlink(git_path_revert_head(r));
> +       if (!unlink(git_path_cherry_pick_head(r)))
> +               sequencer_post_commit_cleanup();
> +       if (!unlink(git_path_revert_head(r)))
> +               sequencer_post_commit_cleanup();
>         unlink(git_path_merge_head(r));
>         unlink(git_path_merge_rr(r));
>         unlink(git_path_merge_msg(r));
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 2986553d5f..422b7d62a5 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1657,8 +1657,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>                 die("%s", err.buf);
>         }
>
> -       unlink(git_path_cherry_pick_head(the_repository));
> -       unlink(git_path_revert_head(the_repository));
> +       if (!unlink(git_path_cherry_pick_head(the_repository)))
> +               sequencer_post_commit_cleanup();
> +       if (!unlink(git_path_revert_head(the_repository)))
> +               sequencer_post_commit_cleanup();
>         unlink(git_path_merge_head(the_repository));
>         unlink(git_path_merge_msg(the_repository));
>         unlink(git_path_merge_mode(the_repository));
> @@ -1678,6 +1680,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>         if (amend && !no_post_rewrite) {
>                 commit_post_rewrite(the_repository, current_head, &oid);
>         }
> +
>         if (!quiet) {
>                 unsigned int flags = 0;
>
> diff --git a/sequencer.c b/sequencer.c
> index 0db410d590..028699209f 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -2220,6 +2220,29 @@ static ssize_t strbuf_read_file_or_whine(struct strbuf *sb, const char *path)
>         return len;
>  }
>
> +void sequencer_post_commit_cleanup(void)
> +{
> +       struct replay_opts opts = REPLAY_OPTS_INIT;
> +       struct strbuf buf = STRBUF_INIT;
> +       const char *eol;
> +       const char *todo_path = git_path_todo_file();
> +
> +       if (strbuf_read_file(&buf, todo_path, 0) < 0) {
> +               if (errno == ENOENT) {
> +                       return;
> +               } else {
> +                       error_errno("unable to open '%s'", todo_path);

_() the string to make it translatable.

> +                       return;
> +               }
> +       }
> +       /* If there is only one line then we are done */
> +       eol = strchr(buf.buf, '\n');
> +       if (!eol || !eol[1])
> +               sequencer_remove_state(&opts);

Should we say something to let the user know cherry-pick/revert is
finished? (unless --quiet is specified)

> +
> +       strbuf_release(&buf);
> +}
> +
>  static int read_populate_todo(struct repository *r,
>                               struct todo_list *todo_list,
>                               struct replay_opts *opts)
-- 
Duy

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/2] commit/reset: try to clean up sequencer state
  2019-04-01  8:28   ` Junio C Hamano
@ 2019-04-08 14:15     ` Phillip Wood
  0 siblings, 0 replies; 15+ messages in thread
From: Phillip Wood @ 2019-04-08 14:15 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git Mailing List, Johannes Schindelin, Elijah Newren, Duy Nguyen,
	Phillip Wood

Hi Junio

On 01/04/2019 09:28, Junio C Hamano wrote:
> Phillip Wood <phillip.wood123@gmail.com> writes:
> 
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> When cherry-picking or reverting a sequence of commits and if the final
>> pick/revert has conflicts and the user uses `git commit` to commit the
>> conflict resolution and does not run `git cherry-pick --continue` then
>> the sequencer state is left behind. This can cause problems later. In my
>> case I cherry-picked a sequence of commits the last one of which I
>> committed with `git commit` after resolving some conflicts, then a while
>> later, on a different branch I aborted a revert which rewound my HEAD to
>> the end of the cherry-pick sequence on the previous branch.
> 
> I've certainly seen this myself.  Do you use command line prompt
> support to remind you of the operation in progress?  I do, and I
> have a suspicion that it did not help me in this situation by
> ceasing to tell me that I have leftover state files after a manual
> commit of the final step that conflicted and gave control back to
> me.

Same here, the prompt I use just checks for the presence of 
CHERRY_PICK_HEAD which disappears after committing.

> And detecting that we are finishing the last step and making sure
> that the state files are removed does sound like the right approach
> to fix it.
> 
>> diff --git a/branch.c b/branch.c
>> index 28b81a7e02..9ed60081c1 100644
>> --- a/branch.c
>> +++ b/branch.c
>> @@ -5,6 +5,7 @@
>>   #include "refs.h"
>>   #include "refspec.h"
>>   #include "remote.h"
>> +#include "sequencer.h"
>>   #include "commit.h"
>>   #include "worktree.h"
>>   
>> @@ -339,8 +340,10 @@ void create_branch(struct repository *r,
>>   
>>   void remove_branch_state(struct repository *r)
>>   {
>> -	unlink(git_path_cherry_pick_head(r));
>> -	unlink(git_path_revert_head(r));
>> +	if (!unlink(git_path_cherry_pick_head(r)))
>> +		sequencer_post_commit_cleanup();
>> +	if (!unlink(git_path_revert_head(r)))
>> +		sequencer_post_commit_cleanup();
> 
> This and the same one in builtin/commit.c feels a bit iffy.  If we
> had CHERRY_PICK_HEAD or REVERT_HEAD and attempted to remove one or
> the other, whether the removal succeeds or fails (perhaps a virus
> scanner on Windows had the file open while we tried to unlink it,
> causing the unlink() to fail), don't we want the clean-up to happen?

Good point, I could add '|| errno == ENOENT' to the if or just use 
file_exists() as you suggest below

>> @@ -1678,6 +1680,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>>   	if (amend && !no_post_rewrite) {
>>   		commit_post_rewrite(the_repository, current_head, &oid);
>>   	}
>> +
> 
> This is an unrelated change.

Oops I'm not sure where that came from

>>   	if (!quiet) {
>>   		unsigned int flags = 0;
>>   
>> diff --git a/sequencer.c b/sequencer.c
>> index 0db410d590..028699209f 100644
>> --- a/sequencer.c
>> +++ b/sequencer.c
>> @@ -2220,6 +2220,29 @@ static ssize_t strbuf_read_file_or_whine(struct strbuf *sb, const char *path)
>>   	return len;
>>   }
>>   
>> +void sequencer_post_commit_cleanup(void)
>> +{
>> +	struct replay_opts opts = REPLAY_OPTS_INIT;
>> +	struct strbuf buf = STRBUF_INIT;
>> +	const char *eol;
>> +	const char *todo_path = git_path_todo_file();
>> +
>> +	if (strbuf_read_file(&buf, todo_path, 0) < 0) {
>> +		if (errno == ENOENT) {
>> +			return;
>> +		} else {
>> +			error_errno("unable to open '%s'", todo_path);
>> +			return;
>> +		}
>> +	}
>> +	/* If there is only one line then we are done */
>> +	eol = strchr(buf.buf, '\n');
>> +	if (!eol || !eol[1])
>> +		sequencer_remove_state(&opts);
>> +
>> +	strbuf_release(&buf);
>> +}
> 
> I find this helper doing a bit too much and a bit too little at the
> same time.  To reduce the iffiness I mentioned earlier, the callers
> would behefit to have a helper that
> 
>   - notices the need to remove CHERRY_PICK_HEAD or REVERT_HEAD, and
>     returns without doing anything if there is no need;
> 
>   - remove the *_HEAD file.
> 
>   - detect if we have dealt with the last step, and returns without
>     doing any more thing if there are more to do;
> 
>   - remove the state files.
> 
> IOW, replace the existing series of two unlink() calls with a single
> call to the helper.
> 
> On the other hand, the bulk of hand-rolled logic to determine if we
> have processed the last step is better done in another helper
> function that helps this helper, i.e.
> 
> 	void sequencer_post_commit_cleanup(struct repo *r)
> 	{
> 		int need_cleanup = 0;
> 
> 		if (file_exists(git_path_cherry_pick_head(r)) {
> 			unlink(git_path_cherry_pick_head(r));
> 			need_cleanup = 1;
> 		}
> 		if (file_exists(git_path_revert_head(r)) {
> 			unlink(git_path_revert_head(r));
> 			need_cleanup = 1;
> 		}
> 		if (!need_cleanup)
> 			return;
> 		if (!have_finished_the_last_pick())
> 			return;
> 		sequencer_remove_state(&opts);
> 	}
> 
> as that makes it easier to follow the logic of what is going on at
> this level, while at the same time making the logic in the
> have_finished_the_last_pick() helper easier to read by giving it a
> meaningful name.

Thanks that definitely improves things, I'll send a re-roll

Best Wishes

Phillip

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 2/2] fix cherry-pick/revert status after commit
  2019-04-01  8:34   ` Junio C Hamano
@ 2019-04-08 14:17     ` Phillip Wood
  0 siblings, 0 replies; 15+ messages in thread
From: Phillip Wood @ 2019-04-08 14:17 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Git Mailing List, Johannes Schindelin, Elijah Newren, Duy Nguyen,
	Phillip Wood

On 01/04/2019 09:34, Junio C Hamano wrote:
> Phillip Wood <phillip.wood123@gmail.com> writes:
> 
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> If the user commits a conflict resolution using 'git commit' during a
>> sequence of picks then 'git status' missed the fact that a
>> cherry-pick/revert is still in progress.
> 
> How well would this play with the previous step?  Didn't the change
> to builtin/commit.c made in [1/2] mean that after 'git commit' that
> concludes the last step, there is nothing 'git status' to notice?

You're right about the final pick in a sequence but the idea here is 
that if the user runs 'git commit' in the middle of a sequence of 
cherry-picks then we want 'git status' to report that a cherry-pick is 
in progress.

Best Wishes

Phillip

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH 1/2] commit/reset: try to clean up sequencer state
  2019-04-01 10:09   ` Duy Nguyen
@ 2019-04-08 15:47     ` Phillip Wood
  0 siblings, 0 replies; 15+ messages in thread
From: Phillip Wood @ 2019-04-08 15:47 UTC (permalink / raw)
  To: Duy Nguyen, Phillip Wood
  Cc: Git Mailing List, Johannes Schindelin, Junio C Hamano,
	Elijah Newren

On 01/04/2019 11:09, Duy Nguyen wrote:
> On Fri, Mar 29, 2019 at 11:32 PM Phillip Wood <phillip.wood123@gmail.com> wrote:
>>
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> When cherry-picking or reverting a sequence of commits and if the final
>> pick/revert has conflicts and the user uses `git commit` to commit the
>> conflict resolution and does not run `git cherry-pick --continue` then
>> the sequencer state is left behind. This can cause problems later. In my
>> case I cherry-picked a sequence of commits the last one of which I
>> committed with `git commit` after resolving some conflicts, then a while
>> later, on a different branch I aborted a revert which rewound my HEAD to
>> the end of the cherry-pick sequence on the previous branch. Avoid this
>> potential problem by removing the sequencer state if we're committing or
>> resetting the final pick in a sequence.
>>
>> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
>> ---
>>   branch.c                        |  7 +++++--
>>   builtin/commit.c                |  7 +++++--
>>   sequencer.c                     | 23 +++++++++++++++++++++++
>>   sequencer.h                     |  1 +
>>   t/t3507-cherry-pick-conflict.sh | 19 +++++++++++++++++++
>>   5 files changed, 53 insertions(+), 4 deletions(-)
>>
>> diff --git a/branch.c b/branch.c
>> index 28b81a7e02..9ed60081c1 100644
>> --- a/branch.c
>> +++ b/branch.c
>> @@ -5,6 +5,7 @@
>>   #include "refs.h"
>>   #include "refspec.h"
>>   #include "remote.h"
>> +#include "sequencer.h"
>>   #include "commit.h"
>>   #include "worktree.h"
>>
>> @@ -339,8 +340,10 @@ void create_branch(struct repository *r,
>>
>>   void remove_branch_state(struct repository *r)
> 
> This function is also called in git-am, git-rebase and git-checkout.
> While the first two should not be affected, git-checkout can be
> executed while we're in the middle of a cherry-pick or revert. I guess
> that's ok because git-checkout is basically the same as git-reset in
> this case?

Yes that's right

>>   {
>> -       unlink(git_path_cherry_pick_head(r));
>> -       unlink(git_path_revert_head(r));
>> +       if (!unlink(git_path_cherry_pick_head(r)))
>> +               sequencer_post_commit_cleanup();
>> +       if (!unlink(git_path_revert_head(r)))
>> +               sequencer_post_commit_cleanup();
>>          unlink(git_path_merge_head(r));
>>          unlink(git_path_merge_rr(r));
>>          unlink(git_path_merge_msg(r));
>> diff --git a/builtin/commit.c b/builtin/commit.c
>> index 2986553d5f..422b7d62a5 100644
>> --- a/builtin/commit.c
>> +++ b/builtin/commit.c
>> @@ -1657,8 +1657,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>>                  die("%s", err.buf);
>>          }
>>
>> -       unlink(git_path_cherry_pick_head(the_repository));
>> -       unlink(git_path_revert_head(the_repository));
>> +       if (!unlink(git_path_cherry_pick_head(the_repository)))
>> +               sequencer_post_commit_cleanup();
>> +       if (!unlink(git_path_revert_head(the_repository)))
>> +               sequencer_post_commit_cleanup();
>>          unlink(git_path_merge_head(the_repository));
>>          unlink(git_path_merge_msg(the_repository));
>>          unlink(git_path_merge_mode(the_repository));
>> @@ -1678,6 +1680,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
>>          if (amend && !no_post_rewrite) {
>>                  commit_post_rewrite(the_repository, current_head, &oid);
>>          }
>> +
>>          if (!quiet) {
>>                  unsigned int flags = 0;
>>
>> diff --git a/sequencer.c b/sequencer.c
>> index 0db410d590..028699209f 100644
>> --- a/sequencer.c
>> +++ b/sequencer.c
>> @@ -2220,6 +2220,29 @@ static ssize_t strbuf_read_file_or_whine(struct strbuf *sb, const char *path)
>>          return len;
>>   }
>>
>> +void sequencer_post_commit_cleanup(void)
>> +{
>> +       struct replay_opts opts = REPLAY_OPTS_INIT;
>> +       struct strbuf buf = STRBUF_INIT;
>> +       const char *eol;
>> +       const char *todo_path = git_path_todo_file();
>> +
>> +       if (strbuf_read_file(&buf, todo_path, 0) < 0) {
>> +               if (errno == ENOENT) {
>> +                       return;
>> +               } else {
>> +                       error_errno("unable to open '%s'", todo_path);
> 
> _() the string to make it translatable.

Well spotted, thanks

>> +                       return;
>> +               }
>> +       }
>> +       /* If there is only one line then we are done */
>> +       eol = strchr(buf.buf, '\n');
>> +       if (!eol || !eol[1])
>> +               sequencer_remove_state(&opts);
> 
> Should we say something to let the user know cherry-pick/revert is
> finished? (unless --quiet is specified)

I'd not thought of that, at the moment we don't say anything about 
removing CHERRY_PICK_HEAD etc when they are removed by reset or 
checkout, I'm not sure this is much different to those cases - but maybe 
they should be printing some feedback as well.

Best Wishes

Phillip

>> +
>> +       strbuf_release(&buf);
>> +}
>> +
>>   static int read_populate_todo(struct repository *r,
>>                                struct todo_list *todo_list,
>>                                struct replay_opts *opts)

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v2 0/2] A couple of cherry-pick related fixes
  2019-03-29 16:30 [PATCH 0/2] A couple of cherry-pick related fixes Phillip Wood
  2019-03-29 16:30 ` [PATCH 1/2] commit/reset: try to clean up sequencer state Phillip Wood
  2019-03-29 16:30 ` [PATCH 2/2] fix cherry-pick/revert status after commit Phillip Wood
@ 2019-04-16 10:18 ` Phillip Wood
  2019-04-16 10:18   ` [PATCH v2 1/2] commit/reset: try to clean up sequencer state Phillip Wood
  2019-04-16 10:18   ` [PATCH v2 2/2] fix cherry-pick/revert status after commit Phillip Wood
  2 siblings, 2 replies; 15+ messages in thread
From: Phillip Wood @ 2019-04-16 10:18 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Johannes Schindelin, Elijah Newren, Duy Nguyen, Junio C Hamano,
	Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

I've updated the first patch as per Junio's suggestions and added
tests for revert as well as cherry-pick. I've also changed the second
patch to avoid printing the oid of the origin of the commit that's
just been created and added tests for revert as well as
cherry-pick. In the end I didn't add any messages when we remove
.git/sequencer as we don't say anything when we remove
CHERRY_PICK_HEAD at the moment. Duy mentioned this, I could add this
if there is a strong demand for it.

Phillip Wood (2):
  commit/reset: try to clean up sequencer state
  fix cherry-pick/revert status after commit

 branch.c                        |  4 +-
 builtin/commit.c                |  3 +-
 sequencer.c                     | 86 +++++++++++++++++++++++++++++++++
 sequencer.h                     |  3 ++
 t/t3507-cherry-pick-conflict.sh | 39 +++++++++++++++
 t/t7512-status-help.sh          | 36 ++++++++++++++
 wt-status.c                     | 39 +++++++++++++--
 7 files changed, 201 insertions(+), 9 deletions(-)

Range-diff against v1:
1:  9b310618ed ! 1:  e963e02628 commit/reset: try to clean up sequencer state
    @@ -32,10 +32,7 @@
      {
     -	unlink(git_path_cherry_pick_head(r));
     -	unlink(git_path_revert_head(r));
    -+	if (!unlink(git_path_cherry_pick_head(r)))
    -+		sequencer_post_commit_cleanup();
    -+	if (!unlink(git_path_revert_head(r)))
    -+		sequencer_post_commit_cleanup();
    ++	sequencer_post_commit_cleanup(r);
      	unlink(git_path_merge_head(r));
      	unlink(git_path_merge_rr(r));
      	unlink(git_path_merge_msg(r));
    @@ -49,21 +46,10 @@
      
     -	unlink(git_path_cherry_pick_head(the_repository));
     -	unlink(git_path_revert_head(the_repository));
    -+	if (!unlink(git_path_cherry_pick_head(the_repository)))
    -+		sequencer_post_commit_cleanup();
    -+	if (!unlink(git_path_revert_head(the_repository)))
    -+		sequencer_post_commit_cleanup();
    ++	sequencer_post_commit_cleanup(the_repository);
      	unlink(git_path_merge_head(the_repository));
      	unlink(git_path_merge_msg(the_repository));
      	unlink(git_path_merge_mode(the_repository));
    -@@
    - 	if (amend && !no_post_rewrite) {
    - 		commit_post_rewrite(the_repository, current_head, &oid);
    - 	}
    -+
    - 	if (!quiet) {
    - 		unsigned int flags = 0;
    - 
     
      diff --git a/sequencer.c b/sequencer.c
      --- a/sequencer.c
    @@ -72,27 +58,55 @@
      	return len;
      }
      
    -+void sequencer_post_commit_cleanup(void)
    ++static int have_finished_the_last_pick(void)
     +{
    -+	struct replay_opts opts = REPLAY_OPTS_INIT;
     +	struct strbuf buf = STRBUF_INIT;
     +	const char *eol;
     +	const char *todo_path = git_path_todo_file();
    ++	int ret = 0;
     +
     +	if (strbuf_read_file(&buf, todo_path, 0) < 0) {
     +		if (errno == ENOENT) {
    -+			return;
    ++			return 0;
     +		} else {
     +			error_errno("unable to open '%s'", todo_path);
    -+			return;
    ++			return 0;
     +		}
     +	}
     +	/* If there is only one line then we are done */
     +	eol = strchr(buf.buf, '\n');
     +	if (!eol || !eol[1])
    -+		sequencer_remove_state(&opts);
    ++		ret = 1;
     +
     +	strbuf_release(&buf);
    ++
    ++	return ret;
    ++}
    ++
    ++void sequencer_post_commit_cleanup(struct repository *r)
    ++{
    ++	struct replay_opts opts = REPLAY_OPTS_INIT;
    ++	int need_cleanup = 0;
    ++
    ++	if (file_exists(git_path_cherry_pick_head(r))) {
    ++		unlink(git_path_cherry_pick_head(r));
    ++		opts.action = REPLAY_PICK;
    ++		need_cleanup = 1;
    ++	}
    ++
    ++	if (file_exists(git_path_revert_head(r))) {
    ++		unlink(git_path_revert_head(r));
    ++		opts.action = REPLAY_REVERT;
    ++		need_cleanup = 1;
    ++	}
    ++
    ++	if (!need_cleanup)
    ++		return;
    ++
    ++	if (!have_finished_the_last_pick())
    ++		return;
    ++
    ++	sequencer_remove_state(&opts);
     +}
     +
      static int read_populate_todo(struct repository *r,
    @@ -106,7 +120,7 @@
      void parse_strategy_opts(struct replay_opts *opts, char *raw_opts);
      int write_basic_state(struct replay_opts *opts, const char *head_name,
      		      const char *onto, const char *orig_head);
    -+void sequencer_post_commit_cleanup(void);
    ++void sequencer_post_commit_cleanup(struct repository *r);
     
      diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh
      --- a/t/t3507-cherry-pick-conflict.sh
    @@ -115,7 +129,7 @@
      
      	test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
      '
    -+test_expect_success 'successful final commit clears sequencer state' '
    ++test_expect_success 'successful final commit clears cherry-pick state' '
     +	pristine_detach initial &&
     +
     +	test_must_fail git cherry-pick base picked-signed &&
    @@ -125,7 +139,7 @@
     +	test_must_fail test_path_exists .git/sequencer
     +'
     +
    -+test_expect_success 'reset after final pick clears sequencer state' '
    ++test_expect_success 'reset after final pick clears cherry-pick state' '
     +	pristine_detach initial &&
     +
     +	test_must_fail git cherry-pick base picked-signed &&
    @@ -137,3 +151,30 @@
      
      test_expect_success 'failed cherry-pick produces dirty index' '
      	pristine_detach initial &&
    +@@
    + 	test_cmp_rev picked REVERT_HEAD
    + '
    + 
    ++test_expect_success 'successful final commit clears revert state' '
    ++       pristine_detach picked-signed &&
    ++
    ++       test_must_fail git revert picked-signed base &&
    ++       echo resolved >foo &&
    ++       test_path_is_file .git/sequencer/todo &&
    ++       git commit -a &&
    ++       test_must_fail test_path_exists .git/sequencer
    ++'
    ++
    ++test_expect_success 'reset after final pick clears revert state' '
    ++       pristine_detach picked-signed &&
    ++
    ++       test_must_fail git revert picked-signed base &&
    ++       echo resolved >foo &&
    ++       test_path_is_file .git/sequencer/todo &&
    ++       git reset &&
    ++       test_must_fail test_path_exists .git/sequencer
    ++'
    ++
    + test_expect_success 'revert conflict, diff3 -m style' '
    + 	pristine_detach initial &&
    + 	git config merge.conflictstyle diff3 &&
2:  edb1bfb3d6 ! 2:  ee7db0cfe0 fix cherry-pick/revert status after commit
    @@ -2,9 +2,9 @@
     
         fix cherry-pick/revert status after commit
     
    -    If the user commits a conflict resolution using 'git commit' during a
    -    sequence of picks then 'git status' missed the fact that a
    -    cherry-pick/revert is still in progress.
    +    If the user commits a conflict resolution using `git commit` in the
    +    middle of a sequence of cherry-picks/reverts then `git status` missed
    +    the fact that a cherry-pick/revert is still in progress.
     
         Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
     
    @@ -15,8 +15,7 @@
      	return !item->commit;
      }
      
    -+int sequencer_get_last_command(struct repository *r, enum replay_action *action,
    -+			       struct object_id *oid)
    ++int sequencer_get_last_command(struct repository *r, enum replay_action *action)
     +{
     +	struct todo_item item;
     +	char *eol;
    @@ -43,7 +42,6 @@
     +	else
     +		goto fail;
     +
    -+	oidcpy(oid, &item.commit->object.oid);
     +	ret = 0;
     +
     + fail:
    @@ -62,9 +60,9 @@
     @@
      int write_basic_state(struct replay_opts *opts, const char *head_name,
      		      const char *onto, const char *orig_head);
    - void sequencer_post_commit_cleanup(void);
    -+int sequencer_get_last_command(struct repository* r, enum replay_action *action,
    -+			       struct object_id *oid);
    + void sequencer_post_commit_cleanup(struct repository *r);
    ++int sequencer_get_last_command(struct repository* r,
    ++			       enum replay_action *action);
     
      diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
      --- a/t/t7512-status-help.sh
    @@ -77,13 +75,12 @@
     +	git reset --hard cherry_branch &&
     +	test_when_finished "git cherry-pick --abort" &&
     +	test_must_fail git cherry-pick cherry_branch_second one_cherry &&
    -+	TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) &&
     +	echo end >main.txt &&
     +	git commit -a &&
     +	cat >expected <<EOF &&
     +On branch cherry_branch
    -+You are currently cherry-picking commit $TO_CHERRY_PICK.
    -+  (all conflicts fixed: run "git cherry-pick --continue")
    ++Cherry-pick currently in progress.
    ++  (run "git cherry-pick --continue" to continue)
     +  (use "git cherry-pick --abort" to cancel the cherry-pick operation)
     +
     +nothing to commit (use -u to show untracked files)
    @@ -95,6 +92,31 @@
      test_expect_success 'status showing detached at and from a tag' '
      	test_commit atag tagging &&
      	git checkout atag &&
    +@@
    + 	test_i18ncmp expected actual
    + '
    + 
    ++test_expect_success 'status while reverting after committing conflict resolution' '
    ++	test_when_finished "git revert --abort" &&
    ++	git reset --hard new &&
    ++	test_must_fail git revert old new &&
    ++	echo reverted >to-revert.txt &&
    ++	git commit -a &&
    ++	cat >expected <<EOF &&
    ++On branch master
    ++Revert currently in progress.
    ++  (run "git revert --continue" to continue)
    ++  (use "git revert --abort" to cancel the revert operation)
    ++
    ++nothing to commit (use -u to show untracked files)
    ++EOF
    ++	git status --untracked-files=no >actual &&
    ++	test_i18ncmp expected actual
    ++'
    ++
    + test_expect_success 'prepare for different number of commits rebased' '
    + 	git reset --hard master &&
    + 	git checkout -b several_commits &&
     
      diff --git a/wt-status.c b/wt-status.c
      --- a/wt-status.c
    @@ -107,6 +129,55 @@
      
      static const char cut_line[] =
      "------------------------ >8 ------------------------\n";
    +@@
    + static void show_cherry_pick_in_progress(struct wt_status *s,
    + 					 const char *color)
    + {
    +-	status_printf_ln(s, color, _("You are currently cherry-picking commit %s."),
    +-			find_unique_abbrev(&s->state.cherry_pick_head_oid, DEFAULT_ABBREV));
    ++	if (is_null_oid(&s->state.cherry_pick_head_oid))
    ++		status_printf_ln(s, color,
    ++			_("Cherry-pick currently in progress."));
    ++	else
    ++		status_printf_ln(s, color,
    ++			_("You are currently cherry-picking commit %s."),
    ++			find_unique_abbrev(&s->state.cherry_pick_head_oid,
    ++					   DEFAULT_ABBREV));
    ++
    + 	if (s->hints) {
    + 		if (has_unmerged(s))
    + 			status_printf_ln(s, color,
    + 				_("  (fix conflicts and run \"git cherry-pick --continue\")"));
    ++		else if (is_null_oid(&s->state.cherry_pick_head_oid))
    ++			status_printf_ln(s, color,
    ++				_("  (run \"git cherry-pick --continue\" to continue)"));
    + 		else
    + 			status_printf_ln(s, color,
    + 				_("  (all conflicts fixed: run \"git cherry-pick --continue\")"));
    +@@
    + static void show_revert_in_progress(struct wt_status *s,
    + 				    const char *color)
    + {
    +-	status_printf_ln(s, color, _("You are currently reverting commit %s."),
    +-			 find_unique_abbrev(&s->state.revert_head_oid, DEFAULT_ABBREV));
    ++	if (is_null_oid(&s->state.revert_head_oid))
    ++		status_printf_ln(s, color,
    ++			_("Revert currently in progress."));
    ++	else
    ++		status_printf_ln(s, color,
    ++			_("You are currently reverting commit %s."),
    ++			find_unique_abbrev(&s->state.revert_head_oid,
    ++					   DEFAULT_ABBREV));
    + 	if (s->hints) {
    + 		if (has_unmerged(s))
    + 			status_printf_ln(s, color,
    + 				_("  (fix conflicts and run \"git revert --continue\")"));
    ++		else if (is_null_oid(&s->state.revert_head_oid))
    ++			status_printf_ln(s, color,
    ++				_("  (run \"git revert --continue\" to continue)"));
    + 		else
    + 			status_printf_ln(s, color,
    + 				_("  (all conflicts fixed: run \"git revert --continue\")"));
     @@
      {
      	struct stat st;
    @@ -120,13 +191,13 @@
      		oidcpy(&state->revert_head_oid, &oid);
      	}
     -
    -+	if (!sequencer_get_last_command(r, &action, &oid)) {
    ++	if (!sequencer_get_last_command(r, &action)) {
     +		if (action == REPLAY_PICK) {
     +			state->cherry_pick_in_progress = 1;
    -+			oidcpy(&state->cherry_pick_head_oid, &oid);
    ++			oidcpy(&state->cherry_pick_head_oid, &null_oid);
     +		} else {
     +			state->revert_in_progress = 1;
    -+			oidcpy(&state->revert_head_oid, &oid);
    ++			oidcpy(&state->revert_head_oid, &null_oid);
     +		}
     +	}
      	if (get_detached_from)
--
2.21.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v2 1/2] commit/reset: try to clean up sequencer state
  2019-04-16 10:18 ` [PATCH v2 0/2] A couple of cherry-pick related fixes Phillip Wood
@ 2019-04-16 10:18   ` Phillip Wood
  2019-04-17  7:04     ` Junio C Hamano
  2019-04-16 10:18   ` [PATCH v2 2/2] fix cherry-pick/revert status after commit Phillip Wood
  1 sibling, 1 reply; 15+ messages in thread
From: Phillip Wood @ 2019-04-16 10:18 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Johannes Schindelin, Elijah Newren, Duy Nguyen, Junio C Hamano,
	Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

When cherry-picking or reverting a sequence of commits and if the final
pick/revert has conflicts and the user uses `git commit` to commit the
conflict resolution and does not run `git cherry-pick --continue` then
the sequencer state is left behind. This can cause problems later. In my
case I cherry-picked a sequence of commits the last one of which I
committed with `git commit` after resolving some conflicts, then a while
later, on a different branch I aborted a revert which rewound my HEAD to
the end of the cherry-pick sequence on the previous branch. Avoid this
potential problem by removing the sequencer state if we're committing or
resetting the final pick in a sequence.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 branch.c                        |  4 +--
 builtin/commit.c                |  3 +-
 sequencer.c                     | 51 +++++++++++++++++++++++++++++++++
 sequencer.h                     |  1 +
 t/t3507-cherry-pick-conflict.sh | 39 +++++++++++++++++++++++++
 5 files changed, 94 insertions(+), 4 deletions(-)

diff --git a/branch.c b/branch.c
index 28b81a7e02..643694542a 100644
--- a/branch.c
+++ b/branch.c
@@ -5,6 +5,7 @@
 #include "refs.h"
 #include "refspec.h"
 #include "remote.h"
+#include "sequencer.h"
 #include "commit.h"
 #include "worktree.h"
 
@@ -339,8 +340,7 @@ void create_branch(struct repository *r,
 
 void remove_branch_state(struct repository *r)
 {
-	unlink(git_path_cherry_pick_head(r));
-	unlink(git_path_revert_head(r));
+	sequencer_post_commit_cleanup(r);
 	unlink(git_path_merge_head(r));
 	unlink(git_path_merge_rr(r));
 	unlink(git_path_merge_msg(r));
diff --git a/builtin/commit.c b/builtin/commit.c
index 2986553d5f..9df3414d80 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1657,8 +1657,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		die("%s", err.buf);
 	}
 
-	unlink(git_path_cherry_pick_head(the_repository));
-	unlink(git_path_revert_head(the_repository));
+	sequencer_post_commit_cleanup(the_repository);
 	unlink(git_path_merge_head(the_repository));
 	unlink(git_path_merge_msg(the_repository));
 	unlink(git_path_merge_mode(the_repository));
diff --git a/sequencer.c b/sequencer.c
index 0db410d590..7c7b8a07c4 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2220,6 +2220,57 @@ static ssize_t strbuf_read_file_or_whine(struct strbuf *sb, const char *path)
 	return len;
 }
 
+static int have_finished_the_last_pick(void)
+{
+	struct strbuf buf = STRBUF_INIT;
+	const char *eol;
+	const char *todo_path = git_path_todo_file();
+	int ret = 0;
+
+	if (strbuf_read_file(&buf, todo_path, 0) < 0) {
+		if (errno == ENOENT) {
+			return 0;
+		} else {
+			error_errno("unable to open '%s'", todo_path);
+			return 0;
+		}
+	}
+	/* If there is only one line then we are done */
+	eol = strchr(buf.buf, '\n');
+	if (!eol || !eol[1])
+		ret = 1;
+
+	strbuf_release(&buf);
+
+	return ret;
+}
+
+void sequencer_post_commit_cleanup(struct repository *r)
+{
+	struct replay_opts opts = REPLAY_OPTS_INIT;
+	int need_cleanup = 0;
+
+	if (file_exists(git_path_cherry_pick_head(r))) {
+		unlink(git_path_cherry_pick_head(r));
+		opts.action = REPLAY_PICK;
+		need_cleanup = 1;
+	}
+
+	if (file_exists(git_path_revert_head(r))) {
+		unlink(git_path_revert_head(r));
+		opts.action = REPLAY_REVERT;
+		need_cleanup = 1;
+	}
+
+	if (!need_cleanup)
+		return;
+
+	if (!have_finished_the_last_pick())
+		return;
+
+	sequencer_remove_state(&opts);
+}
+
 static int read_populate_todo(struct repository *r,
 			      struct todo_list *todo_list,
 			      struct replay_opts *opts)
diff --git a/sequencer.h b/sequencer.h
index 4d505b3590..6c7cf8d72f 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -144,3 +144,4 @@ int read_author_script(const char *path, char **name, char **email, char **date,
 void parse_strategy_opts(struct replay_opts *opts, char *raw_opts);
 int write_basic_state(struct replay_opts *opts, const char *head_name,
 		      const char *onto, const char *orig_head);
+void sequencer_post_commit_cleanup(struct repository *r);
diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh
index 0db166152a..cebf91dce2 100755
--- a/t/t3507-cherry-pick-conflict.sh
+++ b/t/t3507-cherry-pick-conflict.sh
@@ -156,6 +156,25 @@ test_expect_success 'successful commit clears CHERRY_PICK_HEAD' '
 
 	test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
 '
+test_expect_success 'successful final commit clears cherry-pick state' '
+	pristine_detach initial &&
+
+	test_must_fail git cherry-pick base picked-signed &&
+	echo resolved >foo &&
+	test_path_is_file .git/sequencer/todo &&
+	git commit -a &&
+	test_must_fail test_path_exists .git/sequencer
+'
+
+test_expect_success 'reset after final pick clears cherry-pick state' '
+	pristine_detach initial &&
+
+	test_must_fail git cherry-pick base picked-signed &&
+	echo resolved >foo &&
+	test_path_is_file .git/sequencer/todo &&
+	git reset &&
+	test_must_fail test_path_exists .git/sequencer
+'
 
 test_expect_success 'failed cherry-pick produces dirty index' '
 	pristine_detach initial &&
@@ -316,6 +335,26 @@ test_expect_success 'failed commit does not clear REVERT_HEAD' '
 	test_cmp_rev picked REVERT_HEAD
 '
 
+test_expect_success 'successful final commit clears revert state' '
+       pristine_detach picked-signed &&
+
+       test_must_fail git revert picked-signed base &&
+       echo resolved >foo &&
+       test_path_is_file .git/sequencer/todo &&
+       git commit -a &&
+       test_must_fail test_path_exists .git/sequencer
+'
+
+test_expect_success 'reset after final pick clears revert state' '
+       pristine_detach picked-signed &&
+
+       test_must_fail git revert picked-signed base &&
+       echo resolved >foo &&
+       test_path_is_file .git/sequencer/todo &&
+       git reset &&
+       test_must_fail test_path_exists .git/sequencer
+'
+
 test_expect_success 'revert conflict, diff3 -m style' '
 	pristine_detach initial &&
 	git config merge.conflictstyle diff3 &&
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v2 2/2] fix cherry-pick/revert status after commit
  2019-04-16 10:18 ` [PATCH v2 0/2] A couple of cherry-pick related fixes Phillip Wood
  2019-04-16 10:18   ` [PATCH v2 1/2] commit/reset: try to clean up sequencer state Phillip Wood
@ 2019-04-16 10:18   ` Phillip Wood
  1 sibling, 0 replies; 15+ messages in thread
From: Phillip Wood @ 2019-04-16 10:18 UTC (permalink / raw)
  To: Git Mailing List
  Cc: Johannes Schindelin, Elijah Newren, Duy Nguyen, Junio C Hamano,
	Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

If the user commits a conflict resolution using `git commit` in the
middle of a sequence of cherry-picks/reverts then `git status` missed
the fact that a cherry-pick/revert is still in progress.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 sequencer.c            | 35 +++++++++++++++++++++++++++++++++++
 sequencer.h            |  2 ++
 t/t7512-status-help.sh | 36 ++++++++++++++++++++++++++++++++++++
 wt-status.c            | 39 ++++++++++++++++++++++++++++++++++-----
 4 files changed, 107 insertions(+), 5 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index 7c7b8a07c4..c6a9a35422 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2142,6 +2142,41 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
 	return !item->commit;
 }
 
+int sequencer_get_last_command(struct repository *r, enum replay_action *action)
+{
+	struct todo_item item;
+	char *eol;
+	const char *todo_file;
+	struct strbuf buf = STRBUF_INIT;
+	int ret = -1;
+
+	todo_file = git_path_todo_file();
+	if (strbuf_read_file(&buf, todo_file, 0) < 0) {
+		if (errno == ENOENT)
+			return -1;
+		else
+			return error_errno("unable to open '%s'", todo_file);
+	}
+	eol = strchrnul(buf.buf, '\n');
+	if (buf.buf != eol && eol[-1] == '\r')
+		eol--; /* strip Carriage Return */
+	if (parse_insn_line(r, &item, buf.buf, eol))
+		goto fail;
+	if (item.command == TODO_PICK)
+		*action = REPLAY_PICK;
+	else if (item.command == TODO_REVERT)
+		*action = REPLAY_REVERT;
+	else
+		goto fail;
+
+	ret = 0;
+
+ fail:
+	strbuf_release(&buf);
+
+	return ret;
+}
+
 static int parse_insn_buffer(struct repository *r, char *buf,
 			     struct todo_list *todo_list)
 {
diff --git a/sequencer.h b/sequencer.h
index 6c7cf8d72f..c4b79165d3 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -145,3 +145,5 @@ void parse_strategy_opts(struct replay_opts *opts, char *raw_opts);
 int write_basic_state(struct replay_opts *opts, const char *head_name,
 		      const char *onto, const char *orig_head);
 void sequencer_post_commit_cleanup(struct repository *r);
+int sequencer_get_last_command(struct repository* r,
+			       enum replay_action *action);
diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
index 458608cc1e..c1eb72555d 100755
--- a/t/t7512-status-help.sh
+++ b/t/t7512-status-help.sh
@@ -780,6 +780,24 @@ EOF
 	test_i18ncmp expected actual
 '
 
+test_expect_success 'status when cherry-picking after committing conflict resolution' '
+	git reset --hard cherry_branch &&
+	test_when_finished "git cherry-pick --abort" &&
+	test_must_fail git cherry-pick cherry_branch_second one_cherry &&
+	echo end >main.txt &&
+	git commit -a &&
+	cat >expected <<EOF &&
+On branch cherry_branch
+Cherry-pick currently in progress.
+  (run "git cherry-pick --continue" to continue)
+  (use "git cherry-pick --abort" to cancel the cherry-pick operation)
+
+nothing to commit (use -u to show untracked files)
+EOF
+	git status --untracked-files=no >actual &&
+	test_i18ncmp expected actual
+'
+
 test_expect_success 'status showing detached at and from a tag' '
 	test_commit atag tagging &&
 	git checkout atag &&
@@ -857,6 +875,24 @@ EOF
 	test_i18ncmp expected actual
 '
 
+test_expect_success 'status while reverting after committing conflict resolution' '
+	test_when_finished "git revert --abort" &&
+	git reset --hard new &&
+	test_must_fail git revert old new &&
+	echo reverted >to-revert.txt &&
+	git commit -a &&
+	cat >expected <<EOF &&
+On branch master
+Revert currently in progress.
+  (run "git revert --continue" to continue)
+  (use "git revert --abort" to cancel the revert operation)
+
+nothing to commit (use -u to show untracked files)
+EOF
+	git status --untracked-files=no >actual &&
+	test_i18ncmp expected actual
+'
+
 test_expect_success 'prepare for different number of commits rebased' '
 	git reset --hard master &&
 	git checkout -b several_commits &&
diff --git a/wt-status.c b/wt-status.c
index 1f564b12d2..1dbb4d949c 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -17,6 +17,7 @@
 #include "utf8.h"
 #include "worktree.h"
 #include "lockfile.h"
+#include "sequencer.h"
 
 static const char cut_line[] =
 "------------------------ >8 ------------------------\n";
@@ -1369,12 +1370,22 @@ static void show_rebase_in_progress(struct wt_status *s,
 static void show_cherry_pick_in_progress(struct wt_status *s,
 					 const char *color)
 {
-	status_printf_ln(s, color, _("You are currently cherry-picking commit %s."),
-			find_unique_abbrev(&s->state.cherry_pick_head_oid, DEFAULT_ABBREV));
+	if (is_null_oid(&s->state.cherry_pick_head_oid))
+		status_printf_ln(s, color,
+			_("Cherry-pick currently in progress."));
+	else
+		status_printf_ln(s, color,
+			_("You are currently cherry-picking commit %s."),
+			find_unique_abbrev(&s->state.cherry_pick_head_oid,
+					   DEFAULT_ABBREV));
+
 	if (s->hints) {
 		if (has_unmerged(s))
 			status_printf_ln(s, color,
 				_("  (fix conflicts and run \"git cherry-pick --continue\")"));
+		else if (is_null_oid(&s->state.cherry_pick_head_oid))
+			status_printf_ln(s, color,
+				_("  (run \"git cherry-pick --continue\" to continue)"));
 		else
 			status_printf_ln(s, color,
 				_("  (all conflicts fixed: run \"git cherry-pick --continue\")"));
@@ -1387,12 +1398,21 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
 static void show_revert_in_progress(struct wt_status *s,
 				    const char *color)
 {
-	status_printf_ln(s, color, _("You are currently reverting commit %s."),
-			 find_unique_abbrev(&s->state.revert_head_oid, DEFAULT_ABBREV));
+	if (is_null_oid(&s->state.revert_head_oid))
+		status_printf_ln(s, color,
+			_("Revert currently in progress."));
+	else
+		status_printf_ln(s, color,
+			_("You are currently reverting commit %s."),
+			find_unique_abbrev(&s->state.revert_head_oid,
+					   DEFAULT_ABBREV));
 	if (s->hints) {
 		if (has_unmerged(s))
 			status_printf_ln(s, color,
 				_("  (fix conflicts and run \"git revert --continue\")"));
+		else if (is_null_oid(&s->state.revert_head_oid))
+			status_printf_ln(s, color,
+				_("  (run \"git revert --continue\" to continue)"));
 		else
 			status_printf_ln(s, color,
 				_("  (all conflicts fixed: run \"git revert --continue\")"));
@@ -1563,6 +1583,7 @@ void wt_status_get_state(struct repository *r,
 {
 	struct stat st;
 	struct object_id oid;
+	enum replay_action action;
 
 	if (!stat(git_path_merge_head(r), &st)) {
 		wt_status_check_rebase(NULL, state);
@@ -1580,7 +1601,15 @@ void wt_status_get_state(struct repository *r,
 		state->revert_in_progress = 1;
 		oidcpy(&state->revert_head_oid, &oid);
 	}
-
+	if (!sequencer_get_last_command(r, &action)) {
+		if (action == REPLAY_PICK) {
+			state->cherry_pick_in_progress = 1;
+			oidcpy(&state->cherry_pick_head_oid, &null_oid);
+		} else {
+			state->revert_in_progress = 1;
+			oidcpy(&state->revert_head_oid, &null_oid);
+		}
+	}
 	if (get_detached_from)
 		wt_status_get_detached_from(r, state);
 }
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 1/2] commit/reset: try to clean up sequencer state
  2019-04-16 10:18   ` [PATCH v2 1/2] commit/reset: try to clean up sequencer state Phillip Wood
@ 2019-04-17  7:04     ` Junio C Hamano
  2019-04-17 12:26       ` Johannes Schindelin
  0 siblings, 1 reply; 15+ messages in thread
From: Junio C Hamano @ 2019-04-17  7:04 UTC (permalink / raw)
  To: Phillip Wood
  Cc: Git Mailing List, Johannes Schindelin, Elijah Newren, Duy Nguyen,
	Phillip Wood

Phillip Wood <phillip.wood123@gmail.com> writes:

> Avoid this
> potential problem by removing the sequencer state if we're committing or
> resetting the final pick in a sequence.

The use-case story before this conclusion only mentioned "commit"
that concluded the multi-step cherry-pick/revert, and never talked
about "reset", which made my eyebrows to rise.

As a part of "reset", we have already been removing CHERRY_PICK_HEAD
and REVERT_HEAD, so "git reset" during a conflicted "cherry-pick"
for example is already destructive and the user can no longer get
back to continuing the cherry-pick anyway after running it, even
without this patch.  So from that point of view, it does make sense
to remove the other sequencer states at the same time.

Thanks.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 1/2] commit/reset: try to clean up sequencer state
  2019-04-17  7:04     ` Junio C Hamano
@ 2019-04-17 12:26       ` Johannes Schindelin
  2019-04-17 15:04         ` Phillip Wood
  0 siblings, 1 reply; 15+ messages in thread
From: Johannes Schindelin @ 2019-04-17 12:26 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Phillip Wood, Git Mailing List, Elijah Newren, Duy Nguyen,
	Phillip Wood

Hi,

On Wed, 17 Apr 2019, Junio C Hamano wrote:

> Phillip Wood <phillip.wood123@gmail.com> writes:
>
> > Avoid this potential problem by removing the sequencer state if we're
> > committing or resetting the final pick in a sequence.
>
> The use-case story before this conclusion only mentioned "commit"
> that concluded the multi-step cherry-pick/revert, and never talked
> about "reset", which made my eyebrows to rise.
>
> As a part of "reset", we have already been removing CHERRY_PICK_HEAD
> and REVERT_HEAD, so "git reset" during a conflicted "cherry-pick"
> for example is already destructive and the user can no longer get
> back to continuing the cherry-pick anyway after running it, even
> without this patch.  So from that point of view, it does make sense
> to remove the other sequencer states at the same time.

Do you mean to say that a `git reset` during `git cherry-pick <range>`
aborts it?

In my experience, this is not the case. The advice printed out after a
conflict even recommends to run `git reset` (followed by `git cherry-pick
--continue`, in lieu of the `git cherry-pick --skip` we have yet to
implement).

So I don't think it is correct to say that `git reset` does not let the
user get back to continuing a cherry-pick...

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 1/2] commit/reset: try to clean up sequencer state
  2019-04-17 12:26       ` Johannes Schindelin
@ 2019-04-17 15:04         ` Phillip Wood
  0 siblings, 0 replies; 15+ messages in thread
From: Phillip Wood @ 2019-04-17 15:04 UTC (permalink / raw)
  To: Johannes Schindelin, Junio C Hamano
  Cc: Git Mailing List, Elijah Newren, Duy Nguyen, Phillip Wood

Hi Dscho

On 17/04/2019 13:26, Johannes Schindelin wrote:
> Hi,
> 
> On Wed, 17 Apr 2019, Junio C Hamano wrote:
> 
>> Phillip Wood <phillip.wood123@gmail.com> writes:
>>
>>> Avoid this potential problem by removing the sequencer state if we're
>>> committing or resetting the final pick in a sequence.
>>
>> The use-case story before this conclusion only mentioned "commit"
>> that concluded the multi-step cherry-pick/revert, and never talked
>> about "reset", which made my eyebrows to rise.
>>
>> As a part of "reset", we have already been removing CHERRY_PICK_HEAD
>> and REVERT_HEAD, so "git reset" during a conflicted "cherry-pick"
>> for example is already destructive and the user can no longer get
>> back to continuing the cherry-pick anyway after running it, even
>> without this patch.  So from that point of view, it does make sense
>> to remove the other sequencer states at the same time.
> 
> Do you mean to say that a `git reset` during `git cherry-pick <range>`
> aborts it?

No I mean it removes CHERRY_PICK_HEAD/REVERT_HEAD and so cancels the 
conflicting pick/revert, it does not abort the operation as a whole. If 
the conflicting pick/revert was the last in a range then we want it to 
remove .git/sequencer as well as the ..._HEAD file as it is easy to 
forget to run --continue in that case.

Best Wishes

Phillip

> In my experience, this is not the case. The advice printed out after a
> conflict even recommends to run `git reset` (followed by `git cherry-pick
> --continue`, in lieu of the `git cherry-pick --skip` we have yet to
> implement).
> 
> So I don't think it is correct to say that `git reset` does not let the
> user get back to continuing a cherry-pick...
> 
> Ciao,
> Dscho
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-04-17 15:04 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-29 16:30 [PATCH 0/2] A couple of cherry-pick related fixes Phillip Wood
2019-03-29 16:30 ` [PATCH 1/2] commit/reset: try to clean up sequencer state Phillip Wood
2019-04-01  8:28   ` Junio C Hamano
2019-04-08 14:15     ` Phillip Wood
2019-04-01 10:09   ` Duy Nguyen
2019-04-08 15:47     ` Phillip Wood
2019-03-29 16:30 ` [PATCH 2/2] fix cherry-pick/revert status after commit Phillip Wood
2019-04-01  8:34   ` Junio C Hamano
2019-04-08 14:17     ` Phillip Wood
2019-04-16 10:18 ` [PATCH v2 0/2] A couple of cherry-pick related fixes Phillip Wood
2019-04-16 10:18   ` [PATCH v2 1/2] commit/reset: try to clean up sequencer state Phillip Wood
2019-04-17  7:04     ` Junio C Hamano
2019-04-17 12:26       ` Johannes Schindelin
2019-04-17 15:04         ` Phillip Wood
2019-04-16 10:18   ` [PATCH v2 2/2] fix cherry-pick/revert status after commit Phillip Wood

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).