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

[PATCH 6/7] sequencer: teach '--continue' how to commit

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Nov 13, 2011, 10:46 UTC
Message-ID
<1321181181-23923-7-git-send-email-artagnon@gmail.com>
In-Reply-To
<1321181181-23923-1-git-send-email-artagnon@gmail.com>

As discussed earlier in the series, the commit-before-continue convention has caused a lot of workflow inconsistencies. Teach '--continue' how to commit so that you can now do:

  $ git cherry-pick foo..bar
  ... conflict occured in bar~1 ...
  $ echo "resolved" >problematicfile
  $ git add problematicfile
  $ git sequencer --continue

Modify existing tests in 't3510-sequencer.sh' to exclude the 'git commit' step, and port relevant tests from 't3511-cherry-pick-sequence.sh' after removing the 'git commit' step. Note that the tests in 't3511-cherry-pick-sequence.sh' (with the 'git commit' step) still need to respect backward compatibility.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 sequencer.c          |   10 +++++++-
 t/t3510-sequencer.sh |   51 +++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 52 insertions(+), 9 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index 012d531..7b10b7b 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -269,7 +269,7 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts)
 	args[i++] = "-n";
 	if (opts->signoff)
 		args[i++] = "-s";
-	if (!opts->edit) {
+	if (!opts->edit && defmsg) {
 		args[i++] = "-F";
 		args[i++] = defmsg;
 	}
@@ -776,6 +776,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)
 {
 	struct replay_insn_list *todo_list = NULL;
 	unsigned char sha1[20];
+	int res;
 
 	if (opts->subcommand == REPLAY_NONE)
 		assert(opts->revs);
@@ -796,9 +797,14 @@ int sequencer_pick_revisions(struct replay_opts *opts)
 		read_populate_opts(&opts);
 		read_populate_todo(&todo_list);
 
-		/* Verify that the conflict has been resolved */
 		if (!index_differs_from("HEAD", 0))
 			todo_list = todo_list->next;
+		else if (!opts->no_commit && !read_cache_unmerged()) {
+			res = run_git_commit(NULL, opts);
+			if (res)
+				return res;
+			todo_list = todo_list->next;
+		}
 	} else {
 		/*
 		 * Start a new cherry-pick/ revert sequence; but
diff --git a/t/t3510-sequencer.sh b/t/t3510-sequencer.sh
index 6b2e712..65f2724 100755
--- a/t/t3510-sequencer.sh
+++ b/t/t3510-sequencer.sh
@@ -45,12 +45,54 @@ test_expect_success '--continue complains when there are unresolved conflicts' '
 	test_must_fail git sequencer --continue
 '
 
+test_expect_success '--continue continues after conflicts are resolved' '
+	pristine_detach initial &&
+	test_must_fail git cherry-pick base..anotherpick &&
+	echo "c" >foo &&
+	git add foo &&
+	git sequencer --continue &&
+	test_path_is_missing .git/sequencer &&
+	{
+		git rev-list HEAD |
+		git diff-tree --root --stdin |
+		sed "s/$_x40/OBJID/g"
+	} >actual &&
+	cat >expect <<-\EOF &&
+	OBJID
+	:100644 100644 OBJID OBJID M	foo
+	OBJID
+	:100644 100644 OBJID OBJID M	foo
+	OBJID
+	:100644 100644 OBJID OBJID M	unrelated
+	OBJID
+	:000000 100644 OBJID OBJID A	foo
+	:000000 100644 OBJID OBJID A	unrelated
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success '--continue respects opts' '
+	pristine_detach initial &&
+	test_must_fail git cherry-pick -x base..anotherpick &&
+	echo "c" >foo &&
+	git add foo &&
+	git sequencer --continue &&
+	test_path_is_missing .git/sequencer &&
+	git cat-file commit HEAD >anotherpick_msg &&
+	git cat-file commit HEAD~1 >picked_msg &&
+	git cat-file commit HEAD~2 >unrelatedpick_msg &&
+	git cat-file commit HEAD~3 >initial_msg &&
+	test_must_fail grep "cherry picked from" initial_msg &&
+	grep "cherry picked from" unrelatedpick_msg &&
+	grep "cherry picked from" picked_msg &&
+	grep "cherry picked from" anotherpick_msg
+'
+
 test_expect_success 'malformed instruction sheet 1' '
 	pristine_detach initial &&
 	test_must_fail git cherry-pick base..anotherpick &&
 	echo "resolved" >foo &&
 	git add foo &&
-	git commit &&
 	sed "s/pick /pick/" .git/sequencer/todo >new_sheet &&
 	cp new_sheet .git/sequencer/todo &&
 	test_must_fail git sequencer --continue
@@ -61,7 +103,6 @@ test_expect_success 'malformed instruction sheet 2' '
 	test_must_fail git cherry-pick base..anotherpick &&
 	echo "resolved" >foo &&
 	git add foo &&
-	git commit &&
 	sed "s/pick/revert/" .git/sequencer/todo >new_sheet &&
 	cp new_sheet .git/sequencer/todo &&
 	test_must_fail git sequencer --continue
@@ -72,7 +113,6 @@ test_expect_success 'malformed instruction sheet 3' '
 	test_must_fail git cherry-pick base..anotherpick &&
 	echo "resolved" >foo &&
 	git add foo &&
-	git commit &&
 	sed "s/pick \([0-9a-f]*\)/pick $_r10/" .git/sequencer/todo >new_sheet &&
 	cp new_sheet .git/sequencer/todo &&
 	test_must_fail git sequencer --continue
@@ -83,7 +123,6 @@ test_expect_success 'commit descriptions in insn sheet are optional' '
 	test_must_fail git cherry-pick base..anotherpick &&
 	echo "c" >foo &&
 	git add foo &&
-	git commit &&
 	cut -d" " -f1,2 .git/sequencer/todo >new_sheet &&
 	cp new_sheet .git/sequencer/todo &&
 	git sequencer --continue &&
@@ -97,7 +136,6 @@ test_expect_success 'revert --continue continues after cherry-pick' '
 	test_must_fail git cherry-pick base..anotherpick &&
 	echo "c" >foo &&
 	git add foo &&
-	git commit &&
 	git revert --continue &&
 	test_path_is_missing .git/sequencer &&
 	{
@@ -120,12 +158,11 @@ test_expect_success 'revert --continue continues after cherry-pick' '
 '
 
 test_expect_success 'mixed pick and revert instructions' '
+	oldsha=`git rev-parse --short HEAD~2` &&
 	pristine_detach initial &&
 	test_must_fail git cherry-pick base..anotherpick &&
 	echo "c" >foo &&
 	git add foo &&
-	git commit &&
-	oldsha=`git rev-parse --short HEAD~1` &&
 	echo "revert $oldsha unrelatedpick" >>.git/sequencer/todo &&
 	git sequencer --continue &&
 	test_path_is_missing .git/sequencer &&
-- 
1.7.6.351.gb35ac.dirty
Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 11 of 17 in “New sequencer workflow!”
  1. 0/7 New sequencer workflow!Ramkumar Ramachandra, Nov 13, 2011
  2. 1/7 sequencer: factor code out of revert builtinRamkumar Ramachandra, Nov 13, 2011
  3. 2/7 sequencer: invalidate sequencer state without todoRamkumar Ramachandra, Nov 13, 2011
  4. 3/7 sequencer: handle single-commit pick as special caseRamkumar Ramachandra, Nov 13, 2011
  5. Junio C HamanoNov 13, 2011
  6. Ramkumar RamachandraNov 15, 2011
  7. Junio C HamanoNov 15, 2011
  8. Ramkumar RamachandraNov 16, 2011
  9. 4/7 sequencer: handle cherry-pick conflict in last commitRamkumar Ramachandra, Nov 13, 2011
  10. 5/7 sequencer: introduce git-sequencer builtinRamkumar Ramachandra, Nov 13, 2011
  11. 6/7 sequencer: teach '--continue' how to commitRamkumar Ramachandra, Nov 13, 2011
  12. 7/7 sequencer: teach parser about CHERRY_PICK_HEADRamkumar Ramachandra, Nov 13, 2011
  13. Junio C HamanoNov 13, 2011
  14. Junio C HamanoNov 14, 2011
  15. Ramkumar RamachandraNov 15, 2011
  16. Phil HordNov 15, 2011
  17. Ramkumar RamachandraNov 15, 2011

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.