1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-11-18 15:04:49 +01:00
git/t/t3409-rebase-preserve-merges.sh
Andrew Wong 12bf828348 rebase -i -p: include non-first-parent commits in todo list
Consider this graph:

        D---E    (topic, HEAD)
       /   /
  A---B---C      (master)
   \
    F            (topic2)

and the following three commands:
  1. git rebase -i -p A
  2. git rebase -i -p --onto F A
  3. git rebase -i -p B

Currently, (1) and (2) will pick B, D, C, and E onto A and F,
respectively.  However, (3) will only pick D and E onto B, but not C,
which is inconsistent with (1) and (2).  As a result, we cannot modify C
during the interactive-rebase.

The current behavior also creates a bug if we do:
  4. git rebase -i -p C

In (4), E is never picked.  And since interactive-rebase resets "HEAD"
to "onto" before picking any commits, D and E are lost after the
interactive-rebase.

This patch fixes the inconsistency and bug by ensuring that all children
of upstream are always picked.  This essentially reverts the commit:
  d80d6bc146

When compiling the todo list, commits reachable from "upstream" should
never be skipped under any conditions.  Otherwise, we lose the ability
to modify them like (3), and create a bug like (4).

Two of the tests contain a scenario like (3).  Since the new behavior
added more commits for picking, these tests need to be updated to
account for the additional pick lines.  A new test has also been added
for (4).

Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-19 14:37:23 -07:00

152 lines
3.5 KiB
Bash
Executable file

#!/bin/sh
#
# Copyright(C) 2008 Stephen Habermann & Andreas Ericsson
#
test_description='git rebase -p should preserve merges
Run "git rebase -p" and check that merges are properly carried along
'
. ./test-lib.sh
GIT_AUTHOR_EMAIL=bogus_email_address
export GIT_AUTHOR_EMAIL
# Clone 1 (trivial merge):
#
# A1--A2 <-- origin/master
# \ \
# B1--M <-- topic
# \
# B2 <-- origin/topic
#
# Clone 2 (conflicting merge):
#
# A1--A2--B3 <-- origin/master
# \ \
# B1------M <-- topic
# \
# B2 <-- origin/topic
#
# Clone 3 (no-ff merge):
#
# A1--A2--B3 <-- origin/master
# \
# B1------M <-- topic
# \ /
# \--A3 <-- topic2
# \
# B2 <-- origin/topic
#
# Clone 4 (merge using second parent as base):
#
# A1--A2--B3 <-- origin/master
# \
# B1--A3--M <-- topic
# \ /
# \--A4 <-- topic2
# \
# B2 <-- origin/topic
test_expect_success 'setup for merge-preserving rebase' \
'echo First > A &&
git add A &&
git commit -m "Add A1" &&
git checkout -b topic &&
echo Second > B &&
git add B &&
git commit -m "Add B1" &&
git checkout -f master &&
echo Third >> A &&
git commit -a -m "Modify A2" &&
git clone ./. clone1 &&
(cd clone1 &&
git checkout -b topic origin/topic &&
git merge origin/master
) &&
git clone ./. clone4 &&
(
cd clone4 &&
git checkout -b topic origin/topic &&
git merge origin/master
) &&
echo Fifth > B &&
git add B &&
git commit -m "Add different B" &&
git clone ./. clone2 &&
(
cd clone2 &&
git checkout -b topic origin/topic &&
test_must_fail git merge origin/master &&
echo Resolved >B &&
git add B &&
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"
'
test_expect_success 'rebase -p fakes interactive rebase' '
(
cd clone1 &&
git fetch &&
git rebase -p origin/topic &&
test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) &&
test 1 = $(git rev-list --all --pretty=oneline | grep "Merge remote-tracking branch " | wc -l)
)
'
test_expect_success '--continue works after a conflict' '
(
cd clone2 &&
git fetch &&
test_must_fail git rebase -p origin/topic &&
test 2 = $(git ls-files B | wc -l) &&
echo Resolved again > B &&
test_must_fail git rebase --continue &&
grep "^@@@ " .git/rebase-merge/patch &&
git add B &&
git rebase --continue &&
test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) &&
test 1 = $(git rev-list --all --pretty=oneline | grep "Add different" | wc -l) &&
test 1 = $(git rev-list --all --pretty=oneline | grep "Merge origin" | wc -l)
)
'
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_expect_success 'rebase -p works when base inside second parent' '
(
cd clone4 &&
git fetch &&
git rebase -p HEAD^2 &&
test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) &&
test 1 = $(git rev-list --all --pretty=oneline | grep "Modify B" | wc -l) &&
test 1 = $(git rev-list --all --pretty=oneline | grep "Merge remote-tracking branch " | wc -l)
)
'
test_done