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