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