Stephen Haberman | 42f939e | 2008-10-15 02:44:34 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2008 Stephen Haberman |
| 4 | # |
| 5 | |
| 6 | test_description='git rebase preserve merges |
| 7 | |
Johannes Schindelin | 29a0334 | 2009-01-27 23:34:29 +0100 | [diff] [blame] | 8 | This test runs git rebase with -p and tries to squash a commit from after |
| 9 | a merge to before the merge. |
Stephen Haberman | 42f939e | 2008-10-15 02:44:34 -0500 | [diff] [blame] | 10 | ' |
| 11 | . ./test-lib.sh |
| 12 | |
Johannes Schindelin | 11aad46 | 2018-10-31 13:02:02 -0700 | [diff] [blame] | 13 | if ! test_have_prereq REBASE_P; then |
| 14 | skip_all='skipping git rebase -p tests, as asked for' |
| 15 | test_done |
| 16 | fi |
| 17 | |
Jeff King | eaf0551 | 2009-08-09 04:37:52 -0400 | [diff] [blame] | 18 | . "$TEST_DIRECTORY"/lib-rebase.sh |
Stephen Haberman | 42f939e | 2008-10-15 02:44:34 -0500 | [diff] [blame] | 19 | |
Johannes Schindelin | 29a0334 | 2009-01-27 23:34:29 +0100 | [diff] [blame] | 20 | set_fake_editor |
Stephen Haberman | 42f939e | 2008-10-15 02:44:34 -0500 | [diff] [blame] | 21 | |
| 22 | # set up two branches like this: |
| 23 | # |
| 24 | # A1 - B1 - D1 - E1 - F1 |
| 25 | # \ / |
| 26 | # -- C1 -- |
| 27 | |
| 28 | test_expect_success 'setup' ' |
Johannes Schindelin | 37e5c8f | 2009-01-27 23:35:05 +0100 | [diff] [blame] | 29 | test_commit A1 && |
| 30 | test_commit B1 && |
| 31 | test_commit C1 && |
| 32 | git reset --hard B1 && |
| 33 | test_commit D1 && |
| 34 | test_merge E1 C1 && |
| 35 | test_commit F1 |
Stephen Haberman | 42f939e | 2008-10-15 02:44:34 -0500 | [diff] [blame] | 36 | ' |
| 37 | |
| 38 | # Should result in: |
| 39 | # |
| 40 | # A1 - B1 - D2 - E2 |
| 41 | # \ / |
| 42 | # -- C1 -- |
| 43 | # |
Stephen Haberman | 80fe82e | 2008-10-15 02:44:40 -0500 | [diff] [blame] | 44 | test_expect_success 'squash F1 into D1' ' |
Andrew Wong | 12bf828 | 2011-06-18 18:12:01 -0400 | [diff] [blame] | 45 | FAKE_LINES="1 squash 4 2 3" git rebase -i -p B1 && |
Johannes Schindelin | 37e5c8f | 2009-01-27 23:35:05 +0100 | [diff] [blame] | 46 | test "$(git rev-parse HEAD^2)" = "$(git rev-parse C1)" && |
Stephen Haberman | 42f939e | 2008-10-15 02:44:34 -0500 | [diff] [blame] | 47 | test "$(git rev-parse HEAD~2)" = "$(git rev-parse B1)" && |
| 48 | git tag E2 |
| 49 | ' |
| 50 | |
| 51 | # Start with: |
| 52 | # |
| 53 | # A1 - B1 - D2 - E2 |
| 54 | # \ |
| 55 | # G1 ---- L1 ---- M1 |
| 56 | # \ / |
| 57 | # H1 -- J1 -- K1 |
| 58 | # \ / |
| 59 | # -- I1 -- |
| 60 | # |
| 61 | # And rebase G1..M1 onto E2 |
| 62 | |
Stephen Haberman | 80fe82e | 2008-10-15 02:44:40 -0500 | [diff] [blame] | 63 | test_expect_success 'rebase two levels of merge' ' |
Johannes Sixt | 9ef5b2b | 2012-05-18 15:48:53 +0200 | [diff] [blame] | 64 | git checkout A1 && |
Johannes Schindelin | 37e5c8f | 2009-01-27 23:35:05 +0100 | [diff] [blame] | 65 | test_commit G1 && |
| 66 | test_commit H1 && |
| 67 | test_commit I1 && |
| 68 | git checkout -b branch3 H1 && |
| 69 | test_commit J1 && |
| 70 | test_merge K1 I1 && |
| 71 | git checkout -b branch2 G1 && |
| 72 | test_commit L1 && |
| 73 | test_merge M1 K1 && |
Stephen Haberman | 42f939e | 2008-10-15 02:44:34 -0500 | [diff] [blame] | 74 | GIT_EDITOR=: git rebase -i -p E2 && |
| 75 | test "$(git rev-parse HEAD~3)" = "$(git rev-parse E2)" && |
| 76 | test "$(git rev-parse HEAD~2)" = "$(git rev-parse HEAD^2^2~2)" && |
| 77 | test "$(git rev-parse HEAD^2^1^1)" = "$(git rev-parse HEAD^2^2^1)" |
| 78 | ' |
| 79 | |
| 80 | test_done |