git/t/t3411-rebase-preserve-around-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

75 lines
1.5 KiB
Bash
Executable file

#!/bin/sh
#
# Copyright (c) 2008 Stephen Haberman
#
test_description='git rebase preserve merges
This test runs git rebase with -p and tries to squash a commit from after
a merge to before the merge.
'
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-rebase.sh
set_fake_editor
# set up two branches like this:
#
# A1 - B1 - D1 - E1 - F1
# \ /
# -- C1 --
test_expect_success 'setup' '
test_commit A1 &&
test_commit B1 &&
test_commit C1 &&
git reset --hard B1 &&
test_commit D1 &&
test_merge E1 C1 &&
test_commit F1
'
# Should result in:
#
# A1 - B1 - D2 - E2
# \ /
# -- C1 --
#
test_expect_success 'squash F1 into D1' '
FAKE_LINES="1 squash 4 2 3" git rebase -i -p B1 &&
test "$(git rev-parse HEAD^2)" = "$(git rev-parse C1)" &&
test "$(git rev-parse HEAD~2)" = "$(git rev-parse B1)" &&
git tag E2
'
# Start with:
#
# A1 - B1 - D2 - E2
# \
# G1 ---- L1 ---- M1
# \ /
# H1 -- J1 -- K1
# \ /
# -- I1 --
#
# And rebase G1..M1 onto E2
test_expect_success 'rebase two levels of merge' '
test_commit G1 &&
test_commit H1 &&
test_commit I1 &&
git checkout -b branch3 H1 &&
test_commit J1 &&
test_merge K1 I1 &&
git checkout -b branch2 G1 &&
test_commit L1 &&
test_merge M1 K1 &&
GIT_EDITOR=: git rebase -i -p E2 &&
test "$(git rev-parse HEAD~3)" = "$(git rev-parse E2)" &&
test "$(git rev-parse HEAD~2)" = "$(git rev-parse HEAD^2^2~2)" &&
test "$(git rev-parse HEAD^2^1^1)" = "$(git rev-parse HEAD^2^2^1)"
'
test_done