From: "David D. Kilzer" <ddkilzer@kilzer.net>
To: git@vger.kernel.org
Cc: "David D. Kilzer" <ddkilzer@kilzer.net>
Subject: [RFC PATCH] Why doesn't git rebase --interactive --preserve-merges continue past known conflicts?
Date: Sat, 1 Jan 2011 17:20:02 -0800 [thread overview]
Message-ID: <1293931202-88931-1-git-send-email-ddkilzer@kilzer.net> (raw)
In-Reply-To: <282560.39741.qm@web30004.mail.mud.yahoo.com>
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
prev parent reply other threads:[~2011-01-02 1:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-31 19:30 Why doesn't git rebase --interactive --preserve-merges continue past known conflicts? David D. Kilzer
2011-01-02 1:20 ` David D. Kilzer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1293931202-88931-1-git-send-email-ddkilzer@kilzer.net \
--to=ddkilzer@kilzer.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).