Greg Price | 1830d9c | 2009-07-22 12:38:58 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2009 Greg Price |
| 4 | # |
| 5 | |
| 6 | test_description='git rebase -p should respect --onto |
| 7 | |
| 8 | In a rebase with --onto, we should rewrite all the commits that |
| 9 | aren'"'"'t on top of $ONTO, even if they are on top of $UPSTREAM. |
| 10 | ' |
| 11 | . ./test-lib.sh |
| 12 | |
Jeff King | eaf0551 | 2009-08-09 04:37:52 -0400 | [diff] [blame] | 13 | . "$TEST_DIRECTORY"/lib-rebase.sh |
Greg Price | 1830d9c | 2009-07-22 12:38:58 -0400 | [diff] [blame] | 14 | |
| 15 | # Set up branches like this: |
| 16 | # A1---B1---E1---F1---G1 |
| 17 | # \ \ / |
| 18 | # \ \--C1---D1--/ |
| 19 | # H1 |
| 20 | |
| 21 | test_expect_success 'setup' ' |
| 22 | test_commit A1 && |
| 23 | test_commit B1 && |
| 24 | test_commit C1 && |
| 25 | test_commit D1 && |
| 26 | git reset --hard B1 && |
| 27 | test_commit E1 && |
| 28 | test_commit F1 && |
| 29 | test_merge G1 D1 && |
| 30 | git reset --hard A1 && |
| 31 | test_commit H1 |
| 32 | ' |
| 33 | |
| 34 | # Now rebase merge G1 from both branches' base B1, both should move: |
| 35 | # A1---B1---E1---F1---G1 |
| 36 | # \ \ / |
| 37 | # \ \--C1---D1--/ |
| 38 | # \ |
| 39 | # H1---E2---F2---G2 |
| 40 | # \ / |
| 41 | # \--C2---D2--/ |
| 42 | |
| 43 | test_expect_success 'rebase from B1 onto H1' ' |
| 44 | git checkout G1 && |
| 45 | git rebase -p --onto H1 B1 && |
| 46 | test "$(git rev-parse HEAD^1^1^1)" = "$(git rev-parse H1)" && |
| 47 | test "$(git rev-parse HEAD^2^1^1)" = "$(git rev-parse H1)" |
| 48 | ' |
| 49 | |
| 50 | # On the other hand if rebase from E1 which is within one branch, |
| 51 | # then the other branch stays: |
| 52 | # A1---B1---E1---F1---G1 |
| 53 | # \ \ / |
| 54 | # \ \--C1---D1--/ |
| 55 | # \ \ |
| 56 | # H1-----F3-----G3 |
| 57 | |
| 58 | test_expect_success 'rebase from E1 onto H1' ' |
| 59 | git checkout G1 && |
| 60 | git rebase -p --onto H1 E1 && |
| 61 | test "$(git rev-parse HEAD^1^1)" = "$(git rev-parse H1)" && |
| 62 | test "$(git rev-parse HEAD^2)" = "$(git rev-parse D1)" |
| 63 | ' |
| 64 | |
| 65 | # And the same if we rebase from a commit in the second-parent branch. |
| 66 | # A1---B1---E1---F1----G1 |
| 67 | # \ \ \ / |
| 68 | # \ \--C1---D1-\-/ |
| 69 | # \ \ |
| 70 | # H1------D3------G4 |
| 71 | |
| 72 | test_expect_success 'rebase from C1 onto H1' ' |
| 73 | git checkout G1 && |
| 74 | git rev-list --first-parent --pretty=oneline C1..G1 && |
| 75 | git rebase -p --onto H1 C1 && |
| 76 | test "$(git rev-parse HEAD^2^1)" = "$(git rev-parse H1)" && |
| 77 | test "$(git rev-parse HEAD^1)" = "$(git rev-parse F1)" |
| 78 | ' |
| 79 | |
| 80 | test_done |