]>
Commit | Line | Data |
---|---|---|
190f5323 TR |
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 | ' | |
d1c02d93 | 7 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
8 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
9 | ||
9ff2f060 | 10 | TEST_PASSES_SANITIZE_LEAK=true |
190f5323 | 11 | . ./test-lib.sh |
21828964 | 12 | |
2ea3c171 TR |
13 | log_with_names () { |
14 | git rev-list --topo-order --parents --pretty="tformat:%s" HEAD | | |
34ae3b70 | 15 | git name-rev --annotate-stdin --name-only --refs=refs/heads/$1 |
2ea3c171 TR |
16 | } |
17 | ||
18 | ||
190f5323 | 19 | test_expect_success 'prepare repository' ' |
f7951e1d JS |
20 | test_commit 1 A && |
21 | test_commit 2 A && | |
190f5323 TR |
22 | git symbolic-ref HEAD refs/heads/other && |
23 | rm .git/index && | |
f7951e1d JS |
24 | test_commit 3 B && |
25 | test_commit 1b A 1 && | |
26 | test_commit 4 B | |
190f5323 TR |
27 | ' |
28 | ||
f2b6a199 MZ |
29 | test_expect_success 'rebase --root fails with too many args' ' |
30 | git checkout -B fail other && | |
d1c02d93 | 31 | test_must_fail git rebase --onto main --root fail fail |
f2b6a199 MZ |
32 | ' |
33 | ||
190f5323 | 34 | test_expect_success 'setup pre-rebase hook' ' |
c36c6285 ÆAB |
35 | test_hook --setup pre-rebase <<-\EOF |
36 | echo "$1,$2" >.git/PRE-REBASE-INPUT | |
37 | EOF | |
190f5323 TR |
38 | ' |
39 | cat > expect <<EOF | |
40 | 4 | |
41 | 3 | |
42 | 2 | |
43 | 1 | |
44 | EOF | |
45 | ||
46 | test_expect_success 'rebase --root --onto <newbase>' ' | |
f2b6a199 | 47 | git checkout -b work other && |
d1c02d93 | 48 | git rebase --root --onto main && |
190f5323 TR |
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 && | |
d1c02d93 | 59 | git rebase --root --onto main work2 && |
190f5323 TR |
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 | ||
d911d146 TR |
68 | test_expect_success 'rebase -i --root --onto <newbase>' ' |
69 | git checkout -b work3 other && | |
d1c02d93 | 70 | git rebase -i --root --onto main && |
d911d146 TR |
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 && | |
d1c02d93 | 81 | git rebase -i --root --onto main work4 && |
d911d146 TR |
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 | ||
d911d146 TR |
90 | test_expect_success 'set up merge history' ' |
91 | git checkout other^ && | |
92 | git checkout -b side && | |
f7951e1d | 93 | test_commit 5 C && |
d911d146 TR |
94 | git checkout other && |
95 | git merge side | |
96 | ' | |
97 | ||
2ea3c171 TR |
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 | |
d911d146 TR |
111 | EOF |
112 | ||
d911d146 TR |
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 && | |
f7951e1d | 117 | test_commit 6 D && |
d911d146 | 118 | git checkout other && |
e379fdf3 | 119 | git merge --allow-unrelated-histories third |
d911d146 TR |
120 | ' |
121 | ||
2ea3c171 TR |
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 | |
d911d146 TR |
139 | EOF |
140 | ||
190f5323 | 141 | test_expect_success 'setup pre-rebase hook that fails' ' |
c36c6285 ÆAB |
142 | test_hook --setup --clobber pre-rebase <<-\EOF |
143 | false | |
144 | EOF | |
190f5323 TR |
145 | ' |
146 | ||
147 | test_expect_success 'pre-rebase hook stops rebase' ' | |
148 | git checkout -b stops1 other && | |
d1c02d93 | 149 | test_must_fail git rebase --root --onto main && |
a48fcd83 | 150 | test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 && |
190f5323 TR |
151 | test 0 = $(git rev-list other...stops1 | wc -l) |
152 | ' | |
153 | ||
d911d146 TR |
154 | test_expect_success 'pre-rebase hook stops rebase -i' ' |
155 | git checkout -b stops2 other && | |
d1c02d93 | 156 | test_must_fail git rebase --root --onto main && |
a48fcd83 | 157 | test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 && |
d911d146 TR |
158 | test 0 = $(git rev-list other...stops2 | wc -l) |
159 | ' | |
160 | ||
a6c7a276 JH |
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' ' | |
d1c02d93 | 166 | git checkout main && |
a6c7a276 JH |
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 && | |
d1c02d93 | 174 | test_must_fail git rebase --root --onto main && |
a6c7a276 JH |
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 && | |
d1c02d93 | 201 | test_must_fail git rebase -i --root --onto main && |
a6c7a276 JH |
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 | ||
a6c7a276 JH |
237 | test_expect_success 'fix the conflict' ' |
238 | echo 3 > B && | |
239 | git add B | |
240 | ' | |
241 | ||
190f5323 | 242 | test_done |