tg.sh: handle help -h
[topgit/pro.git] / t / t4100-summary.sh
blobacaec6cc908b23db8c12649fe2342d5e1f672e1d
1 #!/bin/sh
3 test_description='check summary output'
5 TEST_NO_CREATE_REPO=1
7 . ./test-lib.sh
9 test_plan 29
11 reset_repo() {
12 git read-tree --empty &&
13 git symbolic-ref HEAD refs/heads/orphan
16 squish() {
17 tab=" " # single tab in there
18 tr -s "$tab" " "
21 test_expect_success 'setup' '
22 test_create_repo pristine && cd pristine &&
23 git checkout --orphan rootcommit &&
24 git read-tree --empty &&
25 test_tick &&
26 git commit --allow-empty -m "empty root commit" &&
27 git tag rootcommit &&
28 git checkout --orphan branch1 &&
29 git read-tree --empty &&
30 test_commit branch1-start &&
31 git checkout --orphan branch2 &&
32 git read-tree --empty &&
33 test_commit branch2-start &&
34 git checkout --orphan branch3 &&
35 git read-tree --empty &&
36 test_commit branch3-start &&
37 reset_repo &&
38 git clean -x -d -f &&
39 tg_test_create_branches <<-EOT &&
40 rootbare bare empty root
43 rootmsg topmsg root
46 rootdeps --no-topmsg topdeps root
49 root standard root branch
52 annihilated annihilated branch
55 basebare bare base
56 ::rootcommit
58 +basebare bare base
59 :::basebare
61 t/branch1 branch1 topgit
62 branch1
64 t/branch2 branch2 topgit
65 branch2
67 t/branch3 branch3 topgit
68 branch3
70 reused-1level1 reused with one tg branch below
71 t/branch1
73 reused-2level1 reused with two tg branches below
74 t/branch1
75 t/branch2
77 reused-1level2 reused with one tg branch below
78 reused-1level1
80 reused-2level2 reused with two tg branches below
81 reused-1level1
82 reused-2level1
84 reused-multi multi-level reuse
85 reused-2level1
86 t/branch3
87 reused-2level2
89 EOT
90 git checkout -f annihilated &&
91 test_tick &&
92 git commit --allow-empty -m "annihilated not empty" &&
93 git checkout -f t/branch2 &&
94 <.topmsg grep -v -i subject >.topmsg2 &&
95 mv -f .topmsg2 .topmsg &&
96 printf "%s\n" "subject:[PATCH] branch2" " topgit" >> .topmsg &&
97 git add .topmsg &&
98 test_tick &&
99 git commit -m ".topmsg: no space after subject colon" &&
100 reset_repo &&
101 git clean -x -d -f &&
102 cd .. &&
103 cp -pR pristine copy
106 test_expect_success 'bad usage' '
107 cd copy && reset_repo &&
109 # HEAD is unborn
110 test_must_fail tg summary --rdeps && # bad HEAD default
111 test_must_fail tg summary --rdeps-once && # bad HEAD default
112 test_must_fail tg summary --rdeps-full && # bad HEAD default
113 test_must_fail tg summary --with-deps && # bad HEAD default
114 test_must_fail tg summary --without-deps && # bad HEAD default
115 test_must_fail tg summary --deps-only && # bad HEAD default
116 test_must_fail tg summary --deps HEAD && # bad HEAD (--deps does not default)
118 git update-ref --no-deref HEAD branch1 &&
120 # HEAD is detached
121 test_must_fail tg summary --rdeps && # bad HEAD default
122 test_must_fail tg summary --rdeps-once && # bad HEAD default
123 test_must_fail tg summary --rdeps-full && # bad HEAD default
124 test_must_fail tg summary --with-deps && # bad HEAD default
125 test_must_fail tg summary --without-deps && # bad HEAD default
126 test_must_fail tg summary --deps-only && # bad HEAD default
127 test_must_fail tg summary --deps HEAD && # bad HEAD (--deps does not default)
129 git symbolic-ref HEAD refs/heads/branch3 &&
131 # HEAD is a non-TopGit branch
132 test_must_fail tg summary --rdeps && # bad HEAD default
133 test_must_fail tg summary --rdeps-once && # bad HEAD default
134 test_must_fail tg summary --rdeps-full && # bad HEAD default
135 test_must_fail tg summary --with-deps && # bad HEAD default
136 test_must_fail tg summary --without-deps && # bad HEAD default
137 test_must_fail tg summary --deps-only && # bad HEAD default
138 test_must_fail tg summary --deps HEAD && # bad HEAD (--deps does not default)
140 : # placeholder
143 printf "%s" "\
144 basebare branch basebare (bare branch)
145 0 reused-1level1 [PATCH] reused with one tg branch below
146 0 reused-1level2 [PATCH] reused with one tg branch below
147 0 D * reused-2level1 [PATCH] reused with two tg branches below
148 0 D * reused-2level2 [PATCH] reused with two tg branches below
149 0 D reused-multi [PATCH] multi-level reuse
150 0 root [PATCH] standard root branch
151 0 rootdeps branch rootdeps (missing .topmsg)
152 0 rootmsg [PATCH] topmsg root
153 0 t/branch1 [PATCH] branch1 topgit
154 0 * t/branch2 [PATCH] branch2 topgit
155 0 * t/branch3 [PATCH] branch3 topgit
156 " > pristine_full_summary.raw ||
157 die failed to make pristine_full_summary.raw
158 < pristine_full_summary.raw squish > pristine_full_summary ||
159 die failed to make pristine_full_summary
161 printf "%s" "\
162 0 reused-1level1 [PATCH] reused with one tg branch below
163 0 D * reused-2level1 [PATCH] reused with two tg branches below
164 0 D * reused-2level2 [PATCH] reused with two tg branches below
165 0 D reused-multi [PATCH] multi-level reuse
166 0 t/branch1 [PATCH] branch1 topgit
167 0 * t/branch2 [PATCH] branch2 topgit
168 0 * t/branch3 [PATCH] branch3 topgit
169 " > pristine_multi_summary.raw ||
170 die failed to make pristine_multi_summary.raw
171 < pristine_multi_summary.raw squish > pristine_multi_summary ||
172 die failed to make pristine_multi_summary
174 printf "%s" "\
175 0 D reused-2level1 [PATCH] reused with two tg branches below
176 0 t/branch1 [PATCH] branch1 topgit
177 0 * t/branch2 [PATCH] branch2 topgit
178 " > pristine_2level1_summary.raw ||
179 die failed to make pristine_2level1_summary.raw
180 < pristine_2level1_summary.raw squish > pristine_2level1_summary ||
181 die failed to make pristine_2level1_summary
183 printf "%s" "\
184 basebare
185 reused-1level1
186 reused-1level2
187 reused-2level1
188 reused-2level2
189 reused-multi
190 root
191 rootdeps
192 rootmsg
193 t/branch1
194 t/branch2
195 t/branch3
196 " >pristine_list || die failed to make pristine_list
198 printf "%s" "\
199 reused-1level1 t/branch1
200 reused-1level2 reused-1level1
201 reused-2level1 t/branch1
202 reused-2level1 t/branch2
203 reused-2level2 reused-1level1
204 reused-2level2 reused-2level1
205 reused-multi reused-2level1
206 reused-multi t/branch3
207 reused-multi reused-2level2
208 t/branch1 branch1
209 t/branch2 branch2
210 t/branch3 branch3
211 " >pristine_deps || die failed to make pristine_deps
213 printf "%s" "\
214 basebare
215 branch1
216 branch2
217 branch3
218 reused-1level1
219 reused-1level2
220 reused-2level1
221 reused-2level2
222 reused-multi
223 root
224 rootdeps
225 rootmsg
226 t/branch1
227 t/branch2
228 t/branch3
229 " >pristine_deps_only_all || die failed to make pristine_deps_only_all
231 printf "%s" "\
232 reused-multi
233 reused-2level2
234 reused-2level1
235 reused-1level2
236 reused-1level1
237 t/branch3
238 t/branch2
239 t/branch1
240 branch3
241 branch2
242 branch1
243 " >pristine_sort || die failed to make pristine_sort
245 printf "%s" \
246 '# GraphViz output; pipe to:
247 # | dot -Tpng -o <output>
248 # or
249 # | dot -Txlib
251 digraph G {
253 graph [
254 rankdir = "TB"
255 label="TopGit Layout\n\n\n"
256 fontsize = 14
257 labelloc=top
258 pad = "0.5,0.5"
261 "reused-1level1" -> "t/branch1";
262 "reused-1level2" -> "reused-1level1";
263 "reused-2level1" -> "t/branch1";
264 "reused-2level1" -> "t/branch2";
265 "reused-2level2" -> "reused-1level1";
266 "reused-2level2" -> "reused-2level1";
267 "reused-multi" -> "reused-2level1";
268 "reused-multi" -> "t/branch3";
269 "reused-multi" -> "reused-2level2";
270 "t/branch1" -> "branch1";
271 "t/branch2" -> "branch2";
272 "t/branch3" -> "branch3";
274 ' >pristine_graphviz || die failed to make pristine_graphviz
276 printf "%s" "\
277 basebare
278 reused-1level2
279 reused-multi
280 root
281 rootdeps
282 rootmsg
283 " >pristine_heads || die failed to make pristine_heads
285 printf "%s" "\
286 basebare branch basebare (bare branch)
287 reused-1level1 [PATCH] reused with one tg branch below
288 reused-1level2 [PATCH] reused with one tg branch below
289 reused-2level1 [PATCH] reused with two tg branches below
290 reused-2level2 [PATCH] reused with two tg branches below
291 reused-multi [PATCH] multi-level reuse
292 root [PATCH] standard root branch
293 rootbare branch rootbare (no commits)
294 rootdeps branch rootdeps (missing .topmsg)
295 rootmsg [PATCH] topmsg root
296 t/branch1 [PATCH] branch1 topgit
297 t/branch2 [PATCH] branch2 topgit
298 t/branch3 [PATCH] branch3 topgit
299 " > pristine_list_verbose.raw ||
300 die failed to make pristine_list_verbose.raw
301 < pristine_list_verbose.raw squish > pristine_list_verbose ||
302 die failed to make pristine_list_verbose
304 printf "%s" "\
305 basebare branch basebare (bare branch)
306 0 reused-1level2 [PATCH] reused with one tg branch below
307 0 D reused-multi [PATCH] multi-level reuse
308 0 root [PATCH] standard root branch
309 0 rootdeps branch rootdeps (missing .topmsg)
310 0 rootmsg [PATCH] topmsg root
311 " > pristine_heads_only.raw ||
312 die failed to make pristine_heads_only.raw
313 < pristine_heads_only.raw squish > pristine_heads_only ||
314 die failed to make pristine_heads_only
316 printf "%s" "\
317 annihilated branch annihilated (annihilated)
318 basebare branch basebare (bare branch)
319 reused-1level1 [PATCH] reused with one tg branch below
320 reused-1level2 [PATCH] reused with one tg branch below
321 reused-2level1 [PATCH] reused with two tg branches below
322 reused-2level2 [PATCH] reused with two tg branches below
323 reused-multi [PATCH] multi-level reuse
324 root [PATCH] standard root branch
325 rootbare branch rootbare (no commits)
326 rootdeps branch rootdeps (missing .topmsg)
327 rootmsg [PATCH] topmsg root
328 t/branch1 [PATCH] branch1 topgit
329 t/branch2 [PATCH] branch2 topgit
330 t/branch3 [PATCH] branch3 topgit
331 " > pristine_list_verbose2.raw ||
332 die failed to make pristine_list_verbose2.raw
333 < pristine_list_verbose2.raw squish > pristine_list_verbose2 ||
334 die failed to make pristine_list_verbose2
336 printf "%s" "\
337 basebare
339 reused-1level2
340 reused-1level1
341 t/branch1
342 branch1
344 reused-multi
345 reused-2level1
346 t/branch1
347 branch1
348 t/branch2
349 branch2
350 t/branch3
351 branch3
352 reused-2level2
353 reused-1level1
354 t/branch1
355 branch1
356 reused-2level1
357 t/branch1
358 branch1
359 t/branch2
360 branch2
362 root
364 rootdeps
366 rootmsg
367 " >pristine_rdeps_full_heads || die failed to make pristine_rdeps_full_heads
369 printf "%s" "\
370 basebare
372 reused-1level2
373 reused-1level1
374 t/branch1
375 branch1
377 reused-multi
378 reused-2level1
379 t/branch1
380 branch1
381 t/branch2
382 branch2
383 t/branch3
384 branch3
385 reused-2level2
386 reused-1level1
387 t/branch1^
388 reused-2level1^
390 root
392 rootdeps
394 rootmsg
395 " >pristine_rdeps_once_heads || die failed to make pristine_rdeps_once_heads
397 printf "%s" "\
398 reused-multi
399 reused-2level1
400 t/branch1
401 branch1
402 t/branch2
403 branch2
404 t/branch3
405 branch3
406 reused-2level2
407 reused-1level1
408 t/branch1
409 branch1
410 reused-2level1
411 t/branch1
412 branch1
413 t/branch2
414 branch2
415 " >pristine_rdeps_full_multi || die failed to make pristine_rdeps_full_multi
417 printf "%s" "\
418 reused-multi
419 reused-2level1
420 t/branch1
421 branch1
422 t/branch2
423 branch2
424 t/branch3
425 branch3
426 reused-2level2
427 reused-1level1
428 t/branch1^
429 reused-2level1^
430 " >pristine_rdeps_once_multi || die failed to make pristine_rdeps_once_multi
432 printf "%s" "\
433 reused-2level2
434 reused-1level1
435 t/branch1
436 branch1
437 reused-2level1
438 t/branch1
439 branch1
440 t/branch2
441 branch2
442 " >pristine_rdeps_full_2level2 || die failed to make pristine_rdeps_full_2level2
444 printf "%s" "\
445 reused-2level2
446 reused-1level1
447 t/branch1
448 branch1
449 reused-2level1
450 t/branch1^
451 t/branch2
452 branch2
453 " >pristine_rdeps_once_2level2 || die failed to make pristine_rdeps_once_2level2
455 test_expect_success 'list' '
456 cd copy && reset_repo &&
457 tg summary --list > actual.raw &&
458 squish < actual.raw > actual &&
459 test_diff ../pristine_list actual
462 test_expect_success 'list verbose' '
463 cd copy && reset_repo &&
464 tg summary --verbose --list > actual.raw &&
465 squish < actual.raw > actual &&
466 test_diff ../pristine_list_verbose actual
469 test_expect_success 'list verbose verbose' '
470 cd copy && reset_repo &&
471 tg summary --verbose --verbose --list > actual.raw &&
472 squish < actual.raw > actual &&
473 test_diff ../pristine_list_verbose2 actual
476 test_expect_success 'deps' '
477 cd copy && reset_repo &&
478 tg summary --deps > actual &&
479 test_diff ../pristine_deps actual
482 test_expect_success 'deps only all' '
483 cd copy && reset_repo &&
484 tg summary --deps-only --all > actual &&
485 test_diff ../pristine_deps_only_all actual
488 test_expect_success 'sort' '
489 cd copy && reset_repo &&
490 # the problem with tsort is that it is only guaranteed to produce "a"
491 # topological sort. If there is more than one possible correct answer
492 # which one it produces is left unspecified (i.e. up to the
493 # implementation). So we sort the output. Ugh.
494 sort < ../pristine_sort > expected &&
495 tg summary --sort > actual.raw &&
496 sort < actual.raw > actual &&
497 test_diff expected actual &&
498 # but then we also generate a "--sort" output for reused-1level2 which
499 # we do NOT sort because it has only one valid topological ordering
500 # which should therefore provide the best of both worlds.
501 printf "%s" "\
502 reused-1level2
503 reused-1level1
504 t/branch1
505 branch1
506 " > expected &&
507 tg summary --sort reused-1level2 > actual &&
508 test_diff expected actual
511 test_expect_success 'graphviz' '
512 cd copy && reset_repo &&
513 tg summary --graphviz > actual &&
514 test_diff ../pristine_graphviz actual
517 test_expect_success 'heads' '
518 cd copy && reset_repo &&
519 tg summary --heads > actual &&
520 test_diff ../pristine_heads actual
523 test_expect_success 'summary heads only' '
524 cd copy && reset_repo &&
525 tg summary --heads-only > actual.raw &&
526 squish < actual.raw > actual &&
527 test_diff ../pristine_heads_only actual
530 test_expect_success 'summary with orphan HEAD' '
531 cd copy && reset_repo &&
532 tg summary > actual.raw &&
533 squish < actual.raw > actual &&
534 test_diff ../pristine_full_summary actual
537 test_expect_success 'summary with detached HEAD' '
538 cd copy && reset_repo &&
539 git update-ref --no-deref HEAD t/branch1 &&
540 tg summary > actual.raw &&
541 squish < actual.raw > actual &&
542 test_diff ../pristine_full_summary actual
545 test_expect_success 'summary with non-TopGit HEAD' '
546 cd copy && reset_repo &&
547 git symbolic-ref HEAD refs/heads/branch2 &&
548 tg summary > actual.raw &&
549 squish < actual.raw > actual &&
550 test_diff ../pristine_full_summary actual
553 test_expect_success 'summary with TopGit HEAD' '
554 cd copy && reset_repo &&
555 < ../pristine_full_summary sed "/reused-2level1/s/^ />/" > expected &&
556 git symbolic-ref HEAD refs/heads/reused-2level1 &&
557 tg summary > actual.raw &&
558 squish < actual.raw > actual &&
559 test_diff expected actual
562 test_expect_success 'summary with TopGit base HEAD' '
563 cd copy && reset_repo &&
564 < ../pristine_full_summary sed "/reused-2level1/s/^ />/" > expected &&
565 git symbolic-ref HEAD "$(tg --top-bases)/reused-2level1" &&
566 tg summary > actual.raw &&
567 squish < actual.raw > actual &&
568 test_diff expected actual
571 test_expect_success 'rdeps heads' '
572 cd copy && reset_repo &&
573 tg summary --rdeps --heads > actual &&
574 test_diff ../pristine_rdeps_once_heads actual
577 test_expect_success 'rdeps-once heads' '
578 cd copy && reset_repo &&
579 tg summary --rdeps-once --heads > actual &&
580 test_diff ../pristine_rdeps_once_heads actual
583 test_expect_success 'rdeps-full heads' '
584 cd copy && reset_repo &&
585 tg summary --rdeps-full --heads > actual &&
586 test_diff ../pristine_rdeps_full_heads actual
589 test_expect_success 'rdeps-once reused-multi' '
590 cd copy && reset_repo &&
591 tg summary --rdeps-once reused-multi > actual &&
592 test_diff ../pristine_rdeps_once_multi actual
595 test_expect_success 'rdeps-full reused-multi' '
596 cd copy && reset_repo &&
597 tg summary --rdeps-full reused-multi > actual &&
598 test_diff ../pristine_rdeps_full_multi actual
601 test_expect_success 'rdeps-once reused-2level2' '
602 cd copy && reset_repo &&
603 tg summary --rdeps-once reused-2level2 > actual &&
604 test_diff ../pristine_rdeps_once_2level2 actual
607 test_expect_success 'rdeps-full reused-2level2' '
608 cd copy && reset_repo &&
609 tg summary --rdeps-full reused-2level2 > actual &&
610 test_diff ../pristine_rdeps_full_2level2 actual
613 test_expect_success 'summary with-deps multi' '
614 cd copy && reset_repo &&
615 tg summary --with-deps reused-multi > actual.raw &&
616 squish < actual.raw > actual &&
617 test_diff ../pristine_multi_summary actual
620 test_expect_success 'summary with-related multi' '
621 cd copy && reset_repo &&
622 tg summary --with-related reused-multi > actual.raw &&
623 squish < actual.raw > actual &&
624 test_diff ../pristine_multi_summary actual
627 test_expect_success 'summary with-deps 2level1' '
628 cd copy && reset_repo &&
629 tg summary --with-deps reused-2level1 > actual.raw &&
630 squish < actual.raw > actual &&
631 test_diff ../pristine_2level1_summary actual
634 test_expect_success 'summary with-related 2level1' '
635 cd copy && reset_repo &&
636 tg summary --with-related reused-2level1 > actual.raw &&
637 squish < actual.raw > actual &&
638 test_diff ../pristine_multi_summary actual
641 test_expect_success 'summary @ with 2level1 HEAD' '
642 cd copy && reset_repo &&
643 < ../pristine_multi_summary sed "/reused-2level1/s/^ />/" > expected &&
644 git symbolic-ref HEAD "refs/heads/reused-2level1" &&
645 tg summary @ > actual.raw &&
646 squish < actual.raw > actual &&
647 test_diff expected actual
650 test_expect_success 'summary @ @ with 2level1 HEAD' '
651 cd copy && reset_repo &&
652 < ../pristine_2level1_summary sed "/reused-2level1/s/^ />/" > expected &&
653 git symbolic-ref HEAD "refs/heads/reused-2level1" &&
654 tg summary @ @ > actual.raw &&
655 squish < actual.raw > actual &&
656 test_diff expected actual
659 test_done