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