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