12 : ${DGIT_TEST_DEBUG=-D}
13 export DGIT_TEST_DEBUG
15 export GIT_COMMITTER_DATE='1440253867 +0100'
16 export GIT_AUTHOR_DATE='1440253867 +0100'
20 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
23 if [ x"$tmp" = x ]; then
25 tmp=tests/tmp/$testname
38 cp $troot/gnupg/* $tmp/gnupg
39 chmod go-rw $tmp/gnupg/*
41 export DEBCHANGE_VENDOR=dpkg
43 mkdir -p $tmp/incoming
44 cat <<END >$tmp/dput.cf
47 incoming = $tmp/incoming
52 GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
53 GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
57 local mpat="$1"; shift
60 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
61 local ps="${PIPESTATUS[*]}"
65 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
67 *) fail "tee failed" ;;
70 t-grep-mpat "$mpat" $tmp/t.output
83 *) fail "bad mpat prefix in $mpat";;
89 $grepper -e "$mpat" "$file" ||
90 fail "message not found"
93 t-expect-push-fail () {
94 local mpat="$1"; shift
96 local triedpush=`git rev-parse HEAD`
99 t-expect-fail "$mpat" "$@"
101 diff $tmp/show-refs.{pre,post}-push
103 t-git-objects-not-present '' $triedpush
105 eval "$t_expect_push_fail_hook"
108 t-git-objects-not-present () {
109 # t-git-objects-not-present GITDIR|'' OBJID [...]
110 # specifying '' means the repo for package $p
111 local gitdir="${1-$dgitrepo}"
113 if ! [ -e "$gitdir" ]; then return; fi
116 t-expect-fail 'unable to find' \
122 local whichoutput=$1; shift
123 local whichrepo=${1-$dgitrepo}
124 local outputfile="$tmp/show-refs.$whichoutput"
127 if test -d $whichrepo; then
135 local edittree=$1.edit
136 if test -d "$edittree"; then
137 cp -a "$edittree"/* .
145 t-untar $troot/worktrees/${p}_$1
148 t-select-package () {
150 dgitrepo=$tmp/git/$p.git
157 local gs=$troot/git-srcs/${p}_$v.git
158 (set -e; cd $tmp/git; t-untar $gs)
163 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
166 t-git-merge-base () {
167 git merge-base $1 $2 || test $? = 1
171 local now=`git rev-parse HEAD`
172 local ancestor=`git rev-parse $1^{}`
173 local mbase=`t-git-merge-base $ancestor $now`
174 if [ x$mbase != x$ancestor ]; then
175 fail "not ff $ancestor..$now, $mbase != $ancestor"
179 t-prep-newpackage () {
186 if ! git show-ref --verify --quiet refs/heads/master; then
187 git branch -m dgit/sid master
195 mkdir -p $tmp/aq $tmp/mirror/pool/main
199 >$tmp/aq/package.$suite.$p
200 t-archive-updated $suite $p
202 >$tmp/aq/package.new.$p
203 t-archive-updated new $p
205 ln -s sid $tmp/aq/dsc_in_suite/unstable
206 cat <<'END' >$tmp/aq/suites
209 "archive" : "ftp-master",
217 "dakname" : "unstable"
223 t-archive-updated () {
226 local suitedir=$tmp/aq/dsc_in_suite/$suite
228 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
232 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
240 print to_json \@v or die $!;
245 t-archive-process-incoming () {
247 mv $tmp/incoming/${p}_${v}[._]* $tmp/mirror/pool/main/
248 t-archive-query "$suite"
253 local dscf=main/${p}_${v}.dsc
254 local sha=`sha256sum <$tmp/mirror/pool/$dscf`
255 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
256 t-archive-updated $suite $p
262 local dscf=${p}_$2.dsc
263 rm -f $tmp/mirror/pool/main/${p}_*
264 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
268 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
271 t-git-dir-time-passes () {
272 touch -d 'last year' $dgitrepo
276 local gitdir=$dgitrepo
279 if test -e "$gitdir"; then fail "$gitdir exists"; fi
282 public) wantstat='7[75]5' ;;
283 secret) wantstat='7[70]0' ;;
284 *) fail "$1 t-git-dir-check ?" ;;
286 gotstat=`stat -c%a $gitdir`
288 *$wantstat) return ;;
289 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
293 t-rm-dput-dropping () {
294 rm -f $tmp/${p}_${v}_*.upload
298 local dgit=${DGIT_TEST-dgit}
301 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
302 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
303 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
305 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
310 diff --exclude=.git --exclude=.pc -ruN $*
313 t-files-notexist () {
322 t-cloned-fetched-good () {
323 t-diff-nogit ../extract/$p-${v%-*} .
324 t-clean-on-branch dgit/sid
327 refs/heads/dgit/sid \
328 refs/remotes/dgit/dgit/sid
329 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
333 printf "%s\n" "$1" >$tmp/t.want
336 diff $tmp/t.want $tmp/t.got
339 t-clean-on-branch () {
340 t-output "## $1" git status -b --porcelain
343 t-git-get-ref-exact () {
345 # does not dereference, unlike t-git-get-ref
348 *) fail "t-git-get-ref-exact bad $ref" ;;
350 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
357 *) fail "t-git-get-ref bad $ref" ;;
359 (git show-ref -d $1 || test $? = 1) | perl -ne '
360 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
361 END { print "$x\n" if length $x; }
365 t-ref-same-exact () {
367 local val=`t-git-get-ref-exact $name`
368 t-ref-same-val "$name" $val
373 local val=`t-git-get-ref $name`
374 t-ref-same-val "$name" $val
378 local val=`git rev-parse HEAD`
379 t-ref-same-val HEAD $val
388 *) fail "ref varies: $name: $val != $t_ref_val" ;;
393 t-refs-same-start () {
407 val=`t-git-get-ref $g`
408 if [ "x$val" != x ]; then
409 fail "ref $g unexpectedly exists ($val)"
415 echo refs/tags/test-dummy/${v//\~/_}
418 t-check-pushed-master () {
419 local master=`t-git-get-ref refs/heads/master`
420 if [ x$master = x$t_ref_val ]; then return; fi
421 if [ x$master = x ]; then fail "failed to push master"; fi
422 # didn't update master, it must be not FF
423 local mbase=`t-git-merge-base $master $t_ref_val`
424 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
433 refs/remotes/dgit/dgit/sid
435 refs/heads/dgit/unstable \
436 refs/remotes/dgit/dgit/unstable
437 (set -e; cd $dgitrepo
441 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
445 git verify-tag `t-v-tag`
448 t-commit-build-push-expect-log () {
454 t-dgit push --new 2>&1 |tee $tmp/push.log
455 t-grep-mpat "$mpat" $tmp/push.log
462 use Dpkg::Control::Hash;
463 my $h = new Dpkg::Control::Hash allow_pgp=>1;
464 $h->parse(\*STDIN,"'"$file"'");
465 my $val = $h->{"'$field'"},"\n";
466 die "'"$file $field"'" unless defined $val;
478 *) '$var'="$tstunt:$'$var'" ;;
484 local tstunt=$tmp/tstunt
485 t-stunt-envvar PATH $tstunt
486 t-stunt-envvar PERLLIB $tstunt
490 local d="$tstunt/${f%/*}"
492 ln -sf "$troot/tstunt/$f" "$d"/.
496 t-tstunt-parsechangelog () {
497 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
501 local dsc=${p}_${v}.dsc
502 local val=`t-822-field $tmp/incoming/$dsc Dgit`
503 perl -e '$_=shift @ARGV; die "$dsc Dgit $_ ?" unless m/^\w+\b/;' "$val"
504 t-ref-same-val $dsc "$val"
511 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
515 t-gbp-unapplied-pq2qc () {
516 # does `gbp pq export'
517 # commits the resulting debian/patches on qc/BRANCH
518 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
519 # qc/BRANCH is not fast-forwarding
523 branch=`git symbolic-ref HEAD`
524 branch=${branch#refs/heads/}
527 */*) fail "unexpected branch $branch" ;;
530 git branch -f qc/$branch
531 git checkout qc/$branch
532 git add debian/patches
533 git commit -m 'Commit patch queue'
536 t-gbp-example-prep () {
537 t-archive example 1.0-1
545 git-checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
548 echo '/* some comment */' >>src.c
550 git commit -m 'Add a comment to an upstream file'
552 t-gbp-unapplied-pq2qc
554 t-commit 'some updates' 1.0-2
560 dch -v$v --distribution unstable "$1"
561 git add debian/changelog
563 revision=$(( ${revision-0} + 1 ))
567 git config --global "$@"
571 export DGIT_TEST_TROOT=$troot
572 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
573 t-git-config dgit-distro.test-dummy.git-check true
574 t-git-config dgit-distro.test-dummy.git-create true
575 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
576 cp $troot/suites $tmp/.
577 cp $troot/suites $tmp/suites-master
579 export t_check_pushed_master=t-check-pushed-master
581 drs_dispatch=$tmp/distro=test-dummy
584 if [ "x$DGIT_TEST_INTREE" != x ]; then
585 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
588 ln -sf $tmp/git $drs_dispatch/repos
589 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
590 mkdir -p $drs_dispatch/keyrings
591 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
592 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
593 ln -sf /bin/true $drs_dispatch/policy-hook
598 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
599 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
600 t-git-config dgit-distro.test-dummy.git-create true
601 t-git-config dgit-distro.test-dummy.git-url \
602 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
604 t-git-config dgit-distro.test-dummy.diverts.drs /drs
605 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
606 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
607 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
608 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
610 echo 'no-such-package* drs' >$drs_dispatch/diverts
614 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
617 t-policy-nonexist () {
618 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
621 t-make-hook-link () {
622 local hook=$1 # in infra/
624 hook=${DGIT_INFRA_PFX}$hook
627 *) hook=`type -P $hook` ;;
629 ln -sf "$hook" $linkpath
634 t-make-hook-link $policyhook $drs_dispatch/policy-hook
639 t-policy dgit-repos-policy-debian
642 t-policy-admin create-db
645 t-policy-periodic () {
646 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
647 test-dummy $drs_dispatch '' --cron
652 (cd $root; t-restriction-$restriction >&2)
656 : "Hopefully installed: $*"
663 export DGIT_TEST_TESTNAME="$testname"
671 t-chain-test "${t#*-}"