Merge branch 'ar/submodule-add-config'
[git/debian.git] / t / t3414-rebase-preserve-onto.sh
blob72e04b5386a825927f0c9e48d2353fc8c5cf8581
1 #!/bin/sh
3 # Copyright (c) 2009 Greg Price
6 test_description='git rebase -p should respect --onto
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.
11 . ./test-lib.sh
13 if ! test_have_prereq REBASE_P; then
14 skip_all='skipping git rebase -p tests, as asked for'
15 test_done
18 . "$TEST_DIRECTORY"/lib-rebase.sh
20 # Set up branches like this:
21 # A1---B1---E1---F1---G1
22 # \ \ /
23 # \ \--C1---D1--/
24 # H1
26 test_expect_success 'setup' '
27 test_commit A1 &&
28 test_commit B1 &&
29 test_commit C1 &&
30 test_commit D1 &&
31 git reset --hard B1 &&
32 test_commit E1 &&
33 test_commit F1 &&
34 test_merge G1 D1 &&
35 git reset --hard A1 &&
36 test_commit H1
39 # Now rebase merge G1 from both branches' base B1, both should move:
40 # A1---B1---E1---F1---G1
41 # \ \ /
42 # \ \--C1---D1--/
43 # \
44 # H1---E2---F2---G2
45 # \ /
46 # \--C2---D2--/
48 test_expect_success 'rebase from B1 onto H1' '
49 git checkout G1 &&
50 git rebase -p --onto H1 B1 &&
51 test "$(git rev-parse HEAD^1^1^1)" = "$(git rev-parse H1)" &&
52 test "$(git rev-parse HEAD^2^1^1)" = "$(git rev-parse H1)"
55 # On the other hand if rebase from E1 which is within one branch,
56 # then the other branch stays:
57 # A1---B1---E1---F1---G1
58 # \ \ /
59 # \ \--C1---D1--/
60 # \ \
61 # H1-----F3-----G3
63 test_expect_success 'rebase from E1 onto H1' '
64 git checkout G1 &&
65 git rebase -p --onto H1 E1 &&
66 test "$(git rev-parse HEAD^1^1)" = "$(git rev-parse H1)" &&
67 test "$(git rev-parse HEAD^2)" = "$(git rev-parse D1)"
70 # And the same if we rebase from a commit in the second-parent branch.
71 # A1---B1---E1---F1----G1
72 # \ \ \ /
73 # \ \--C1---D1-\-/
74 # \ \
75 # H1------D3------G4
77 test_expect_success 'rebase from C1 onto H1' '
78 git checkout G1 &&
79 git rev-list --first-parent --pretty=oneline C1..G1 &&
80 git rebase -p --onto H1 C1 &&
81 test "$(git rev-parse HEAD^2^1)" = "$(git rev-parse H1)" &&
82 test "$(git rev-parse HEAD^1)" = "$(git rev-parse F1)"
85 test_done