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