]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3412-rebase-root.sh
The third batch
[thirdparty/git.git] / t / t3412-rebase-root.sh
1 #!/bin/sh
2
3 test_description='git rebase --root
4
5 Tests if git rebase --root --onto <newparent> can rebase the root commit.
6 '
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
10 TEST_PASSES_SANITIZE_LEAK=true
11 . ./test-lib.sh
12
13 log_with_names () {
14 git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
15 git name-rev --annotate-stdin --name-only --refs=refs/heads/$1
16 }
17
18
19 test_expect_success 'prepare repository' '
20 test_commit 1 A &&
21 test_commit 2 A &&
22 git symbolic-ref HEAD refs/heads/other &&
23 rm .git/index &&
24 test_commit 3 B &&
25 test_commit 1b A 1 &&
26 test_commit 4 B
27 '
28
29 test_expect_success 'rebase --root fails with too many args' '
30 git checkout -B fail other &&
31 test_must_fail git rebase --onto main --root fail fail
32 '
33
34 test_expect_success 'setup pre-rebase hook' '
35 test_hook --setup pre-rebase <<-\EOF
36 echo "$1,$2" >.git/PRE-REBASE-INPUT
37 EOF
38 '
39 cat > expect <<EOF
40 4
41 3
42 2
43 1
44 EOF
45
46 test_expect_success 'rebase --root --onto <newbase>' '
47 git checkout -b work other &&
48 git rebase --root --onto main &&
49 git log --pretty=tformat:"%s" > rebased &&
50 test_cmp expect rebased
51 '
52
53 test_expect_success 'pre-rebase got correct input (1)' '
54 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
55 '
56
57 test_expect_success 'rebase --root --onto <newbase> <branch>' '
58 git branch work2 other &&
59 git rebase --root --onto main work2 &&
60 git log --pretty=tformat:"%s" > rebased2 &&
61 test_cmp expect rebased2
62 '
63
64 test_expect_success 'pre-rebase got correct input (2)' '
65 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
66 '
67
68 test_expect_success 'rebase -i --root --onto <newbase>' '
69 git checkout -b work3 other &&
70 git rebase -i --root --onto main &&
71 git log --pretty=tformat:"%s" > rebased3 &&
72 test_cmp expect rebased3
73 '
74
75 test_expect_success 'pre-rebase got correct input (3)' '
76 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
77 '
78
79 test_expect_success 'rebase -i --root --onto <newbase> <branch>' '
80 git branch work4 other &&
81 git rebase -i --root --onto main work4 &&
82 git log --pretty=tformat:"%s" > rebased4 &&
83 test_cmp expect rebased4
84 '
85
86 test_expect_success 'pre-rebase got correct input (4)' '
87 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
88 '
89
90 test_expect_success 'set up merge history' '
91 git checkout other^ &&
92 git checkout -b side &&
93 test_commit 5 C &&
94 git checkout other &&
95 git merge side
96 '
97
98 cat > expect-side <<'EOF'
99 commit work6 work6~1 work6^2
100 Merge branch 'side' into other
101 commit work6^2 work6~2
102 5
103 commit work6~1 work6~2
104 4
105 commit work6~2 work6~3
106 3
107 commit work6~3 work6~4
108 2
109 commit work6~4
110 1
111 EOF
112
113 test_expect_success 'set up second root and merge' '
114 git symbolic-ref HEAD refs/heads/third &&
115 rm .git/index &&
116 rm A B C &&
117 test_commit 6 D &&
118 git checkout other &&
119 git merge --allow-unrelated-histories third
120 '
121
122 cat > expect-third <<'EOF'
123 commit work7 work7~1 work7^2
124 Merge branch 'third' into other
125 commit work7^2 work7~4
126 6
127 commit work7~1 work7~2 work7~1^2
128 Merge branch 'side' into other
129 commit work7~1^2 work7~3
130 5
131 commit work7~2 work7~3
132 4
133 commit work7~3 work7~4
134 3
135 commit work7~4 work7~5
136 2
137 commit work7~5
138 1
139 EOF
140
141 test_expect_success 'setup pre-rebase hook that fails' '
142 test_hook --setup --clobber pre-rebase <<-\EOF
143 false
144 EOF
145 '
146
147 test_expect_success 'pre-rebase hook stops rebase' '
148 git checkout -b stops1 other &&
149 test_must_fail git rebase --root --onto main &&
150 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 &&
151 test 0 = $(git rev-list other...stops1 | wc -l)
152 '
153
154 test_expect_success 'pre-rebase hook stops rebase -i' '
155 git checkout -b stops2 other &&
156 test_must_fail git rebase --root --onto main &&
157 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 &&
158 test 0 = $(git rev-list other...stops2 | wc -l)
159 '
160
161 test_expect_success 'remove pre-rebase hook' '
162 rm -f .git/hooks/pre-rebase
163 '
164
165 test_expect_success 'set up a conflict' '
166 git checkout main &&
167 echo conflict > B &&
168 git add B &&
169 git commit -m conflict
170 '
171
172 test_expect_success 'rebase --root with conflict (first part)' '
173 git checkout -b conflict1 other &&
174 test_must_fail git rebase --root --onto main &&
175 git ls-files -u | grep "B$"
176 '
177
178 test_expect_success 'fix the conflict' '
179 echo 3 > B &&
180 git add B
181 '
182
183 cat > expect-conflict <<EOF
184 6
185 5
186 4
187 3
188 conflict
189 2
190 1
191 EOF
192
193 test_expect_success 'rebase --root with conflict (second part)' '
194 git rebase --continue &&
195 git log --pretty=tformat:"%s" > conflict1 &&
196 test_cmp expect-conflict conflict1
197 '
198
199 test_expect_success 'rebase -i --root with conflict (first part)' '
200 git checkout -b conflict2 other &&
201 test_must_fail git rebase -i --root --onto main &&
202 git ls-files -u | grep "B$"
203 '
204
205 test_expect_success 'fix the conflict' '
206 echo 3 > B &&
207 git add B
208 '
209
210 test_expect_success 'rebase -i --root with conflict (second part)' '
211 git rebase --continue &&
212 git log --pretty=tformat:"%s" > conflict2 &&
213 test_cmp expect-conflict conflict2
214 '
215
216 cat >expect-conflict-p <<\EOF
217 commit conflict3 conflict3~1 conflict3^2
218 Merge branch 'third' into other
219 commit conflict3^2 conflict3~4
220 6
221 commit conflict3~1 conflict3~2 conflict3~1^2
222 Merge branch 'side' into other
223 commit conflict3~1^2 conflict3~3
224 5
225 commit conflict3~2 conflict3~3
226 4
227 commit conflict3~3 conflict3~4
228 3
229 commit conflict3~4 conflict3~5
230 conflict
231 commit conflict3~5 conflict3~6
232 2
233 commit conflict3~6
234 1
235 EOF
236
237 test_expect_success 'fix the conflict' '
238 echo 3 > B &&
239 git add B
240 '
241
242 test_done