[RFC PATCH] Why doesn't git rebase --interactive --preserve-merges continue past known conflicts?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2010-12-31, David Kilzer wrote:
> When I run "git rebase --interactive --preserve-merges" on a sequence of 
> commits, edit an earlier commit, then run "git rebase --continue", the rebase 
> operation always stops on a merge commit with a known conflict (in the rr-cache) 
> instead of resolving it and continuing.
> 
> As long as I'm not rearranging commits, I expect git-rebase to resolve the known 
> merge commit conflict and continue.  Why does it always stop?

Here's a very rough patch that fixes my original test case so that an interactive
rebase won't stop when git-rerere knows how to resolve all conflicts during a
merge.

However, if there are any changes to a non-conflicted file during the original
merge commit, they will be lost when rebasing, even with --preserve-merges.
Note that this occurs even without this patch applied.  You must compare the
current commit with original being rebased to make sure they're not lost.

Why doesn't an interactive rebase serialize to disk all of the changes in a merge
commit like it does for non-merge commits?

Dave
---
 git-rebase--interactive.sh                    |   11 ++++-
 t/t3404-rebase-interactive-preserve-merges.sh |   64 +++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 2 deletions(-)
 create mode 100755 t/t3404-rebase-interactive-preserve-merges.sh

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index a5ffd9a..32375bc 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -338,11 +338,18 @@ pick_one_preserving_merges () {
 			msg="$(commit_message $sha1)"
 			# No point in merging the first parent, that's HEAD
 			new_parents=${new_parents# $first_parent}
+			# If rerere is enabled, pass the --rerere-autoupdate flag
+			test "$(git config --bool rerere.enabled)" = "true" &&
+				rerere_autoupdate=--rerere-autoupdate || rerere_autoupdate=
 			if ! do_with_author output \
-				git merge $STRATEGY -m "$msg" $new_parents
+				git merge $STRATEGY $rerere_autoupdate -m "$msg" $new_parents
 			then
 				printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
-				die_with_patch $sha1 "Error redoing merge $sha1"
+				# Commit the result if rerere resolved all the conflicts.
+				git update-index -q --refresh &&
+					printf "Resolved all conflicts using rerere.\n"  &&
+					do_with_author git commit --no-verify -F "$GIT_DIR"/MERGE_MSG ||
+					die_with_patch $sha1 "Error redoing merge $sha1"
 			fi
 			echo "$sha1 $(git rev-parse HEAD^0)" >> "$REWRITTEN_LIST"
 			;;
diff --git a/t/t3404-rebase-interactive-preserve-merges.sh b/t/t3404-rebase-interactive-preserve-merges.sh
new file mode 100755
index 0000000..3479f38
--- /dev/null
+++ b/t/t3404-rebase-interactive-preserve-merges.sh
@@ -0,0 +1,64 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Johannes E. Schindelin
+# Copyright (c) 2010 David D. Kilzer
+#
+
+test_description='git rebase --interactive --preserve-matches does not automatically resolve known conflicts in merge commits'
+. ./test-lib.sh
+
+. "$TEST_DIRECTORY"/lib-rebase.sh
+
+set_fake_editor
+
+test_expect_success 'setup' '
+	test_commit A file1 &&
+	test_commit AA file2 &&
+	test_commit B file1 &&
+	git checkout -b topic1 HEAD^ &&
+	test_commit C file1 &&
+	git checkout master
+'
+
+test_expect_success 'rebase --interactive --preserve-merges should use rerere to resolve conflicts' '
+	git config rerere.enabled 1 &&
+	git rerere clear &&
+
+	git checkout -b merge1 master &&
+	test_must_fail git merge topic1 &&
+	printf "B\nC\n" > file1 &&
+	git add file1 &&
+	git commit -m "Merged." &&
+	git branch merge1-baseline &&
+
+	FAKE_LINES="edit 1 2" git rebase -i -p HEAD~2 &&
+	echo BB >> file2 &&
+	git add file2 &&
+	git commit --amend &&
+	git rebase --continue &&
+	git diff --exit-code merge1-baseline..merge1 file1
+'
+
+test_expect_success 'rebase --interactive --preserve-merges should not lose changes in merge commits' '
+	git config rerere.enabled 1 &&
+	git rerere clear &&
+
+	git checkout -b merge2 master &&
+	test_must_fail git merge topic1 &&
+	printf "B\nC\n" > file1 &&
+	git add file1 &&
+	echo BB >> file2 &&
+	git add file2 &&
+	git commit -m "Merged with change to non-conflicted file." &&
+	git branch merge2-baseline &&
+
+	FAKE_LINES="edit 1 2" git rebase -i -p HEAD~2 &&
+	echo AAA > file3 &&
+	git add file3 &&
+	git commit --amend &&
+	git rebase --continue &&
+	git diff --exit-code merge2-baseline..merge2 file1 &&
+	git diff --exit-code merge2-baseline..merge2 file2
+'
+
+test_done
-- 
1.7.2.1.103.g48452

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]