* [PATCH] git-rebase--interactive.sh: preserve-merges fails on merges created with no-ff
@ 2011-04-21 3:38 Andrew Wong
2011-04-27 2:24 ` Andrew Wong
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Wong @ 2011-04-21 3:38 UTC (permalink / raw
To: git; +Cc: Andrew Wong
'git rebase' uses 'git merge' to preserve merges (-p). This preserves
the original merge commit correctly, except when the original merge
commit was created by 'git merge --no-ff'. In this case, 'git rebase'
will fail to preserve the merge, because during 'git rebase', 'git
merge' will simply fast-forward and skip the commit. For example:
B
/ \
A---M
/
---o---O---P---Q
If we try to rebase M onto P, we lose the merge commit and this happens:
A---B
/
---o---O---P---Q
To correct this, we simply do a "no fast-forward" on all merge commits
when rebasing. Since by the time we decided to do a 'git merge' inside
'git rebase', it means there was a merge originally, so 'git merge'
should always create a merge commit regardless of what the merge
branches look like. This way, when rebase M onto P from the above
example, we get:
B
/ \
A---M
/
---o---O---P---Q
Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
---
git-rebase--interactive.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 5873ba4..c308529 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -339,7 +339,7 @@ pick_one_preserving_merges () {
# No point in merging the first parent, that's HEAD
new_parents=${new_parents# $first_parent}
if ! do_with_author output \
- git merge $STRATEGY -m "$msg" $new_parents
+ git merge --no-ff $STRATEGY -m "$msg" $new_parents
then
printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
die_with_patch $sha1 "Error redoing merge $sha1"
--
1.7.2.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] git-rebase--interactive.sh: preserve-merges fails on merges created with no-ff
2011-04-21 3:38 [PATCH] git-rebase--interactive.sh: preserve-merges fails on merges created with no-ff Andrew Wong
@ 2011-04-27 2:24 ` Andrew Wong
2011-04-27 5:00 ` Junio C Hamano
2011-04-27 17:29 ` Junio C Hamano
0 siblings, 2 replies; 6+ messages in thread
From: Andrew Wong @ 2011-04-27 2:24 UTC (permalink / raw
To: Andrew Wong; +Cc: git
Could someone please take a look at this patch?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] git-rebase--interactive.sh: preserve-merges fails on merges created with no-ff
2011-04-27 2:24 ` Andrew Wong
@ 2011-04-27 5:00 ` Junio C Hamano
2011-04-27 8:15 ` Christian Couder
2011-04-27 17:29 ` Junio C Hamano
1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2011-04-27 5:00 UTC (permalink / raw
To: Andrew Wong; +Cc: Andrew Wong, git
Andrew Wong <andrew.w@sohovfx.com> writes:
> Could someone please take a look at this patch?
I took a look at it when you sent it out, and found it so obviously and
trivially correct that I expected that others will soon say it looked
obviously the right thing to do. So I decided to wait until that to
happen before applying it.
But nobody said anything, and forgot about it.
Let's see if it happens soon enough this time ;-). Thanks for a reminder.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] git-rebase--interactive.sh: preserve-merges fails on merges created with no-ff
2011-04-27 5:00 ` Junio C Hamano
@ 2011-04-27 8:15 ` Christian Couder
0 siblings, 0 replies; 6+ messages in thread
From: Christian Couder @ 2011-04-27 8:15 UTC (permalink / raw
To: Junio C Hamano; +Cc: Andrew Wong, Andrew Wong, git
On Wed, Apr 27, 2011 at 7:00 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Andrew Wong <andrew.w@sohovfx.com> writes:
>
>> Could someone please take a look at this patch?
>
> I took a look at it when you sent it out, and found it so obviously and
> trivially correct that I expected that others will soon say it looked
> obviously the right thing to do.
Me too!
> So I decided to wait until that to
> happen before applying it.
>
> But nobody said anything, and forgot about it.
>
> Let's see if it happens soon enough this time ;-). Thanks for a reminder.
Thanks from me too,
Christian.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] git-rebase--interactive.sh: preserve-merges fails on merges created with no-ff
2011-04-27 2:24 ` Andrew Wong
2011-04-27 5:00 ` Junio C Hamano
@ 2011-04-27 17:29 ` Junio C Hamano
2011-04-28 4:35 ` [PATCH v2] " Andrew Wong
1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2011-04-27 17:29 UTC (permalink / raw
To: Andrew Wong; +Cc: Andrew Wong, git
Andrew Wong <andrew.w@sohovfx.com> writes:
> Could someone please take a look at this patch?
Can you add a test for this change, perhaps to either t3409 or t3414?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] git-rebase--interactive.sh: preserve-merges fails on merges created with no-ff
2011-04-27 17:29 ` Junio C Hamano
@ 2011-04-28 4:35 ` Andrew Wong
0 siblings, 0 replies; 6+ messages in thread
From: Andrew Wong @ 2011-04-28 4:35 UTC (permalink / raw
To: git; +Cc: Andrew Wong
'git rebase' uses 'git merge' to preserve merges (-p). This preserves
the original merge commit correctly, except when the original merge
commit was created by 'git merge --no-ff'. In this case, 'git rebase'
will fail to preserve the merge, because during 'git rebase', 'git
merge' will simply fast-forward and skip the commit. For example:
B
/ \
A---M
/
---o---O---P---Q
If we try to rebase M onto P, we lose the merge commit and this happens:
A---B
/
---o---O---P---Q
To correct this, we simply do a "no fast-forward" on all merge commits
when rebasing. Since by the time we decided to do a 'git merge' inside
'git rebase', it means there was a merge originally, so 'git merge'
should always create a merge commit regardless of what the merge
branches look like. This way, when rebase M onto P from the above
example, we get:
B
/ \
A---M
/
---o---O---P---Q
Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
---
git-rebase--interactive.sh | 2 +-
t/t3409-rebase-preserve-merges.sh | 32 +++++++++++++++++++++++++++++++-
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 5873ba4..c308529 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -339,7 +339,7 @@ pick_one_preserving_merges () {
# No point in merging the first parent, that's HEAD
new_parents=${new_parents# $first_parent}
if ! do_with_author output \
- git merge $STRATEGY -m "$msg" $new_parents
+ git merge --no-ff $STRATEGY -m "$msg" $new_parents
then
printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
die_with_patch $sha1 "Error redoing merge $sha1"
diff --git a/t/t3409-rebase-preserve-merges.sh b/t/t3409-rebase-preserve-merges.sh
index 19341e5..08201e2 100755
--- a/t/t3409-rebase-preserve-merges.sh
+++ b/t/t3409-rebase-preserve-merges.sh
@@ -27,7 +27,17 @@ export GIT_AUTHOR_EMAIL
# \
# B2 <-- origin/topic
#
-# In both cases, 'topic' is rebased onto 'origin/topic'.
+# Clone 3 (no-ff merge):
+#
+# A1--A2--B3 <-- origin/master
+# \
+# B1------M <-- topic
+# \ /
+# \--A3 <-- topic2
+# \
+# B2 <-- origin/topic
+#
+# In all cases, 'topic' is rebased onto 'origin/topic'.
test_expect_success 'setup for merge-preserving rebase' \
'echo First > A &&
@@ -61,6 +71,16 @@ test_expect_success 'setup for merge-preserving rebase' \
git commit -m "Merge origin/master into topic"
) &&
+ git clone ./. clone3 &&
+ (
+ cd clone3 &&
+ git checkout -b topic2 origin/topic &&
+ echo Sixth > A &&
+ git commit -a -m "Modify A3" &&
+ git checkout -b topic origin/topic &&
+ git merge --no-ff topic2
+ ) &&
+
git checkout topic &&
echo Fourth >> B &&
git commit -a -m "Modify B2"
@@ -93,4 +113,14 @@ test_expect_success '--continue works after a conflict' '
)
'
+test_expect_success 'rebase -p preserves no-ff merges' '
+ (
+ cd clone3 &&
+ git fetch &&
+ git rebase -p origin/topic &&
+ test 3 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) &&
+ test 1 = $(git rev-list --all --pretty=oneline | grep "Merge branch" | wc -l)
+ )
+'
+
test_done
--
1.7.2.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-04-28 4:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-21 3:38 [PATCH] git-rebase--interactive.sh: preserve-merges fails on merges created with no-ff Andrew Wong
2011-04-27 2:24 ` Andrew Wong
2011-04-27 5:00 ` Junio C Hamano
2011-04-27 8:15 ` Christian Couder
2011-04-27 17:29 ` Junio C Hamano
2011-04-28 4:35 ` [PATCH v2] " Andrew Wong
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).