chiark / gitweb /
fe8d8fc01ab5aa51a7c361113777a13a68bd4afa
[dgit.git] / tests / lib
1 #
2
3 exec 2>&1
4 set -x
5 set -o pipefail
6
7 . tests/lib-core
8 . tests/lib-restricts
9
10 t-report-failure () {
11         set +x
12         rc=$1
13         cat <<END >&2
14 TEST FAILED
15 funcs: ${FUNCNAME[*]}
16 lines: ${BASH_LINENO[*]}
17 files: ${BASH_SOURCE[*]}
18 END
19         exit 16
20 }
21
22 trap 'test $? = 0 || t-report-failure' EXIT
23
24 t-filter-out-git-hyphen-dir
25
26 t-set-intree
27
28 : ${DGIT_TEST_DEBUG=-D}
29 export DGIT_TEST_DEBUG
30
31 export GIT_COMMITTER_DATE='1440253867 +0100'
32 export GIT_AUTHOR_DATE='1440253867 +0100'
33
34 root=`pwd`
35 troot=$root/tests
36 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
37
38 tmp=$ADTTMP
39 if [ x"$tmp" = x ]; then
40         mkdir -p tests/tmp
41         tmpbase=$troot/tmp
42         tmp=tests/tmp/$testname
43         rm -rf $tmp
44         mkdir $tmp
45 fi
46 cd $tmp
47
48 tmp=`pwd`
49
50 t-set-using-tmp
51
52 env -0 >$tmp/.save-env
53
54 ln -f $troot/ssh ssh
55
56 mkdir -p $tmp/gnupg
57 cp $troot/gnupg/* $tmp/gnupg
58 chmod go-rw $tmp/gnupg/*
59
60 export DEBCHANGE_VENDOR=dpkg
61
62 mkdir -p $tmp/incoming
63 cat <<END >$tmp/dput.cf
64 [test-dummy]
65 method                  = local
66 incoming                = $tmp/incoming
67 run_dinstall            = 0
68 END
69
70 : ${tagpfx:=test-dummy}
71 : ${suitespecs:=sid:unstable}
72
73 t-git-next-date () {
74         GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
75         GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
76 }
77
78 t-expect-fail () {
79         local mpat="$1"; shift
80
81         set +o pipefail
82         LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
83         local ps="${PIPESTATUS[*]}"
84         set -o pipefail
85
86         case $ps in
87         "0 0")  fail "command unexpectedly succeeded (instead of: $mpat)" ;;
88         *" 0")  ;;
89         *)      fail "tee failed"  ;;
90         esac
91
92         t-grep-mpat "$mpat" $tmp/t.output
93 }
94
95 t-grep-mpat () {
96         local mpat="$1"
97         local file="$2"
98
99         local grepper=fgrep
100         case "$mpat" in
101         [A-Z]:*)
102                 case "$mpat" in
103                 E:*)    grepper=egrep   ;;
104                 F:*)    grepper=fgrep   ;;
105                 *)      fail "bad mpat prefix in $mpat";;
106                 esac
107                 mpat=${mpat#[A-Z]:}
108                 ;;
109         esac
110
111         $grepper -e "$mpat" "$file" ||
112                 fail "message not found"
113 }
114
115 t-expect-push-fail () {
116         local mpat="$1"; shift
117
118         local triedpush=`git rev-parse HEAD`
119
120         t-reporefs pre-push
121         t-expect-fail "$mpat"  "$@"
122         t-reporefs post-push
123         diff $tmp/show-refs.{pre,post}-push
124
125         t-git-objects-not-present '' $triedpush
126
127         eval "$t_expect_push_fail_hook"
128 }
129
130 t-git-objects-not-present () {
131         # t-git-objects-not-present GITDIR|'' OBJID [...]
132         # specifying '' means the repo for package $p
133         local gitdir="${1-$dgitrepo}"
134         local obj
135         if ! [ -e "$gitdir" ]; then return; fi
136         for obj in "$@"; do
137                 GIT_DIR=$gitdir \
138                 t-expect-fail 'unable to find' \
139                 git cat-file -t $obj
140         done
141 }
142
143 t-reporefs () {
144         local whichoutput=$1; shift
145         local whichrepo=${1-$dgitrepo}
146         local outputfile="$tmp/show-refs.$whichoutput"
147         (set -e
148          exec >"$outputfile"
149          if test -d $whichrepo; then
150                 cd $whichrepo
151                 git show-ref |sort
152         fi)
153 }
154
155 t-untar () {
156         local tarfile=$1.tar
157         local edittree=$1.edit
158         if test -d "$edittree"; then
159                 cp -a "$edittree"/* .
160         else
161                 tar xf "$tarfile"
162         fi
163 }
164
165 t-worktree () {
166         rm -rf $p
167         t-untar $troot/worktrees/${p}_$1
168 }
169
170 t-select-package () {
171         p=$1
172         dgitrepo=$tmp/git/$p.git
173 }
174
175 t-git () {
176         t-select-package $1
177         v=$2
178         mkdir -p $tmp/git
179         local gs=$troot/git-srcs/${p}_$v.git
180         (set -e; cd $tmp/git; t-untar $gs)
181 }
182
183 t-git-none () {
184         mkdir -p $tmp/git
185         (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
186 }
187
188 t-git-merge-base () {
189         git merge-base $1 $2 || test $? = 1
190 }
191
192 t-has-ancestor () {
193         local now=`git rev-parse HEAD`
194         local ancestor=`git rev-parse $1^{}`
195         local mbase=`t-git-merge-base $ancestor $now`
196         if [ x$mbase != x$ancestor ]; then
197                 fail "not ff $ancestor..$now, $mbase != $ancestor"
198         fi
199 }
200
201 t-prep-newpackage () {
202         t-select-package $1
203         v=$2
204         t-archive-none $p
205         t-git-none
206         t-worktree $v
207         cd $p
208         if ! git show-ref --verify --quiet refs/heads/master; then
209                 git branch -m dgit/sid master
210                 git remote rm dgit
211         fi
212         cd ..
213 }
214
215 t-archive-none () {
216         t-select-package $1
217         mkdir -p $tmp/aq/dsc_in_suite $tmp/mirror/pool/main
218
219         : >$tmp/aq/suites
220         local jsondelim="["
221
222         local suitespec
223         for suitespec in $suitespecs; do
224                 local suite=${suitespec%%:*}
225                 local sname=${suitespec#*:}
226
227                 >$tmp/aq/package.$suite.$p
228                 t-archive-updated $suite $p
229
230                 >$tmp/aq/package.new.$p
231                 t-archive-updated new $p
232
233                 ln -sf $suite $tmp/aq/dsc_in_suite/$sname
234
235                 cat <<END >>$tmp/aq/suites
236 $jsondelim
237    {
238       "archive" : "ftp-master",
239       "codename" : "$suite",
240       "components" : [
241          "main",
242          "contrib",
243          "non-free"
244       ],
245       "name" : "$sname",
246       "dakname" : "$sname"
247 END
248
249                 jsondelim="   },"
250
251         done
252         cat <<END >>$tmp/aq/suites
253     }
254 ]
255 END
256 }
257
258 t-archive-updated () {
259         local suite=$1
260         local p=$2
261         local suitedir=$tmp/aq/dsc_in_suite/$suite
262         mkdir -p $suitedir
263         perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
264                 use JSON;
265                 use strict;
266                 our @v;
267                 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
268                 push @v, {
269                         "version" => "$1",
270                         "sha256sum" => "$2",
271                         "component" => "$3",
272                         "filename" => "$4",
273                 };
274                 END {
275                         my $json = JSON->new->canonical();
276                         print $json->encode(\@v) or die $!;
277                 }
278         '
279 }
280
281 t-archive-process-incoming () {
282         local suite=$1
283         mv $tmp/incoming/${p}_${v}[._]* $tmp/mirror/pool/main/
284         t-archive-query "$suite"
285 }
286
287 t-archive-query () {
288         local suite=${1-sid}
289         local dscf=main/${p}_${v}.dsc
290         local sha=`sha256sum <$tmp/mirror/pool/$dscf`
291         echo "${v} ${sha%  -} $dscf" >>$tmp/aq/package.$suite.${p}
292         t-archive-updated $suite $p
293 }
294
295 t-archive () {
296         t-archive-none $1
297         v=$2
298         local dscf=${p}_$2.dsc
299         rm -f $tmp/mirror/pool/main/${p}_*
300         ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
301         t-archive-query
302         rm -rf $tmp/extract
303         mkdir $tmp/extract
304         (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
305 }
306
307 t-git-dir-time-passes () {
308         touch -d 'last year' $dgitrepo
309 }
310
311 t-git-dir-check () {
312         local gitdir=$dgitrepo
313         case "$1" in
314         enoent)
315                 if test -e "$gitdir"; then fail "$gitdir exists"; fi
316                 return
317                 ;;
318         public) wantstat='7[75]5' ;;
319         secret) wantstat='7[70]0' ;;
320         *)      fail "$1 t-git-dir-check ?" ;;
321         esac
322         gotstat=`stat -c%a $gitdir`
323         case "$gotstat" in
324         *$wantstat) return ;;
325         *)      fail "$gitdir has mode $gotstat, expected $wantstat" ;;
326         esac
327 }
328
329 t-rm-dput-dropping () {
330         rm -f $tmp/${p}_${v}_*.upload
331 }
332
333 t-dgit () {
334         local dgit=${DGIT_TEST-dgit}
335         pwd
336         : '
337 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
338         $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
339                 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
340                 -k39B13D8A $t_dgit_xopts "$@"
341         : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
342 '
343 }
344
345 t-diff-nogit () {
346         diff --exclude=.git --exclude=.pc -ruN $*
347 }
348
349 t-files-notexist () {
350         local f
351         for f in "$@"; do
352                 if [ -e $f ]; then
353                         fail "$f exists!"
354                 fi
355         done
356 }
357
358 t-cloned-fetched-good () {
359         t-diff-nogit ../extract/$p-${v%-*} .
360         t-clean-on-branch dgit/sid
361         t-refs-same-start
362         t-refs-same \
363                 refs/heads/dgit/sid \
364                 refs/remotes/dgit/dgit/sid
365         t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
366 }
367
368 t-output () {
369         printf "%s${1:+\n}" "$1" >$tmp/t.want
370         shift
371         "$@" >$tmp/t.got
372         diff $tmp/t.want $tmp/t.got
373 }
374
375 t-clean-on-branch () {
376         t-output "## $1" git status -b --porcelain
377 }
378
379 t-setup-done () {
380         local savevars=$1
381         local savedirs=$2
382         local importeval=$3
383
384         local import=IMPORT.${0##*/}
385         exec 4>$tmp/$import.new
386
387         local vn
388         for vn in $savevars; do
389                 perl >&4 -I. -MDebian::Dgit -e '
390                         printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
391                 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
392         done
393
394         (set -e; cd $tmp; tar cf $import.tar $savedirs)
395
396         printf >&4 "\n%s\n" "$importeval"
397
398         mv -f $tmp/$import.new $tmp/$import
399 }
400
401 t-setup-import () {
402         local setupname=$1
403
404         local setupsrc
405         local lock
406         if [ "x$tmpbase" = x ]; then
407                 # ADTTMP was set on entry to tests/lib, so we
408                 # are not sharing tmp area between tests
409                 setupsrc="$tmp"
410                 lock="$tmp/.dummy.lock"
411         else
412                 setupsrc="$tmpbase/$setupname"
413                 lock="$setupsrc.lock"
414         fi
415
416         local simport="$setupsrc/IMPORT.$setupname"
417
418         if ! [ -e "$simport" ]; then
419                 with-lock-ex -w "$lock" \
420                 xargs -0 -a $tmp/.save-env \
421                 bash -xec '
422                         cd "$1"; shift
423                         setupname="$1"; shift
424                         simport="$1"; shift
425                         if [ -e "$simport" ]; then exit 0; fi
426                         env - "$@" \
427                         "tests/setup/$setupname"
428                 ' x "$root" "$setupname" "$simport"
429         fi
430
431         if [ "x$setupsrc" != "x$tmp" ]; then
432                 (set -e; cd $tmp; tar xf "$simport.tar")
433         fi
434
435         . "$simport"
436 }
437
438 t-git-get-ref-exact () {
439         local ref=$1
440         # does not dereference, unlike t-git-get-ref
441         case "$ref" in
442         refs/*) ;;
443         *) fail "t-git-get-ref-exact bad $ref" ;;
444         esac
445         git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
446 }
447
448 t-git-get-ref () {
449         local ref=$1
450         case "$ref" in
451         refs/*) ;;
452         *) fail "t-git-get-ref bad $ref" ;;
453         esac
454         (git show-ref -d $1 || test $? = 1) | perl -ne '
455                 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
456                 END { print "$x\n" if length $x; }
457         '
458 }
459
460 t-ref-same-exact () {
461         local name="$1"
462         local val=`t-git-get-ref-exact $name`
463         t-ref-same-val "$name" $val
464 }
465
466 t-ref-same () {
467         local name="$1"
468         local val=`t-git-get-ref $name`
469         t-ref-same-val "$name" $val
470 }
471
472 t-ref-head () {
473         local val=`git rev-parse HEAD`
474         t-ref-same-val HEAD $val
475 }
476
477 t-ref-same-val () {
478         local name="$1"
479         local val=$2
480         case "$t_ref_val" in
481         '')             ;;
482         "$val")         ;;
483         *)              fail "ref varies: $name:\
484  ${val:-nothing} != ${t_ref_val:-nothing}" ;;
485         esac
486         t_ref_val="$val"
487 }
488
489 t-refs-same-start () {
490         t_ref_val=''
491 }
492
493 t-refs-same () {
494         local g
495         for g in $*; do
496                 t-ref-same $g
497         done
498 }
499
500 t-refs-notexist () {
501         local val
502         for g in $*; do
503                 val=`t-git-get-ref $g`
504                 if [ "x$val" != x ]; then
505                         fail "ref $g unexpectedly exists ($val)"
506                 fi
507         done
508 }
509
510 t-v-tag () {
511         echo refs/tags/$tagpfx/${v//\~/_}
512 }
513
514 t-format-ref () {
515         git log -n1 --pretty=format:"$1" "$2"
516 }
517
518 t-sametree-parent () {
519         local ref=$1
520         local parent
521         local ctree=$(t-format-ref '%T' "$ref")
522         while :; do
523                 local psame=''
524                 for parent in $(t-format-ref '%P' "$ref"); do
525                         local ptree=$(t-format-ref '%T' "$parent")
526                         if [ "x$ptree" = "x$ctree" ]; then
527                                 psame+=" $parent"
528                         fi
529                 done
530                 case "$psame" in ""|" * *") break ;; esac
531                 ref="${psame# }"
532         done
533         echo "$ref"
534 }
535
536 t-check-pushed-master () {
537         local master=`t-git-get-ref refs/heads/master`
538         if [ x$master = x$t_ref_val ]; then return; fi
539         if [ x$master = x ]; then fail "failed to push master"; fi
540         # didn't update master, it must be not FF
541         local mbase=`t-git-merge-base $master $t_ref_val`
542         if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
543 }
544
545 t-pushed-good () {
546         local branch=$1
547         local suite=${2:-sid}
548         t-refs-same \
549                 refs/heads/$branch
550         t-pushed-good-core
551 }
552         
553 t-pushed-good-core () {
554         t-ref-dsc-dgit
555         t-refs-same \
556                 `t-v-tag` \
557                 refs/remotes/dgit/dgit/$suite
558         t-refs-notexist \
559                 refs/heads/dgit/unstable \
560                 refs/remotes/dgit/dgit/unstable
561         (set -e; cd $dgitrepo
562          t-refs-same \
563                 refs/dgit/$suite \
564                 `t-v-tag`
565          ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
566          t-refs-notexist \
567                 refs/dgit/unstable
568         )
569         git verify-tag `t-v-tag`
570 }
571
572 t-splitbrain-pushed-good--unpack () {
573         cd $tmp
574         rm -rf t-unpack
575         mkdir t-unpack
576         cd t-unpack
577         ln -s $tmp/mirror/pool/main/*.orig*.tar* .
578         ln -s $incoming_dsc .
579         ln -s ${incoming_dsc/.dsc/.debian.tar}* .
580         dpkg-source "$@" -x *.dsc
581         cd */.
582         git init
583         git fetch ../../$p "refs/tags/*:refs/tags/*"
584 }
585
586 t-splitbrain-pushed-good--checkprep () {
587         git add -Af .
588         git rm --cached -r --ignore-unmatch .pc
589 }
590
591 t-splitbrain-pushed-good--checkdiff () {
592         local tag=$1
593         t-splitbrain-pushed-good--checkprep
594         t-output "" git diff --stat --cached $tag
595 }
596
597 t-splitbrain-pushed-good-start () {
598         dep14tag=refs/tags/test-dummy/${v//\~/_}
599         dgittag=$(t-v-tag)
600         t-output "" git status --porcelain
601         t-ref-head
602         t-refs-same $dep14tag
603         (set -e; cd $dgitrepo; t-refs-same $dep14tag)
604         git merge-base --is-ancestor $dep14tag $dgittag
605
606         t-refs-same-start
607         t-pushed-good-core
608
609         t-incoming-dsc
610
611         t-splitbrain-pushed-good--unpack
612         t-splitbrain-pushed-good--checkdiff $dgittag
613 }
614 t-splitbrain-pushed-good-end-made-dep14 () {
615         t-splitbrain-pushed-good--checkdiff $dep14tag
616         cd $tmp/$p
617 }
618
619 t-splitbrain-rm-gitignore-patch () {
620         perl -i -pe '
621                 next unless $_ eq "auto-gitignore\n";
622                 die if $counter++;
623                 chomp;
624                 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
625                 $_ = "";
626         ' debian/patches/series
627 }
628
629 t-gbp-pushed-good () {
630         local suite=${1:-sid}
631         t-splitbrain-pushed-good-start
632
633         # Right, now we want to check that the maintainer tree and
634         # the dgit tree differ in exactly the ways we expect.  We
635         # achieve this by trying to reconstruct the maintainer tree
636         # from the dgit tree.
637
638         # So, unpack it withut the patches applied
639         t-splitbrain-pushed-good--unpack --skip-patches
640
641         # dgit might have added a .gitignore patch, which we need to
642         # drop and remove
643         t-splitbrain-rm-gitignore-patch
644
645         # Now the result should differ only in non-debian/ .gitignores
646         t-splitbrain-pushed-good--checkprep
647         git diff --cached --name-only $dep14tag >../changed
648         perl -ne '
649                 next if !m#^debian/# && m#(^|/)\.gitignore#;
650                 die "$_ mismatch";
651         ' <../changed
652
653         # If we actually apply the gitignore patch by hand, it
654         # should be perfect:
655         if [ -f ../t-auto-gitignore ]; then
656                 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
657         fi
658
659         t-splitbrain-pushed-good-end-made-dep14
660 }
661
662 t-unapplied-pushed-good () {
663         t-splitbrain-pushed-good-start
664         t-splitbrain-pushed-good--unpack --skip-patches
665         t-splitbrain-pushed-good-end-made-dep14
666 }
667
668 t-dpm-pushed-good () {
669         t-splitbrain-pushed-good-start
670         t-splitbrain-pushed-good--unpack
671         t-splitbrain-rm-gitignore-patch
672         t-splitbrain-pushed-good-end-made-dep14
673 }
674
675 t-commit-build-push-expect-log () {
676         local msg=$1
677         local mpat=$2
678         t-commit "$msg"
679         t-dgit build
680         LC_MESSAGES=C \
681         t-dgit push --new 2>&1 |tee $tmp/push.log
682         t-grep-mpat "$mpat" $tmp/push.log
683 }
684
685 t-822-field () {
686         local file=$1
687         local field=$2
688         perl -e '
689                 use Dpkg::Control::Hash;
690                 my $h = new Dpkg::Control::Hash allow_pgp=>1;
691                 $h->parse(\*STDIN,"'"$file"'");
692                 my $val = $h->{"'$field'"},"\n";
693                 die "'"$file $field"'" unless defined $val;
694                 print $val,"\n";
695         ' <$file
696 }
697
698 t-stunt-envvar () {
699         local var=$1
700         local tstunt=$2
701         eval '
702                 case "$'$var'" in
703                 "$tstunt:"*)    ;;
704                 *":$tstunt:"*)  ;;
705                 "")             '$var'="$tstunt" ;;
706                 *)              '$var'="$tstunt:$'$var'" ;;
707                 esac
708                 export '$var'
709         '
710 }
711
712 t-tstunt () {
713         local tstunt=$tmp/tstunt
714         t-stunt-envvar PATH $tstunt
715         t-stunt-envvar PERLLIB $tstunt
716         local f
717         for f in "$@"; do
718                 f="./$f"
719                 local d="$tstunt/${f%/*}"
720                 mkdir -p $d
721                 ln -sf "$troot/tstunt/$f" "$d"/.
722         done
723 }
724
725 t-tstunt-parsechangelog () {
726         t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
727 }
728
729 t-incoming-dsc () {
730         local dsc=${p}_${v}.dsc
731         incoming_dsc=$tmp/incoming/$dsc
732 }
733
734 t-ref-dsc-dgit () {
735         t-incoming-dsc
736         local val=`t-822-field $incoming_dsc Dgit`
737         perl -e '$_=shift @ARGV; die "Dgit $_ ?" unless m/^\w+\b/;' "$val"
738         t-ref-same-val $incoming_dsc "$val"
739 }
740
741 t-apply-diff () {
742         local v1=$1
743         local v2=$2
744         (cd $troot/pkg-srcs;
745          debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
746          | patch -p1 -u
747 }
748
749 t-gbp-unapplied-pq2qc () {
750         # does `gbp pq export'
751         # commits the resulting debian/patches on  qc/BRANCH
752         # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
753         # qc/BRANCH is not fast-forwarding
754
755         gbp pq export
756
757         branch=`git symbolic-ref HEAD`
758         branch=${branch#refs/heads/}
759
760         case "$branch" in
761         */*) fail "unexpected branch $branch" ;;
762         esac
763
764         git branch -f qc/$branch
765         git checkout qc/$branch
766         git add debian/patches
767         git commit -m 'Commit patch queue'
768 }
769
770 t-git-pseudo-merge () {
771         # like   git merge -s ours
772         if [ ! "$git_pseuomerge_opts" ]; then
773                 if git merge --help \
774                  | grep -q allow-unrelated-histories; then
775                         git_pseuomerge_opts='--allow-unrelated-histories'
776                 fi
777                 git_pseuomerge_opts+=' -s ours'
778         fi
779         git merge $git_pseuomerge_opts "$@"
780 }
781
782 t-gbp-example-prep-no-ff () {
783         t-tstunt-parsechangelog
784         t-archive example 1.0-1
785         t-git-none
786         t-worktree 1.0
787
788         cd example
789
790         t-dgit fetch
791
792         git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
793         gbp pq rebase
794
795         echo '/* some comment */' >>src.c
796         git add src.c
797         git commit -m 'Add a comment to an upstream file'
798
799         t-gbp-unapplied-pq2qc
800
801         t-commit 'some updates' 1.0-2
802 }
803
804 t-gbp-example-prep () {
805         t-gbp-example-prep-no-ff
806
807         t-git-pseudo-merge \
808                 -m 'Pseudo-merge to make descendant of archive' \
809                 remotes/dgit/dgit/sid
810 }
811
812 t-commit () {
813         local msg=$1
814         v=${2:-${majorv:-1}.$revision}
815         dch -v$v --distribution ${3:-unstable} "$1"
816         git add debian/changelog
817         debcommit
818         revision=$(( ${revision-0} + 1 ))
819 }
820
821 t-git-config () {
822         git config --global "$@"
823 }
824
825 t-drs () {
826         export DGIT_TEST_TROOT=$troot
827  t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
828  t-git-config dgit-distro.test-dummy.git-check true
829  t-git-config dgit-distro.test-dummy.git-create true
830  t-git-config dgit-distro.test-dummy.dgit-tag-format old,new
831         cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
832         cp $troot/suites $tmp/.
833         cp $troot/suites $tmp/suites-master
834
835         export t_check_pushed_master=t-check-pushed-master
836
837         drs_dispatch=$tmp/distro=test-dummy
838         mkdir $drs_dispatch
839
840         if [ "x$DGIT_TEST_INTREE" != x ]; then
841                 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
842         fi
843
844         ln -sf $tmp/git $drs_dispatch/repos
845         ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
846         mkdir -p $drs_dispatch/keyrings
847         ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
848         ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
849         ln -sf /bin/true $drs_dispatch/policy-hook
850 }
851
852 t-newtag () {
853  export tagpfx=archive/test-dummy
854  t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
855 }
856 t-oldtag () {
857  t-git-config dgit-distro.test-dummy.dgit-tag-format old
858 }
859
860 t-dsd () {
861         t-drs
862  t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
863  t-git-config dgit-distro.test-dummy.git-check ssh-cmd
864  t-git-config dgit-distro.test-dummy.git-create true
865  t-git-config dgit-distro.test-dummy.git-url \
866                 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
867
868  t-git-config dgit-distro.test-dummy.diverts.drs /drs
869  t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
870  t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
871  t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
872  t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
873
874         echo 'no-such-package* drs' >$drs_dispatch/diverts
875 }
876
877 t-policy-admin () {
878         ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
879 }
880
881 t-policy-nonexist () {
882         ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
883 }
884
885 t-make-hook-link () {
886         local hook=$1 # in infra/
887         local linkpath=$2
888         hook=${DGIT_INFRA_PFX}$hook
889         case $hook in
890         */*)    ;;
891         *)      hook=`type -P $hook` ;;
892         esac
893         ln -sf "$hook" $linkpath
894 }
895
896 t-policy () {
897         local policyhook=$1
898         t-make-hook-link $policyhook $drs_dispatch/policy-hook
899 }
900
901 t-debpolicy () {
902         t-dsd
903         t-policy dgit-repos-policy-debian
904
905         mkdir $tmp/git
906         t-policy-admin create-db
907 }
908
909 t-policy-periodic () {
910         ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
911                 test-dummy $drs_dispatch '' --cron
912 }
913
914 t-restrict () {
915         local restriction=$1
916         (cd $root; t-restriction-$restriction >&2)
917 }
918
919 t-dependencies () {
920         : "Hopefully installed: $*"
921 }
922
923 t-chain-test () {
924         local ct=$1
925         local d=${0%/*}
926         cd $root
927         export DGIT_TEST_TESTNAME="$testname"
928         export ADTTMP=$tmp
929         exec "$d/$ct"
930 }       
931
932 t-alt-test () {
933         local t=${0##*/}
934         t-${t%%-*}
935         t-chain-test "${t#*-}"
936 }