git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5 14/36] revert/cherry-pick: add --skip option

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Jun 9, 2013, 19:24 UTC
Message-ID
<1370805890-3453-15-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1370805890-3453-1-git-send-email-felipe.contreras@gmail.com>
Akin to 'am --skip' and 'rebase --skip'.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 Documentation/git-cherry-pick.txt |  1 +
 Documentation/git-revert.txt      |  1 +
 Documentation/sequencer.txt       |  3 +++
 builtin/revert.c                  |  6 ++++++
 builtin/sequencer.c               | 24 ++++++++++++++++++++++++
 builtin/sequencer.h               |  3 ++-
 t/t3510-cherry-pick-sequence.sh   | 12 ++++++++++++
 7 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt
index da0bd81..d95c63c 100644
--- a/Documentation/git-cherry-pick.txt
+++ b/Documentation/git-cherry-pick.txt
@@ -10,6 +10,7 @@ SYNOPSIS
 [verse]
 'git cherry-pick' [-q] [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>...
 'git cherry-pick' --continue
+'git cherry-pick' --skip
 'git cherry-pick' --quit
 'git cherry-pick' --abort
 
diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt
index 98a8e7a..52e146e 100644
--- a/Documentation/git-revert.txt
+++ b/Documentation/git-revert.txt
@@ -10,6 +10,7 @@ SYNOPSIS
 [verse]
 'git revert' [-q] [--[no-]edit] [-n] [-m parent-number] [-s] <commit>...
 'git revert' --continue
+'git revert' --skip
 'git revert' --quit
 'git revert' --abort
 
diff --git a/Documentation/sequencer.txt b/Documentation/sequencer.txt
index 5747f44..df2d355 100644
--- a/Documentation/sequencer.txt
+++ b/Documentation/sequencer.txt
@@ -3,6 +3,9 @@
 	'.git/sequencer'.  Can be used to continue after resolving
 	conflicts in a failed cherry-pick or revert.
 
+--skip::
+	Skip the current commit, and then continue.
+
 --quit::
 	Forget about the current operation in progress.  Can be used
 	to clear the sequencer state after a failed cherry-pick or
diff --git a/builtin/revert.c b/builtin/revert.c
index ec83748..d3d5600 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -99,11 +99,13 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
 	int remove_state = 0;
 	int contin = 0;
 	int rollback = 0;
+	int skip = 0;
 	struct option options[] = {
 		OPT__QUIET(&opts->quiet, N_("suppress progress reporting")),
 		OPT_BOOLEAN(0, "quit", &remove_state, N_("end revert or cherry-pick sequence")),
 		OPT_BOOLEAN(0, "continue", &contin, N_("resume revert or cherry-pick sequence")),
 		OPT_BOOLEAN(0, "abort", &rollback, N_("cancel revert or cherry-pick sequence")),
+		OPT_BOOLEAN(0, "skip", &skip, N_("skip current commit in the sequence")),
 		OPT_BOOLEAN('n', "no-commit", &opts->no_commit, N_("don't automatically commit")),
 		OPT_BOOLEAN('e', "edit", &opts->edit, N_("edit the commit message")),
 		OPT_NOOP_NOARG('r', NULL),
@@ -164,6 +166,8 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
 		opts->subcommand = REPLAY_CONTINUE;
 	else if (rollback)
 		opts->subcommand = REPLAY_ROLLBACK;
+	else if (skip)
+		opts->subcommand = REPLAY_SKIP;
 	else
 		opts->subcommand = REPLAY_NONE;
 
@@ -174,6 +178,8 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
 			this_operation = "--quit";
 		else if (opts->subcommand == REPLAY_CONTINUE)
 			this_operation = "--continue";
+		else if (opts->subcommand == REPLAY_SKIP)
+			this_operation = "--skip";
 		else {
 			assert(opts->subcommand == REPLAY_ROLLBACK);
 			this_operation = "--abort";
diff --git a/builtin/sequencer.c b/builtin/sequencer.c
index 0f50942..2b1b30a 100644
--- a/builtin/sequencer.c
+++ b/builtin/sequencer.c
@@ -961,6 +961,28 @@ static int sequencer_continue(struct replay_opts *opts)
 	return pick_commits(todo_list, opts);
 }
 
+static int sequencer_skip(struct replay_opts *opts)
+{
+	const char *argv[4]; /* reset --hard HEAD + NULL */
+	struct string_list merge_rr = STRING_LIST_INIT_DUP;
+	int ret;
+
+	if (setup_rerere(&merge_rr, 0) >= 0) {
+		rerere_clear(&merge_rr);
+		string_list_clear(&merge_rr, 1);
+	}
+
+	argv[0] = "reset";
+	argv[1] = "--hard";
+	argv[2] = "HEAD";
+	argv[3] = NULL;
+	ret = run_command_v_opt(argv, RUN_GIT_CMD);
+	if (ret)
+		return ret;
+
+	return sequencer_continue(opts);
+}
+
 static int single_pick(struct commit *cmit, struct replay_opts *opts)
 {
 	setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
@@ -991,6 +1013,8 @@ int sequencer_pick_revisions(struct replay_opts *opts)
 		return sequencer_rollback(opts);
 	if (opts->subcommand == REPLAY_CONTINUE)
 		return sequencer_continue(opts);
+	if (opts->subcommand == REPLAY_SKIP)
+		return sequencer_skip(opts);
 
 	for (i = 0; i < opts->revs->pending.nr; i++) {
 		unsigned char sha1[20];
diff --git a/builtin/sequencer.h b/builtin/sequencer.h
index e45411c..e69495a 100644
--- a/builtin/sequencer.h
+++ b/builtin/sequencer.h
@@ -15,7 +15,8 @@ enum replay_subcommand {
 	REPLAY_NONE,
 	REPLAY_REMOVE_STATE,
 	REPLAY_CONTINUE,
-	REPLAY_ROLLBACK
+	REPLAY_ROLLBACK,
+	REPLAY_SKIP
 };
 
 struct replay_opts {
diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh
index 33c5512..c43c327 100755
--- a/t/t3510-cherry-pick-sequence.sh
+++ b/t/t3510-cherry-pick-sequence.sh
@@ -511,4 +511,16 @@ test_expect_success 'commit descriptions in insn sheet are optional' '
 	test_line_count = 4 commits
 '
 
+test_expect_success 'skip' '
+	pristine_detach conflicting &&
+	test_must_fail git cherry-pick initial..picked &&
+
+	git checkout HEAD -- unrelated &&
+	test_must_fail git cherry-pick --continue &&
+	git cherry-pick --skip &&
+
+	git rev-list initial..HEAD >commits &&
+	test_line_count = 3 commits
+'
+
 test_done
-- 
1.8.3.698.g079b096
Previous: Felipe ContrerasNext: Felipe Contreras
Message 15 of 42 in “Massive improvents to rebase and cherry-pick”
  1. 00/36 Massive improvents to rebase and cherry-pickFelipe Contreras, Jun 9, 2013
  2. 01/36 build: generate and clean test scriptsFelipe Contreras, Jun 9, 2013
  3. 02/36 build: do not install git-remote-testgitFelipe Contreras, Jun 9, 2013
  4. 03/36 build: trivial cleanupFelipe Contreras, Jun 9, 2013
  5. 04/36 build: add builtin libFelipe Contreras, Jun 9, 2013
  6. 05/36 log-tree: remove dependency from sequencerFelipe Contreras, Jun 9, 2013
  7. 06/36 Move sequencer to builtinFelipe Contreras, Jun 9, 2013
  8. 07/36 unpack-trees: plug a memory leakFelipe Contreras, Jun 9, 2013
  9. 08/36 read-cache: plug a few leaksFelipe Contreras, Jun 9, 2013
  10. 09/36 sequencer: remove useless indentationFelipe Contreras, Jun 9, 2013
  11. 10/36 sequencer: trivial fixFelipe Contreras, Jun 9, 2013
  12. 11/36 cherry-pick: don't barf when there's nothing to doFelipe Contreras, Jun 9, 2013
  13. 12/36 cherry-pick: add --skip-empty optionFelipe Contreras, Jun 9, 2013
  14. 13/36 revert/cherry-pick: add --quiet optionFelipe Contreras, Jun 9, 2013
  15. 14/36 revert/cherry-pick: add --skip optionFelipe Contreras, Jun 9, 2013
  16. 15/36 builtin: add rewrite helperFelipe Contreras, Jun 9, 2013
  17. 16/36 cherry-pick: store rewritten commitsFelipe Contreras, Jun 9, 2013
  18. 17/36 cherry-pick: don't store skipped commitFelipe Contreras, Jun 9, 2013
  19. 18/36 builtin: move run_rewrite_hook() to rewrite.cFelipe Contreras, Jun 9, 2013
  20. 19/36 builtin: add copy_rewrite_notes()Felipe Contreras, Jun 9, 2013
  21. 20/36 cherry-pick: copy notes and run hooksFelipe Contreras, Jun 9, 2013
  22. 21/36 cherry-pick: add --action-name optionFelipe Contreras, Jun 9, 2013
  23. 22/36 cherry-pick: remember rerere-autoupdateFelipe Contreras, Jun 9, 2013
  24. 23/36 rebase: split the cherry-pick stuffFelipe Contreras, Jun 9, 2013
  25. 24/36 rebase: cherry-pick: fix mode storageFelipe Contreras, Jun 9, 2013
  26. 25/36 rebase: cherry-pick: fix sequence continuationFelipe Contreras, Jun 9, 2013
  27. 26/36 rebase: cherry-pick: fix abort of cherry modeFelipe Contreras, Jun 9, 2013
  28. 27/36 rebase: cherry-pick: fix command invocationsFelipe Contreras, Jun 9, 2013
  29. 28/36 rebase: cherry-pick: fix status messagesFelipe Contreras, Jun 9, 2013
  30. 29/36 rebase: cherry-pick: automatically commit stageFelipe Contreras, Jun 9, 2013
  31. 30/36 rebase: cherry-pick: set correct action-nameFelipe Contreras, Jun 9, 2013
  32. 31/36 rebase: trivial cleanupFelipe Contreras, Jun 9, 2013
  33. 32/36 rebase: use 'cherrypick' mode instead of 'am'Felipe Contreras, Jun 9, 2013
  34. 33/36 rebase: cherry-pick: fix for shell promptFelipe Contreras, Jun 9, 2013
  35. 34/36 rebase: cherry-pick: add merge optionsFelipe Contreras, Jun 9, 2013
  36. 35/36 rebase: remove merge modeFelipe Contreras, Jun 9, 2013
  37. 36/36 rebase: cherry-pick: add copyrightFelipe Contreras, Jun 9, 2013
  38. Felipe ContrerasJun 9, 2013
  39. Phil HordJun 10, 2013
  40. Felipe ContrerasJun 10, 2013
  41. Phil HordJun 11, 2013
  42. Felipe ContrerasJun 11, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.