README-TESTLIB-TG: fix typo
[topgit/pro.git] / t / t8100-import.sh
blob98cf0467910694ab8e9546bf40882b8573c12179
1 #!/bin/sh
3 test_description='tg import tests'
5 TEST_NO_CREATE_REPO=1
7 . ./test-lib.sh
9 test_plan 11
11 test_expect_success 'default branch import' '
12 test_create_repo r1 && cd r1 &&
13 test_commit --notick start^here &&
14 git branch base &&
15 test_commit --notick one^ &&
16 test_commit --notick two^ &&
17 test_commit --notick three^ &&
18 git checkout base &&
19 tg import base..master &&
20 printf "%s" "\
21 t/one [PATCH] one^
22 t/three [PATCH] three^
23 t/two [PATCH] two^
24 " > ../expected &&
25 tg summary -v -l | tr -s "\\t" " " > ../actual &&
26 test_diff ../expected ../actual &&
27 printf "%s" "\
28 t/three
29 t/two
30 t/one
31 base
32 " > ../expected &&
33 tg summary --rdeps --heads > ../actual &&
34 test_diff ../expected ../actual &&
35 test_cmp_rev base "$(tg base t/one)" &&
36 git diff --exit-code master t/three -- :/ :\!/.topdeps :\!/.topmsg
39 test_expect_success 'specified branch import' '
40 test_create_repo r2 && cd r2 &&
41 test_commit --notick start^here &&
42 git branch base &&
43 test_commit --notick one^ &&
44 test_commit --notick two^ &&
45 test_commit --notick three^ &&
46 git checkout --orphan alt &&
47 git read-tree --empty &&
48 git commit --allow-empty -m "empty" &&
49 git clean -d -f -x &&
50 git checkout base &&
51 tg import -d alt base..master &&
52 printf "%s" "\
53 t/one [PATCH] one^
54 t/three [PATCH] three^
55 t/two [PATCH] two^
56 " > ../expected &&
57 tg summary -v -l | tr -s "\\t" " " > ../actual &&
58 test_diff ../expected ../actual &&
59 printf "%s" "\
60 t/three
61 t/two
62 t/one
63 alt
64 " > ../expected &&
65 tg summary --rdeps --heads > ../actual &&
66 test_diff ../expected ../actual &&
67 test_cmp_rev alt "$(tg base t/one)" &&
68 printf "%s" "\
69 diff --git a/start^here.t b/start^here.t
70 deleted file mode 100644
71 index 1a2b97e..0000000
72 --- a/start^here.t
73 +++ /dev/null
74 @@ -1 +0,0 @@
75 -start^here
76 " > ../expected &&
77 git diff master t/three -- :/ :\!/.topdeps :\!/.topmsg > ../actual &&
78 test_diff ../expected ../actual
81 test_expect_success 'specified branch import HEAD relative range' '
82 test_create_repo r3 && cd r3 &&
83 test_commit --notick start^here &&
84 git branch base &&
85 test_commit --notick one^ &&
86 test_commit --notick two^ &&
87 test_commit --notick three^ &&
88 git checkout --orphan alt &&
89 git read-tree --empty &&
90 git commit --allow-empty -m "empty" &&
91 git clean -d -f -x &&
92 git checkout master &&
93 tg import -d alt HEAD~3..HEAD &&
94 printf "%s" "\
95 t/one [PATCH] one^
96 t/three [PATCH] three^
97 t/two [PATCH] two^
98 " > ../expected &&
99 tg summary -v -l | tr -s "\\t" " " > ../actual &&
100 test_diff ../expected ../actual &&
101 printf "%s" "\
102 t/three
103 t/two
104 t/one
106 " > ../expected &&
107 tg summary --rdeps --heads > ../actual &&
108 test_diff ../expected ../actual &&
109 test_cmp_rev alt "$(tg base t/one)" &&
110 printf "%s" "\
111 diff --git a/start^here.t b/start^here.t
112 deleted file mode 100644
113 index 1a2b97e..0000000
114 --- a/start^here.t
115 +++ /dev/null
116 @@ -1 +0,0 @@
117 -start^here
118 " > ../expected &&
119 git diff master t/three -- :/ :\!/.topdeps :\!/.topmsg > ../actual &&
120 test_diff ../expected ../actual
122 test_expect_success 'specified branch import foo..HEAD implied relative range' '
123 test_create_repo r4 && cd r4 &&
124 test_commit --notick start^here &&
125 git branch base &&
126 test_commit --notick one^ &&
127 test_commit --notick two^ &&
128 test_commit --notick three^ &&
129 git checkout --orphan alt &&
130 git read-tree --empty &&
131 git commit --allow-empty -m "empty" &&
132 git clean -d -f -x &&
133 git checkout master &&
134 tg import -d alt HEAD~3.. &&
135 printf "%s" "\
136 t/one [PATCH] one^
137 t/three [PATCH] three^
138 t/two [PATCH] two^
139 " > ../expected &&
140 tg summary -v -l | tr -s "\\t" " " > ../actual &&
141 test_diff ../expected ../actual &&
142 printf "%s" "\
143 t/three
144 t/two
145 t/one
147 " > ../expected &&
148 tg summary --rdeps --heads > ../actual &&
149 test_diff ../expected ../actual &&
150 test_cmp_rev alt "$(tg base t/one)" &&
151 printf "%s" "\
152 diff --git a/start^here.t b/start^here.t
153 deleted file mode 100644
154 index 1a2b97e..0000000
155 --- a/start^here.t
156 +++ /dev/null
157 @@ -1 +0,0 @@
158 -start^here
159 " > ../expected &&
160 git diff master t/three -- :/ :\!/.topdeps :\!/.topmsg > ../actual &&
161 test_diff ../expected ../actual
164 test_expect_success 'specified branch import HEAD..foo implied relative range' '
165 test_create_repo r5 && cd r5 &&
166 test_commit --notick start^here &&
167 git branch base &&
168 test_commit --notick one^ &&
169 test_commit --notick two^ &&
170 test_commit --notick three^ &&
171 git checkout --orphan alt &&
172 git read-tree --empty &&
173 git commit --allow-empty -m "empty" &&
174 git clean -d -f -x &&
175 git checkout base &&
176 tg import -d alt ..master &&
177 printf "%s" "\
178 t/one [PATCH] one^
179 t/three [PATCH] three^
180 t/two [PATCH] two^
181 " > ../expected &&
182 tg summary -v -l | tr -s "\\t" " " > ../actual &&
183 test_diff ../expected ../actual &&
184 printf "%s" "\
185 t/three
186 t/two
187 t/one
189 " > ../expected &&
190 tg summary --rdeps --heads > ../actual &&
191 test_diff ../expected ../actual &&
192 test_cmp_rev alt "$(tg base t/one)" &&
193 printf "%s" "\
194 diff --git a/start^here.t b/start^here.t
195 deleted file mode 100644
196 index 1a2b97e..0000000
197 --- a/start^here.t
198 +++ /dev/null
199 @@ -1 +0,0 @@
200 -start^here
201 " > ../expected &&
202 git diff master t/three -- :/ :\!/.topdeps :\!/.topmsg > ../actual &&
203 test_diff ../expected ../actual
206 test_expect_success 'specified branch import HEAD relative single commit range' '
207 test_create_repo r6 && cd r6 &&
208 test_commit --notick start^here &&
209 git branch base &&
210 test_commit --notick one^ &&
211 test_commit --notick two^ &&
212 git tag "test#2" &&
213 test_commit --notick three^ &&
214 git checkout --orphan alt &&
215 git read-tree --empty &&
216 git commit --allow-empty -m "empty" &&
217 git clean -d -f -x &&
218 git checkout master &&
219 tg import -d alt HEAD~^\! &&
220 printf "%s" "\
221 t/two [PATCH] two^
222 " > ../expected &&
223 tg summary -v -l | tr -s "\\t" " " > ../actual &&
224 test_diff ../expected ../actual &&
225 printf "%s" "\
226 t/two
228 " > ../expected &&
229 tg summary --rdeps --heads > ../actual &&
230 test_diff ../expected ../actual &&
231 test_cmp_rev alt "$(tg base t/two)" &&
232 printf "%s" "\
233 diff --git a/one^.t b/one^.t
234 deleted file mode 100644
235 index 9a60eae..0000000
236 --- a/one^.t
237 +++ /dev/null
238 @@ -1 +0,0 @@
239 -one^
240 diff --git a/start^here.t b/start^here.t
241 deleted file mode 100644
242 index 1a2b97e..0000000
243 --- a/start^here.t
244 +++ /dev/null
245 @@ -1 +0,0 @@
246 -start^here
247 " > ../expected &&
248 git diff "test#2" t/two -- :/ :\!/.topdeps :\!/.topmsg > ../actual &&
249 test_diff ../expected ../actual
252 test_expect_success 'default unrelated branch import' '
253 test_create_repo r7 && cd r7 &&
254 test_commit --notick start^here &&
255 git branch base &&
256 test_commit --notick one^ &&
257 test_commit --notick two^ &&
258 test_commit --notick three^ &&
259 git checkout --orphan alt &&
260 git read-tree --empty &&
261 git commit --allow-empty -m "empty" &&
262 git clean -d -f -x &&
263 tg import base..master &&
264 printf "%s" "\
265 t/one [PATCH] one^
266 t/three [PATCH] three^
267 t/two [PATCH] two^
268 " > ../expected &&
269 tg summary -v -l | tr -s "\\t" " " > ../actual &&
270 test_diff ../expected ../actual &&
271 printf "%s" "\
272 t/three
273 t/two
274 t/one
276 " > ../expected &&
277 tg summary --rdeps --heads > ../actual &&
278 test_diff ../expected ../actual &&
279 test_cmp_rev alt "$(tg base t/one)" &&
280 printf "%s" "\
281 diff --git a/start^here.t b/start^here.t
282 deleted file mode 100644
283 index 1a2b97e..0000000
284 --- a/start^here.t
285 +++ /dev/null
286 @@ -1 +0,0 @@
287 -start^here
288 " > ../expected &&
289 git diff master t/three -- :/ :\!/.topdeps :\!/.topmsg > ../actual &&
290 test_diff ../expected ../actual
293 test_expect_success 'HEAD unrelated branch import' '
294 test_create_repo r8 && cd r8 &&
295 test_commit --notick start^here &&
296 git branch base &&
297 test_commit --notick one^ &&
298 test_commit --notick two^ &&
299 test_commit --notick three^ &&
300 git checkout --orphan alt &&
301 git read-tree --empty &&
302 git commit --allow-empty -m "empty" &&
303 git clean -d -f -x &&
304 tg import -d HEAD base..master &&
305 printf "%s" "\
306 t/one [PATCH] one^
307 t/three [PATCH] three^
308 t/two [PATCH] two^
309 " > ../expected &&
310 tg summary -v -l | tr -s "\\t" " " > ../actual &&
311 test_diff ../expected ../actual &&
312 printf "%s" "\
313 t/three
314 t/two
315 t/one
317 " > ../expected &&
318 tg summary --rdeps --heads > ../actual &&
319 test_diff ../expected ../actual &&
320 test_cmp_rev alt "$(tg base t/one)" &&
321 printf "%s" "\
322 diff --git a/start^here.t b/start^here.t
323 deleted file mode 100644
324 index 1a2b97e..0000000
325 --- a/start^here.t
326 +++ /dev/null
327 @@ -1 +0,0 @@
328 -start^here
329 " > ../expected &&
330 git diff master t/three -- :/ :\!/.topdeps :\!/.topmsg > ../actual &&
331 test_diff ../expected ../actual
334 test_expect_success '@ unrelated branch import' '
335 test_create_repo r9 && cd r9 &&
336 test_commit --notick start^here &&
337 git branch base &&
338 test_commit --notick one^ &&
339 test_commit --notick two^ &&
340 test_commit --notick three^ &&
341 git checkout --orphan alt &&
342 git read-tree --empty &&
343 git commit --allow-empty -m "empty" &&
344 git clean -d -f -x &&
345 tg import -d HEAD base..master &&
346 printf "%s" "\
347 t/one [PATCH] one^
348 t/three [PATCH] three^
349 t/two [PATCH] two^
350 " > ../expected &&
351 tg summary -v -l | tr -s "\\t" " " > ../actual &&
352 test_diff ../expected ../actual &&
353 printf "%s" "\
354 t/three
355 t/two
356 t/one
358 " > ../expected &&
359 tg summary --rdeps --heads > ../actual &&
360 test_diff ../expected ../actual &&
361 test_cmp_rev alt "$(tg base t/one)" &&
362 printf "%s" "\
363 diff --git a/start^here.t b/start^here.t
364 deleted file mode 100644
365 index 1a2b97e..0000000
366 --- a/start^here.t
367 +++ /dev/null
368 @@ -1 +0,0 @@
369 -start^here
370 " > ../expected &&
371 git diff master t/three -- :/ :\!/.topdeps :\!/.topmsg > ../actual &&
372 test_diff ../expected ../actual
375 test_expect_success 'detached HEAD import fails' '
376 test_create_repo r10 && cd r10 &&
377 test_commit --notick start^here &&
378 git branch base &&
379 test_commit --notick one^ &&
380 test_commit --notick two^ &&
381 test_commit --notick three^ &&
382 git checkout --orphan alt &&
383 git read-tree --empty &&
384 git commit --allow-empty -m "empty" &&
385 git clean -d -f -x &&
386 git checkout --detach HEAD &&
387 test_must_fail tg import base..master &&
388 test_must_fail tg import -d HEAD base..master &&
389 test_must_fail tg import -d @ base..master
392 auh_opt=
393 ! vcmp "$git_version" '>=' "2.9" || auh_opt="--allow-unrelated-histories"
395 test_expect_success 'single commit range requires exactly one parent' '
396 test_create_repo r11 && cd r11 &&
397 test_commit --notick start^here &&
398 git branch base &&
399 git checkout --orphan alt &&
400 git read-tree --empty &&
401 git commit --allow-empty -m empty &&
402 git clean -d -f -x &&
403 git checkout master &&
404 git merge $auh_opt -m merged alt &&
405 test_must_fail tg import HEAD^\! &&
406 test_must_fail tg import base^\!
409 test_done