Merge branch 'tb/commit-graph-genv2-upgrade-fix' into maint
[git/debian.git] / t / t3416-rebase-onto-threedots.sh
blob3e04802cb003b027c0d70319465af4363877de06
1 #!/bin/sh
3 test_description='git rebase --onto A...B'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY/lib-rebase.sh"
11 # Rebase only the tip commit of "topic" on merge base between "main"
12 # and "topic". Cannot do this for "side" with "main" because there
13 # is no single merge base.
16 # F---G topic G'
17 # / /
18 # A---B---C---D---E main --> A---B---C---D---E
19 # \ \ /
20 # \ x
21 # \ / \
22 # H---I---J---K side
24 test_expect_success setup '
25 test_commit A &&
26 test_commit B &&
27 git branch side &&
28 test_commit C &&
29 git branch topic &&
30 git checkout side &&
31 test_commit H &&
32 git checkout main &&
33 test_tick &&
34 git merge H &&
35 git tag D &&
36 test_commit E &&
37 git checkout topic &&
38 test_commit F &&
39 test_commit G &&
40 git checkout side &&
41 test_tick &&
42 git merge C &&
43 git tag I &&
44 test_commit J &&
45 test_commit K
48 test_expect_success 'rebase --onto main...topic' '
49 git reset --hard &&
50 git checkout topic &&
51 git reset --hard G &&
53 git rebase --onto main...topic F &&
54 git rev-parse HEAD^1 >actual &&
55 git rev-parse C^0 >expect &&
56 test_cmp expect actual
59 test_expect_success 'rebase --onto main...' '
60 git reset --hard &&
61 git checkout topic &&
62 git reset --hard G &&
64 git rebase --onto main... F &&
65 git rev-parse HEAD^1 >actual &&
66 git rev-parse C^0 >expect &&
67 test_cmp expect actual
70 test_expect_success 'rebase --onto main...side' '
71 git reset --hard &&
72 git checkout side &&
73 git reset --hard K &&
75 test_must_fail git rebase --onto main...side J
78 test_expect_success 'rebase -i --onto main...topic' '
79 git reset --hard &&
80 git checkout topic &&
81 git reset --hard G &&
82 set_fake_editor &&
83 EXPECT_COUNT=1 git rebase -i --onto main...topic F &&
84 git rev-parse HEAD^1 >actual &&
85 git rev-parse C^0 >expect &&
86 test_cmp expect actual
89 test_expect_success 'rebase -i --onto main...' '
90 git reset --hard &&
91 git checkout topic &&
92 git reset --hard G &&
93 set_fake_editor &&
94 EXPECT_COUNT=1 git rebase -i --onto main... F &&
95 git rev-parse HEAD^1 >actual &&
96 git rev-parse C^0 >expect &&
97 test_cmp expect actual
100 test_expect_success 'rebase -i --onto main...side' '
101 git reset --hard &&
102 git checkout side &&
103 git reset --hard K &&
105 set_fake_editor &&
106 test_must_fail git rebase -i --onto main...side J
109 test_expect_success 'rebase --keep-base --onto incompatible' '
110 test_must_fail git rebase --keep-base --onto main...
113 test_expect_success 'rebase --keep-base --root incompatible' '
114 test_must_fail git rebase --keep-base --root
117 test_expect_success 'rebase --keep-base main from topic' '
118 git reset --hard &&
119 git checkout topic &&
120 git reset --hard G &&
122 git rebase --keep-base main &&
123 git rev-parse C >base.expect &&
124 git merge-base main HEAD >base.actual &&
125 test_cmp base.expect base.actual &&
127 git rev-parse HEAD~2 >actual &&
128 git rev-parse C^0 >expect &&
129 test_cmp expect actual
132 test_expect_success 'rebase --keep-base main topic from main' '
133 git checkout main &&
134 git branch -f topic G &&
136 git rebase --keep-base main topic &&
137 git rev-parse C >base.expect &&
138 git merge-base main HEAD >base.actual &&
139 test_cmp base.expect base.actual &&
141 git rev-parse HEAD~2 >actual &&
142 git rev-parse C^0 >expect &&
143 test_cmp expect actual
146 test_expect_success 'rebase --keep-base main from side' '
147 git reset --hard &&
148 git checkout side &&
149 git reset --hard K &&
151 test_must_fail git rebase --keep-base main
154 test_expect_success 'rebase -i --keep-base main from topic' '
155 git reset --hard &&
156 git checkout topic &&
157 git reset --hard G &&
159 set_fake_editor &&
160 EXPECT_COUNT=2 git rebase -i --keep-base main &&
161 git rev-parse C >base.expect &&
162 git merge-base main HEAD >base.actual &&
163 test_cmp base.expect base.actual &&
165 git rev-parse HEAD~2 >actual &&
166 git rev-parse C^0 >expect &&
167 test_cmp expect actual
170 test_expect_success 'rebase -i --keep-base main topic from main' '
171 git checkout main &&
172 git branch -f topic G &&
174 set_fake_editor &&
175 EXPECT_COUNT=2 git rebase -i --keep-base main topic &&
176 git rev-parse C >base.expect &&
177 git merge-base main HEAD >base.actual &&
178 test_cmp base.expect base.actual &&
180 git rev-parse HEAD~2 >actual &&
181 git rev-parse C^0 >expect &&
182 test_cmp expect actual
185 test_expect_success 'rebase -i --keep-base main from side' '
186 git reset --hard &&
187 git checkout side &&
188 git reset --hard K &&
190 set_fake_editor &&
191 test_must_fail git rebase -i --keep-base main
194 test_done