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