tg.sh: make sure noalt_setup takes effect when it should
[topgit/pro.git] / t / t8200-export-subject.sh
blob9e46476a718fe9791d8915238ed593aba2c2092c
1 #!/bin/sh
3 test_description='test export subject handling'
5 . ./test-lib.sh
7 test_plan 40
9 tmp="$(test_get_temp commit)" || die
11 getsubj() {
12 git cat-file commit "$1" >"$tmp" &&
13 <"$tmp" awk '
14 BEGIN {hdr=1}
15 hdr {if ($0 == "") hdr=0; next}
16 !hdr {print; exit}
20 striptopsubj() {
21 grep -v -i 'subject:' <.topmsg >"$tmp" &&
22 cat "$tmp" >.topmsg
25 test_expect_success 'strip patch' '
26 tg_test_create_branches <<-EOT &&
27 t/patch [PATCH] just a patch
30 +t/patch commit on patch
31 :::t/patch
32 EOT
33 git checkout -f t/patch &&
34 tg export e/patch &&
35 subj="$(getsubj e/patch)" &&
36 test z"$subj" = z"just a patch"
39 test_expect_success 'fsck' '
40 git fsck --no-progress --no-dangling
43 test_expect_success 'bad modes' '
44 git checkout -f t/patch &&
45 test_must_fail tg export -s bad no-such-branch &&
46 test_must_fail tg export -s tg -s bad no-such-branch &&
47 test_must_fail tg -c topgit.subjectmode=keep export -s bad no-such-branch &&
48 test_must_fail tg -c topgit.subjectmode=bad export no-such-branch
51 test_expect_success 'strip patch sp' '
52 tg_test_create_branches <<-EOT &&
53 t/patchsp [PATCH ] [PATCH] just a patch sp
56 +t/patchsp commit on patchsp
57 :::t/patchsp
58 EOT
59 git checkout -f t/patchsp &&
60 tg export e/patchsp &&
61 subj="$(getsubj e/patchsp)" &&
62 test z"$subj" = z"[PATCH] just a patch sp"
64 test_expect_success 'strip patch tab' '
65 tg_test_create_branches <<-EOT &&
66 t/patchtab [PATCH ] [PATCH] just a patch tab
69 +t/patchtab commit on patchtab
70 :::t/patchtab
71 EOT
72 git checkout -f t/patchtab &&
73 striptopsubj &&
74 printf "%s\n" "SuBjEcT: [PATCH ] [PATCH] just a patch tab " >>.topmsg &&
75 git commit -m "fuss with .topmsg" .topmsg &&
76 tg export e/patchtab &&
77 subj="$(getsubj e/patchtab)" &&
78 test z"$subj" = z"[PATCH] just a patch tab"
81 test_expect_success 'strip patch x' '
82 tg_test_create_branches <<-EOT &&
83 t/patchx [PATCHx] [PATCH] just a patch x
86 +t/patchx commit on patchx
87 :::t/patchx
88 EOT
89 git checkout -f t/patchx &&
90 tg export e/patchx &&
91 subj="$(getsubj e/patchx)" &&
92 test z"$subj" = z"[PATCH] just a patch x"
95 test_expect_success 'strip patch stuff' '
96 tg_test_create_branches <<-EOT &&
97 t/patchstuff [pAtChX stuff goes here ] [PATCH] just a patch stuff
100 +t/patchstuff commit on patchstuff
101 :::t/patchstuff
103 git checkout -f t/patchstuff &&
104 tg export e/patchstuff &&
105 subj="$(getsubj e/patchstuff)" &&
106 test z"$subj" = z"[PATCH] just a patch stuff"
109 test_expect_success 'strip pfx patch' '
110 tg_test_create_branches <<-EOT &&
111 t/pfxpatch [RFC/PATCH] just a pfxpatch
114 +t/pfxpatch commit on pfxpatch
115 :::t/pfxpatch
117 git checkout -f t/pfxpatch &&
118 tg -c topgit.subjectPrefix=XFc/ export e/pfxpatch &&
119 subj="$(getsubj e/pfxpatch)" &&
120 test z"$subj" = z"[RFC/PATCH] just a pfxpatch" &&
121 tg -c topgit.subjectPrefix=rFc/ export --force e/pfxpatch &&
122 subj="$(getsubj e/pfxpatch)" &&
123 test z"$subj" = z"just a pfxpatch"
126 test_expect_success 'strip pfx patch sp' '
127 tg_test_create_branches <<-EOT &&
128 t/pfxpatchsp [BUG PATCH ] [PATCH] just a pfxpatch sp
131 +t/pfxpatchsp commit on pfxpatchsp
132 :::t/pfxpatchsp
134 git checkout -f t/pfxpatchsp &&
135 tg export e/pfxpatchsp &&
136 subj="$(getsubj e/pfxpatchsp)" &&
137 test z"$subj" = z"[BUG PATCH ] [PATCH] just a pfxpatch sp" &&
138 tg -c topgit.subjectPrefix=Bug export --force e/pfxpatchsp &&
139 subj="$(getsubj e/pfxpatchsp)" &&
140 test z"$subj" = z"[PATCH] just a pfxpatch sp"
143 test_expect_success 'strip pfx patch tab' '
144 tg_test_create_branches <<-EOT &&
145 t/pfxpatchtab [DoxPATCH ] [PATCH] just a pfxpatch tab
148 +t/pfxpatchtab commit on pfxpatchtab
149 :::t/pfxpatchtab
151 git checkout -f t/pfxpatchtab &&
152 striptopsubj &&
153 printf "%s\n" "SuBjEcT: [DoxPATCH ] [PATCH] just a pfxpatch tab " >>.topmsg &&
154 git commit -m "fuss with .topmsg" .topmsg &&
155 tg export e/pfxpatchtab &&
156 subj="$(getsubj e/pfxpatchtab)" &&
157 test z"$subj" = z"[DoxPATCH ] [PATCH] just a pfxpatch tab" &&
158 tg -c topgit.subjectprefix=doX export --force e/pfxpatchtab &&
159 subj="$(getsubj e/pfxpatchtab)" &&
160 test z"$subj" = z"[PATCH] just a pfxpatch tab"
163 test_expect_success 'strip pfx patch x' '
164 tg_test_create_branches <<-EOT &&
165 t/pfxpatchx [?PATCHx] [PATCH] just a pfxpatch x
168 +t/pfxpatchx commit on pfxpatchx
169 :::t/pfxpatchx
171 git checkout -f t/pfxpatchx &&
172 tg export e/pfxpatchx &&
173 subj="$(getsubj e/pfxpatchx)" &&
174 test z"$subj" = z"[?PATCHx] [PATCH] just a pfxpatch x" &&
175 tg -c topgit.subjectprefix="?" export --force e/pfxpatchx &&
176 subj="$(getsubj e/pfxpatchx)" &&
177 test z"$subj" = z"[PATCH] just a pfxpatch x"
180 test_expect_success 'strip pfx patch stuff' '
181 tg_test_create_branches <<-EOT &&
182 t/pfxpatchstuff [- pAtChX stuff goes here ] [PATCH] just a pfxpatch stuff
185 +t/pfxpatchstuff commit on pfxpatchstuff
186 :::t/pfxpatchstuff
188 git checkout -f t/pfxpatchstuff &&
189 tg export e/pfxpatchstuff &&
190 subj="$(getsubj e/pfxpatchstuff)" &&
191 test z"$subj" = z"[- pAtChX stuff goes here ] [PATCH] just a pfxpatch stuff" &&
192 tg -c topgit.sUbJECtPREfix=- export --force e/pfxpatchstuff &&
193 subj="$(getsubj e/pfxpatchstuff)" &&
194 test z"$subj" = z"[PATCH] just a pfxpatch stuff"
197 test_expect_success 'strip multi patch' '
198 tg_test_create_branches <<-EOT &&
199 t/patchmulti [PATCH] [PATCH] [PATCH] just a multi-patch
202 +t/patchmulti commit on patchmulti
203 :::t/patchmulti
205 git checkout -f t/patchmulti &&
206 tg -c topgit.subjectmode=mailinfo export e/patchmulti &&
207 subj="$(getsubj e/patchmulti)" &&
208 test z"$subj" = z"just a multi-patch"
211 test_expect_success 'strip multi brackets' '
212 tg_test_create_branches <<-EOT &&
213 t/multi [PATCH] [PATCHv2] [PATCHv3 1/2] [OTHER] [tag] [whatever] [here] just a mess
216 +t/multi commit on multi
217 :::t/multi
219 git checkout -f t/multi &&
220 tg export -s mailinfo e/multi &&
221 subj="$(getsubj e/multi)" &&
222 test z"$subj" = z"just a mess"
225 test_expect_success 'strip multi brackets only' '
226 tg_test_create_branches <<-EOT &&
227 t/multistop [PATCH] [PATCHv2] [PATCHv3 1/2] [OTHER] stop [tag] [whatever] [here] just a mess
230 +t/multistop commit on multistop
231 :::t/multistop
233 git checkout -f t/multistop &&
234 tg -c topgit.subjectmode=keep export -s mailinfo e/multistop &&
235 subj="$(getsubj e/multistop)" &&
236 test z"$subj" = z"stop [tag] [whatever] [here] just a mess"
239 test_expect_success 'strip clean subject 1' '
240 tg_test_create_branches <<-EOT &&
241 t/cleanup [ M E S S ] j usta m e ss
244 +t/cleanup commit on cleanup
245 :::t/cleanup
247 git checkout -f t/cleanup &&
248 striptopsubj &&
249 printf "%s\n" "SuBjEcT: [Some] [ M e s ] here it is " >>.topmsg &&
250 git commit -m "fuss with .topmsg" .topmsg &&
251 tg export -s keep -s mailinfo e/cleanup &&
252 subj="$(getsubj e/cleanup)" &&
253 test z"$subj" = z"here it is"
256 test_expect_success 'strip clean subject 2' '
257 tg_test_create_branches <<-EOT &&
258 t/cleanuptoo [ M E S S ] j usta m e ss
261 +t/cleanuptoo commit on cleanuptoo
262 :::t/cleanuptoo
264 git checkout -f t/cleanuptoo &&
265 striptopsubj &&
266 printf "%s\n" "SuBjEcT: :[Some] [ M e s ] here it is " >>.topmsg &&
267 git commit -m "fuss with .topmsg" .topmsg &&
268 tg export -s mailinfo e/cleanuptoo &&
269 subj="$(getsubj e/cleanuptoo)" &&
270 test z"$subj" = z"here it is"
273 test_expect_success 'strip clean not a subject' '
274 tg_test_create_branches <<-EOT &&
275 t/cleanupnada [ M E S S ] j usta m e ss
278 +t/cleanupnada commit on cleanupnada
279 :::t/cleanupnada
281 git checkout -f t/cleanupnada &&
282 striptopsubj &&
283 # keywords are only valid when the ":" is attached to them w/o whitespace
284 # that means there is no subject and in that case the subject is expected
285 # to default to the TopGit branch name NOT the first line of .topmsg!
286 printf "%s\n" "SuBjEcT :[Some] [ M e s ] here it is " >>.topmsg &&
287 git commit -m "fuss with .topmsg" .topmsg &&
288 tg export -s mailinfo e/cleanupnada &&
289 subj="$(getsubj e/cleanupnada)" &&
290 test z"$subj" = z"t/cleanupnada"
293 test_expect_success 'strip clean cfws subject' '
294 tg_test_create_branches <<-EOT &&
295 t/cfws [l8r] fill in
298 +t/cfws commit on cfws
299 :::t/cfws
301 git checkout -f t/cfws &&
302 striptopsubj &&
303 printf "%s\n" "SUBject: [Patch]" " [Me]" " First off:" " this should (not?) work " >>.topmsg &&
304 git commit -m "fuss with .topmsg" .topmsg &&
305 tg export -s mailinfo e/cfws &&
306 subj="$(getsubj e/cfws)" &&
307 test z"$subj" = z"First off: this should (not?) work"
310 test_expect_success 'keep subject' '
311 tg_test_create_branches <<-EOT &&
312 t/keep [PATCH] [ M E S S ] j usta m e ss
315 +t/keep commit on keep
316 :::t/keep
318 git checkout -f t/keep &&
319 striptopsubj &&
320 printf "%s\n" "subject: :[Some] [ M e s ] here it is " >>.topmsg &&
321 git commit -m "fuss with .topmsg" .topmsg &&
322 tg export -s keep e/keep &&
323 subj="$(getsubj e/keep)" &&
324 test z"$subj" = z":[Some] [ M e s ] here it is"
327 test_expect_success 'trim subject' '
328 tg_test_create_branches <<-EOT &&
329 t/trim [PATCH] [ M E S S ] j usta m e ss
332 +t/trim commit on trim
333 :::t/trim
335 git checkout -f t/trim &&
336 striptopsubj &&
337 printf "%s\n" "subject: :[Some] [ M e s ] here it is " >>.topmsg &&
338 git commit -m "fuss with .topmsg" .topmsg &&
339 tg export -s trim e/trim &&
340 tg export -s ws e/ws &&
341 subj="$(getsubj e/trim)" &&
342 test z"$subj" = z":[Some] [ M e s ] here it is" &&
343 subj="$(getsubj e/ws)" &&
344 test z"$subj" = z":[Some] [ M e s ] here it is"
347 test_expect_success 'patch mode just one' '
348 tg_test_create_branches <<-EOT &&
349 t/patch1 [PATCH] just a patch
352 +t/patch1 commit on patch1
353 :::t/patch1
355 git checkout -f t/patch1 &&
356 tg export -s patch e/patch1 &&
357 subj="$(getsubj e/patch1)" &&
358 test z"$subj" = z"just a patch" &&
359 tg -c topgit.subjectPrefix=xyz export --force -s patch e/patch1 &&
360 subj="$(getsubj e/patch1)" &&
361 test z"$subj" = z"just a patch" &&
362 tg export --force -s tg e/patch1 &&
363 subj="$(getsubj e/patch1)" &&
364 test z"$subj" = z"just a patch" &&
365 tg -c topgit.subjectPrefix=xyz export --force -s tg e/patch1 &&
366 subj="$(getsubj e/patch1)" &&
367 test z"$subj" = z"just a patch"
370 test_expect_success 'patch mode just one prefixed' '
371 tg_test_create_branches <<-EOT &&
372 t/patch_xyz [XyZ pAtCh] just a patch
375 +t/patch_xyz commit on patch_xyz
376 :::t/patch_xyz
378 git checkout -f t/patch_xyz &&
379 tg export -s patch e/patch_xyz &&
380 subj="$(getsubj e/patch_xyz)" &&
381 test z"$subj" = z"[XyZ pAtCh] just a patch" &&
382 tg -c topgit.subjectPrefix=xyz export --force -s patch e/patch_xyz &&
383 subj="$(getsubj e/patch_xyz)" &&
384 test z"$subj" = z"just a patch" &&
385 tg export --force -s topgit e/patch_xyz &&
386 subj="$(getsubj e/patch_xyz)" &&
387 test z"$subj" = z"[XyZ pAtCh] just a patch" &&
388 tg -c topgit.subjectPrefix=xyz export --force -s topgit e/patch_xyz &&
389 subj="$(getsubj e/patch_xyz)" &&
390 test z"$subj" = z"just a patch"
393 test_expect_success 'patch mode just one prefixed no space' '
394 tg_test_create_branches <<-EOT &&
395 t/patchxyz [XyZpAtCh] just a patch
398 +t/patchxyz commit on patchxyz
399 :::t/patchxyz
401 git checkout -f t/patchxyz &&
402 tg export -s patch e/patchxyz &&
403 subj="$(getsubj e/patchxyz)" &&
404 test z"$subj" = z"[XyZpAtCh] just a patch" &&
405 tg -c topgit.subjectPrefix=xyz export --force -s patch e/patchxyz &&
406 subj="$(getsubj e/patchxyz)" &&
407 test z"$subj" = z"just a patch" &&
408 tg export --force e/patchxyz &&
409 subj="$(getsubj e/patchxyz)" &&
410 test z"$subj" = z"[XyZpAtCh] just a patch" &&
411 tg -c topgit.subjectPrefix=xyz export --force e/patchxyz &&
412 subj="$(getsubj e/patchxyz)" &&
413 test z"$subj" = z"just a patch"
416 test_expect_success 'patch mode non first' '
417 tg_test_create_branches <<-EOT &&
418 t/patchl8r not [PATCH] just a patch
421 +t/patchl8r commit on patchl8r
422 :::t/patchl8r
424 git checkout -f t/patchl8r &&
425 tg export -s patch e/patchl8r &&
426 subj="$(getsubj e/patchl8r)" &&
427 test z"$subj" = z"not [PATCH] just a patch" &&
428 tg export --force e/patchl8r &&
429 subj="$(getsubj e/patchl8r)" &&
430 test z"$subj" = z"not [PATCH] just a patch"
433 test_expect_success 'patch mode just first' '
434 tg_test_create_branches <<-EOT &&
435 t/patch2 [pAtCh] [PATCH] just a patch
438 +t/patch2 commit on patch2
439 :::t/patch2
441 git checkout -f t/patch2 &&
442 tg export -s patch e/patch2 &&
443 subj="$(getsubj e/patch2)" &&
444 test z"$subj" = z"[PATCH] just a patch" &&
445 git checkout -f t/patch2 &&
446 tg export --force e/patch2 &&
447 subj="$(getsubj e/patch2)" &&
448 test z"$subj" = z"[PATCH] just a patch"
451 test_expect_success 'topgit mode stage' '
452 tg_test_create_branches <<-EOT &&
453 t/stage [STAGE] just a patch
456 +t/stage commit on stage
457 :::t/stage
459 git checkout -f t/stage &&
460 tg export -s patch e/stage &&
461 subj="$(getsubj e/stage)" &&
462 test z"$subj" = z"[STAGE] just a patch" &&
463 tg export --force e/stage &&
464 subj="$(getsubj e/stage)" &&
465 test z"$subj" = z"just a patch"
468 test_expect_success 'topgit mode pfx stage' '
469 tg_test_create_branches <<-EOT &&
470 t/pfxstage [PSTAGE] just a pfxpatch
473 +t/pfxstage commit on pfxstage
474 :::t/pfxstage
476 git checkout -f t/pfxstage &&
477 tg export e/pfxstage &&
478 subj="$(getsubj e/pfxstage)" &&
479 test z"$subj" = z"[PSTAGE] just a pfxpatch" &&
480 tg -c topgit.subjectprefix=p export --force -s patch e/pfxstage &&
481 subj="$(getsubj e/pfxstage)" &&
482 test z"$subj" = z"[PSTAGE] just a pfxpatch" &&
483 tg -c topgit.subjectprefix=p export --force e/pfxstage &&
484 subj="$(getsubj e/pfxstage)" &&
485 test z"$subj" = z"just a pfxpatch"
488 test_expect_success 'topgit mode stage sp' '
489 tg_test_create_branches <<-EOT &&
490 t/stagesp [STAGE ] just a patch sp
493 +t/stagesp commit on stagesp
494 :::t/stagesp
496 git checkout -f t/stagesp &&
497 tg export e/stagesp &&
498 subj="$(getsubj e/stagesp)" &&
499 test z"$subj" = z"[STAGE ] just a patch sp"
502 test_expect_success 'topgit mode base' '
503 tg_test_create_branches <<-EOT &&
504 t/base [BASE] just a patch
507 +t/base commit on base
508 :::t/base
510 git checkout -f t/base &&
511 tg export -s patch e/base &&
512 subj="$(getsubj e/base)" &&
513 test z"$subj" = z"[BASE] just a patch" &&
514 tg export --force e/base &&
515 subj="$(getsubj e/base)" &&
516 test z"$subj" = z"just a patch"
519 test_expect_success 'topgit mode pfx base' '
520 tg_test_create_branches <<-EOT &&
521 t/pfxbase [PBASE] just a pfxpatch
524 +t/pfxbase commit on pfxbase
525 :::t/pfxbase
527 git checkout -f t/pfxbase &&
528 tg export e/pfxbase &&
529 subj="$(getsubj e/pfxbase)" &&
530 test z"$subj" = z"[PBASE] just a pfxpatch" &&
531 tg -c topgit.subjectprefix=p export --force -s patch e/pfxbase &&
532 subj="$(getsubj e/pfxbase)" &&
533 test z"$subj" = z"[PBASE] just a pfxpatch" &&
534 tg -c topgit.subjectprefix=p export --force e/pfxbase &&
535 subj="$(getsubj e/pfxbase)" &&
536 test z"$subj" = z"just a pfxpatch"
539 test_expect_success 'topgit mode base sp' '
540 tg_test_create_branches <<-EOT &&
541 t/basesp [BASE ] just a patch sp
544 +t/basesp commit on basesp
545 :::t/basesp
547 git checkout -f t/basesp &&
548 tg export e/basesp &&
549 subj="$(getsubj e/basesp)" &&
550 test z"$subj" = z"[BASE ] just a patch sp"
553 test_expect_success 'topgit mode root' '
554 tg_test_create_branches <<-EOT &&
555 t/root [ROOT] just a patch
558 +t/root commit on root
559 :::t/root
561 git checkout -f t/root &&
562 tg export -s patch e/root &&
563 subj="$(getsubj e/root)" &&
564 test z"$subj" = z"[ROOT] just a patch" &&
565 tg export --force e/root &&
566 subj="$(getsubj e/root)" &&
567 test z"$subj" = z"just a patch"
570 test_expect_success 'topgit mode pfx root' '
571 tg_test_create_branches <<-EOT &&
572 t/pfxroot [PROOT] just a pfxpatch
575 +t/pfxroot commit on pfxroot
576 :::t/pfxroot
578 git checkout -f t/pfxroot &&
579 tg export e/pfxroot &&
580 subj="$(getsubj e/pfxroot)" &&
581 test z"$subj" = z"[PROOT] just a pfxpatch" &&
582 tg -c topgit.subjectprefix=p export --force -s patch e/pfxroot &&
583 subj="$(getsubj e/pfxroot)" &&
584 test z"$subj" = z"[PROOT] just a pfxpatch" &&
585 tg -c topgit.subjectprefix=p export --force e/pfxroot &&
586 subj="$(getsubj e/pfxroot)" &&
587 test z"$subj" = z"just a pfxpatch"
590 test_expect_success 'topgit mode root sp' '
591 tg_test_create_branches <<-EOT &&
592 t/rootsp [ROOT ] just a patch sp
595 +t/rootsp commit on rootsp
596 :::t/rootsp
598 git checkout -f t/rootsp &&
599 tg export e/rootsp &&
600 subj="$(getsubj e/rootsp)" &&
601 test z"$subj" = z"[ROOT ] just a patch sp"
604 test_expect_success 'topgit mode not a patch' '
605 tg_test_create_branches <<-EOT &&
606 t/pnap [PATC ] not a patch
609 +t/pnap commit on pnap
610 :::t/pnap
612 git checkout -f t/pnap &&
613 tg export e/pnap &&
614 subj="$(getsubj e/pnap)" &&
615 test z"$subj" = z"[PATC ] not a patch"
618 test_expect_success 'topgit mode not a stage' '
619 tg_test_create_branches <<-EOT &&
620 t/snap [STAG] not a stage
623 +t/snap commit on snap
624 :::t/snap
626 git checkout -f t/snap &&
627 tg export e/snap &&
628 subj="$(getsubj e/snap)" &&
629 test z"$subj" = z"[STAG] not a stage"
632 test_expect_success 'topgit mode not a base' '
633 tg_test_create_branches <<-EOT &&
634 t/bnap [BASF] not a base
637 +t/bnap commit on bnap
638 :::t/bnap
640 git checkout -f t/bnap &&
641 tg export e/bnap &&
642 subj="$(getsubj e/bnap)" &&
643 test z"$subj" = z"[BASF] not a base"
646 test_expect_success 'topgit mode not a root' '
647 tg_test_create_branches <<-EOT &&
648 t/rnap [ROO] not a root
651 +t/rnap commit on rnap
652 :::t/rnap
654 git checkout -f t/rnap &&
655 tg export e/rnap &&
656 subj="$(getsubj e/rnap)" &&
657 test z"$subj" = z"[ROO] not a root"
660 test_expect_success 'wrap-up fsck' '
661 git fsck --no-progress --no-dangling
664 test_done