]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3416-rebase-onto-threedots.sh
t34*: adjust the references to the default branch name "main"
[thirdparty/git.git] / t / t3416-rebase-onto-threedots.sh
CommitLineData
9f21e97d
NS
1#!/bin/sh
2
3test_description='git rebase --onto A...B'
4
d1c02d93 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
9f21e97d
NS
8. ./test-lib.sh
9. "$TEST_DIRECTORY/lib-rebase.sh"
10
d1c02d93
JS
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
9f21e97d
NS
13# is no single merge base.
14#
15#
16# F---G topic G'
17# / /
d1c02d93 18# A---B---C---D---E main --> A---B---C---D---E
9f21e97d
NS
19# \ \ /
20# \ x
21# \ / \
22# H---I---J---K side
23
24test_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 &&
d1c02d93 32 git checkout main &&
9f21e97d
NS
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
46'
47
d1c02d93 48test_expect_success 'rebase --onto main...topic' '
9f21e97d
NS
49 git reset --hard &&
50 git checkout topic &&
51 git reset --hard G &&
52
d1c02d93 53 git rebase --onto main...topic F &&
9f21e97d
NS
54 git rev-parse HEAD^1 >actual &&
55 git rev-parse C^0 >expect &&
56 test_cmp expect actual
57'
58
d1c02d93 59test_expect_success 'rebase --onto main...' '
9f21e97d
NS
60 git reset --hard &&
61 git checkout topic &&
62 git reset --hard G &&
63
d1c02d93 64 git rebase --onto main... F &&
9f21e97d
NS
65 git rev-parse HEAD^1 >actual &&
66 git rev-parse C^0 >expect &&
67 test_cmp expect actual
68'
69
d1c02d93 70test_expect_success 'rebase --onto main...side' '
9f21e97d
NS
71 git reset --hard &&
72 git checkout side &&
73 git reset --hard K &&
74
d1c02d93 75 test_must_fail git rebase --onto main...side J
9f21e97d
NS
76'
77
d1c02d93 78test_expect_success 'rebase -i --onto main...topic' '
230a4566
NS
79 git reset --hard &&
80 git checkout topic &&
81 git reset --hard G &&
82 set_fake_editor &&
d1c02d93 83 EXPECT_COUNT=1 git rebase -i --onto main...topic F &&
230a4566
NS
84 git rev-parse HEAD^1 >actual &&
85 git rev-parse C^0 >expect &&
86 test_cmp expect actual
87'
88
d1c02d93 89test_expect_success 'rebase -i --onto main...' '
230a4566
NS
90 git reset --hard &&
91 git checkout topic &&
92 git reset --hard G &&
93 set_fake_editor &&
d1c02d93 94 EXPECT_COUNT=1 git rebase -i --onto main... F &&
230a4566
NS
95 git rev-parse HEAD^1 >actual &&
96 git rev-parse C^0 >expect &&
97 test_cmp expect actual
98'
99
d1c02d93 100test_expect_success 'rebase -i --onto main...side' '
230a4566
NS
101 git reset --hard &&
102 git checkout side &&
103 git reset --hard K &&
104
414d924b 105 set_fake_editor &&
d1c02d93 106 test_must_fail git rebase -i --onto main...side J
230a4566
NS
107'
108
414d924b 109test_expect_success 'rebase --keep-base --onto incompatible' '
d1c02d93 110 test_must_fail git rebase --keep-base --onto main...
414d924b
DL
111'
112
113test_expect_success 'rebase --keep-base --root incompatible' '
114 test_must_fail git rebase --keep-base --root
115'
116
d1c02d93 117test_expect_success 'rebase --keep-base main from topic' '
414d924b
DL
118 git reset --hard &&
119 git checkout topic &&
120 git reset --hard G &&
121
d1c02d93 122 git rebase --keep-base main &&
414d924b 123 git rev-parse C >base.expect &&
d1c02d93 124 git merge-base main HEAD >base.actual &&
414d924b
DL
125 test_cmp base.expect base.actual &&
126
127 git rev-parse HEAD~2 >actual &&
128 git rev-parse C^0 >expect &&
129 test_cmp expect actual
130'
131
d1c02d93 132test_expect_success 'rebase --keep-base main from side' '
414d924b
DL
133 git reset --hard &&
134 git checkout side &&
135 git reset --hard K &&
136
d1c02d93 137 test_must_fail git rebase --keep-base main
414d924b
DL
138'
139
d1c02d93 140test_expect_success 'rebase -i --keep-base main from topic' '
414d924b
DL
141 git reset --hard &&
142 git checkout topic &&
143 git reset --hard G &&
144
145 set_fake_editor &&
d1c02d93 146 EXPECT_COUNT=2 git rebase -i --keep-base main &&
414d924b 147 git rev-parse C >base.expect &&
d1c02d93 148 git merge-base main HEAD >base.actual &&
414d924b
DL
149 test_cmp base.expect base.actual &&
150
151 git rev-parse HEAD~2 >actual &&
152 git rev-parse C^0 >expect &&
153 test_cmp expect actual
154'
155
d1c02d93 156test_expect_success 'rebase -i --keep-base main from side' '
414d924b
DL
157 git reset --hard &&
158 git checkout side &&
159 git reset --hard K &&
160
161 set_fake_editor &&
d1c02d93 162 test_must_fail git rebase -i --keep-base main
414d924b
DL
163'
164
9f21e97d 165test_done