16 lines: ${BASH_LINENO[*]}
17 files: ${BASH_SOURCE[*]}
22 trap 'test $? = 0 || t-report-failure' EXIT
26 : ${DGIT_TEST_DEBUG=-D}
27 export DGIT_TEST_DEBUG
29 export GIT_COMMITTER_DATE='1440253867 +0100'
30 export GIT_AUTHOR_DATE='1440253867 +0100'
34 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
37 if [ x"$tmp" = x ]; then
40 tmp=tests/tmp/$testname
50 env -0 >$tmp/.save-env
55 cp $troot/gnupg/* $tmp/gnupg
56 chmod go-rw $tmp/gnupg/*
58 export DEBCHANGE_VENDOR=dpkg
60 mkdir -p $tmp/incoming
61 cat <<END >$tmp/dput.cf
64 incoming = $tmp/incoming
68 : ${tagpfx:=test-dummy}
69 : ${suitespecs:=sid:unstable}
72 GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
73 GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
77 local mpat="$1"; shift
80 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
81 local ps="${PIPESTATUS[*]}"
85 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
87 *) fail "tee failed" ;;
90 t-grep-mpat "$mpat" $tmp/t.output
101 E:*) grepper=egrep ;;
102 F:*) grepper=fgrep ;;
103 *) fail "bad mpat prefix in $mpat";;
109 $grepper -e "$mpat" "$file" ||
110 fail "message not found"
113 t-expect-push-fail () {
114 local mpat="$1"; shift
116 local triedpush=`git rev-parse HEAD`
119 t-expect-fail "$mpat" "$@"
121 diff $tmp/show-refs.{pre,post}-push
123 t-git-objects-not-present '' $triedpush
125 eval "$t_expect_push_fail_hook"
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}"
133 if ! [ -e "$gitdir" ]; then return; fi
136 t-expect-fail 'unable to find' \
142 local whichoutput=$1; shift
143 local whichrepo=${1-$dgitrepo}
144 local outputfile="$tmp/show-refs.$whichoutput"
147 if test -d $whichrepo; then
155 local edittree=$1.edit
156 if test -d "$edittree"; then
157 cp -a "$edittree"/* .
165 t-untar $troot/worktrees/${p}_$1
168 t-select-package () {
170 dgitrepo=$tmp/git/$p.git
177 local gs=$troot/git-srcs/${p}_$v.git
178 (set -e; cd $tmp/git; t-untar $gs)
183 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
186 t-git-merge-base () {
187 git merge-base $1 $2 || test $? = 1
191 local now=`git rev-parse HEAD`
192 local ancestor=`git rev-parse $1^{}`
193 local mbase=`t-git-merge-base $ancestor $now`
194 if [ x$mbase != x$ancestor ]; then
195 fail "not ff $ancestor..$now, $mbase != $ancestor"
199 t-prep-newpackage () {
206 if ! git show-ref --verify --quiet refs/heads/master; then
207 git branch -m dgit/sid master
215 mkdir -p $tmp/aq/dsc_in_suite $tmp/mirror/pool/main
221 for suitespec in $suitespecs; do
222 local suite=${suitespec%%:*}
223 local sname=${suitespec#*:}
225 >$tmp/aq/package.$suite.$p
226 t-archive-updated $suite $p
228 >$tmp/aq/package.new.$p
229 t-archive-updated new $p
231 ln -s $suite $tmp/aq/dsc_in_suite/$sname
233 cat <<END >>$tmp/aq/suites
236 "archive" : "ftp-master",
237 "codename" : "$suite",
250 cat <<END >>$tmp/aq/suites
256 t-archive-updated () {
259 local suitedir=$tmp/aq/dsc_in_suite/$suite
261 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
265 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
273 my $json = JSON->new->canonical();
274 print $json->encode(\@v) or die $!;
279 t-archive-process-incoming () {
281 mv $tmp/incoming/${p}_${v}[._]* $tmp/mirror/pool/main/
282 t-archive-query "$suite"
287 local dscf=main/${p}_${v}.dsc
288 local sha=`sha256sum <$tmp/mirror/pool/$dscf`
289 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
290 t-archive-updated $suite $p
296 local dscf=${p}_$2.dsc
297 rm -f $tmp/mirror/pool/main/${p}_*
298 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
302 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
305 t-git-dir-time-passes () {
306 touch -d 'last year' $dgitrepo
310 local gitdir=$dgitrepo
313 if test -e "$gitdir"; then fail "$gitdir exists"; fi
316 public) wantstat='7[75]5' ;;
317 secret) wantstat='7[70]0' ;;
318 *) fail "$1 t-git-dir-check ?" ;;
320 gotstat=`stat -c%a $gitdir`
322 *$wantstat) return ;;
323 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
327 t-rm-dput-dropping () {
328 rm -f $tmp/${p}_${v}_*.upload
332 local dgit=${DGIT_TEST-dgit}
335 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
336 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
337 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
338 -k39B13D8A $t_dgit_xopts "$@"
339 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
344 diff --exclude=.git --exclude=.pc -ruN $*
347 t-files-notexist () {
356 t-cloned-fetched-good () {
357 t-diff-nogit ../extract/$p-${v%-*} .
358 t-clean-on-branch dgit/sid
361 refs/heads/dgit/sid \
362 refs/remotes/dgit/dgit/sid
363 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
367 printf "%s${1:+\n}" "$1" >$tmp/t.want
370 diff $tmp/t.want $tmp/t.got
373 t-clean-on-branch () {
374 t-output "## $1" git status -b --porcelain
382 exec 4>$tmp/IMPORT.new
385 for vn in $savevars; do
386 perl >&4 -I. -MDebian::Dgit -e '
387 printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
388 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
391 (set -e; cd $tmp; tar cf IMPORT.tar $savedirs)
393 printf >&4 "\n%s\n" "$importeval"
395 mv -f $tmp/IMPORT.new $tmp/IMPORT
403 if [ "x$tmpbase" = x ]; then
404 # ADTTMP was set on entry to tests/lib, so we
405 # are not sharing tmp area between tests
407 lock="$tmp/.dummy.lock"
409 setupsrc="$tmpbase/$setupname"
410 lock="$setupsrc.lock"
413 local simport="$setupsrc/IMPORT"
415 if ! [ -e "$simport" ]; then
416 with-lock-ex -w "$lock" \
417 xargs -0 -a $tmp/.save-env \
420 setupname="$1"; shift
422 if [ -e "$simport" ]; then exit 0; fi
424 "tests/setup/$setupname"
425 ' x "$root" "$setupname" "$simport"
428 if [ "x$setupsrc" != "x$tmp" ]; then
429 (set -e; cd $tmp; tar xf "$simport.tar")
435 t-git-get-ref-exact () {
437 # does not dereference, unlike t-git-get-ref
440 *) fail "t-git-get-ref-exact bad $ref" ;;
442 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
449 *) fail "t-git-get-ref bad $ref" ;;
451 (git show-ref -d $1 || test $? = 1) | perl -ne '
452 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
453 END { print "$x\n" if length $x; }
457 t-ref-same-exact () {
459 local val=`t-git-get-ref-exact $name`
460 t-ref-same-val "$name" $val
465 local val=`t-git-get-ref $name`
466 t-ref-same-val "$name" $val
470 local val=`git rev-parse HEAD`
471 t-ref-same-val HEAD $val
480 *) fail "ref varies: $name:\
481 ${val:-nothing} != ${t_ref_val:-nothing}" ;;
486 t-refs-same-start () {
500 val=`t-git-get-ref $g`
501 if [ "x$val" != x ]; then
502 fail "ref $g unexpectedly exists ($val)"
508 echo refs/tags/$tagpfx/${v//\~/_}
512 git log -n1 --pretty=format:"$1" "$2"
515 t-sametree-parent () {
518 local ctree=$(t-format-ref '%T' "$ref")
521 for parent in $(t-format-ref '%P' "$ref"); do
522 local ptree=$(t-format-ref '%T' "$parent")
523 if [ "x$ptree" = "x$ctree" ]; then
527 case "$psame" in ""|" * *") break ;; esac
533 t-check-pushed-master () {
534 local master=`t-git-get-ref refs/heads/master`
535 if [ x$master = x$t_ref_val ]; then return; fi
536 if [ x$master = x ]; then fail "failed to push master"; fi
537 # didn't update master, it must be not FF
538 local mbase=`t-git-merge-base $master $t_ref_val`
539 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
544 local suite=${2:-sid}
550 t-pushed-good-core () {
554 refs/remotes/dgit/dgit/$suite
556 refs/heads/dgit/unstable \
557 refs/remotes/dgit/dgit/unstable
558 (set -e; cd $dgitrepo
562 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
566 git verify-tag `t-v-tag`
569 t-gbp-pushed-good--unpack () {
574 ln -s $tmp/mirror/pool/main/*.orig*.tar* .
575 ln -s $incoming_dsc .
576 ln -s ${incoming_dsc/.dsc/.debian.tar}* .
577 dpkg-source "$@" -x *.dsc
580 git fetch ../../$p "refs/tags/*:refs/tags/*"
583 t-gbp-pushed-good--checkprep () {
585 git rm --cached -r --ignore-unmatch .pc
588 t-gbp-pushed-good--checkdiff () {
590 t-gbp-pushed-good--checkprep
591 t-output "" git diff --stat --cached $tag
594 t-gbp-pushed-good () {
595 local suite=${1:-sid}
596 local dep14tag=refs/tags/test-dummy/${v//\~/_}
597 local dgittag=$(t-v-tag)
598 t-output "" git status --porcelain
600 t-refs-same $dep14tag
601 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
602 git merge-base --is-ancestor $dep14tag $dgittag
609 t-gbp-pushed-good--unpack
610 t-gbp-pushed-good--checkdiff $dgittag
612 # Right, now we want to check that the maintainer tree and
613 # the dgit tree differ in exactly the ways we expect. We
614 # achieve this by trying to reconstruct the maintainer tree
615 # from the dgit tree.
617 # So, unpack it withut the patches applied
618 t-gbp-pushed-good--unpack --skip-patches
620 # dgit might have added a .gitignore patch, which we need to
623 next unless $_ eq "auto-gitignore\n";
626 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
628 ' debian/patches/series
630 # Now the result should differ only in non-debian/ .gitignores
631 t-gbp-pushed-good--checkprep
632 git diff --cached --name-only $dep14tag >../changed
634 next if !m#^debian/# && m#(^|/)\.gitignore#;
638 # If we actually apply the gitignore patch by hand, it
640 if [ -f ../t-auto-gitignore ]; then
641 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
643 t-gbp-pushed-good--checkdiff $dep14tag
648 t-commit-build-push-expect-log () {
654 t-dgit push --new 2>&1 |tee $tmp/push.log
655 t-grep-mpat "$mpat" $tmp/push.log
662 use Dpkg::Control::Hash;
663 my $h = new Dpkg::Control::Hash allow_pgp=>1;
664 $h->parse(\*STDIN,"'"$file"'");
665 my $val = $h->{"'$field'"},"\n";
666 die "'"$file $field"'" unless defined $val;
678 *) '$var'="$tstunt:$'$var'" ;;
684 local tstunt=$tmp/tstunt
685 t-stunt-envvar PATH $tstunt
686 t-stunt-envvar PERLLIB $tstunt
690 local d="$tstunt/${f%/*}"
692 ln -sf "$troot/tstunt/$f" "$d"/.
696 t-tstunt-parsechangelog () {
697 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
701 local dsc=${p}_${v}.dsc
702 incoming_dsc=$tmp/incoming/$dsc
707 local val=`t-822-field $incoming_dsc Dgit`
708 perl -e '$_=shift @ARGV; die "Dgit $_ ?" unless m/^\w+\b/;' "$val"
709 t-ref-same-val $incoming_dsc "$val"
716 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
720 t-gbp-unapplied-pq2qc () {
721 # does `gbp pq export'
722 # commits the resulting debian/patches on qc/BRANCH
723 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
724 # qc/BRANCH is not fast-forwarding
728 branch=`git symbolic-ref HEAD`
729 branch=${branch#refs/heads/}
732 */*) fail "unexpected branch $branch" ;;
735 git branch -f qc/$branch
736 git checkout qc/$branch
737 git add debian/patches
738 git commit -m 'Commit patch queue'
741 t-gbp-example-prep () {
742 t-tstunt-parsechangelog
743 t-archive example 1.0-1
751 git-checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
754 echo '/* some comment */' >>src.c
756 git commit -m 'Add a comment to an upstream file'
758 t-gbp-unapplied-pq2qc
760 t-commit 'some updates' 1.0-2
763 -m 'Pseudo-merge to make descendant of archive' \
764 remotes/dgit/dgit/sid
769 v=${2:-${majorv:-1}.$revision}
770 dch -v$v --distribution ${3:-unstable} "$1"
771 git add debian/changelog
773 revision=$(( ${revision-0} + 1 ))
777 git config --global "$@"
781 export DGIT_TEST_TROOT=$troot
782 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
783 t-git-config dgit-distro.test-dummy.git-check true
784 t-git-config dgit-distro.test-dummy.git-create true
785 t-git-config dgit-distro.test-dummy.dgit-tag-format old,new
786 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
787 cp $troot/suites $tmp/.
788 cp $troot/suites $tmp/suites-master
790 export t_check_pushed_master=t-check-pushed-master
792 drs_dispatch=$tmp/distro=test-dummy
795 if [ "x$DGIT_TEST_INTREE" != x ]; then
796 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
799 ln -sf $tmp/git $drs_dispatch/repos
800 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
801 mkdir -p $drs_dispatch/keyrings
802 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
803 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
804 ln -sf /bin/true $drs_dispatch/policy-hook
808 export tagpfx=archive/test-dummy
809 t-git-config dgit-distro.test-dummy.dgit-tag-format new
812 t-git-config dgit-distro.test-dummy.dgit-tag-format old
817 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
818 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
819 t-git-config dgit-distro.test-dummy.git-create true
820 t-git-config dgit-distro.test-dummy.git-url \
821 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
823 t-git-config dgit-distro.test-dummy.diverts.drs /drs
824 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
825 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
826 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
827 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
829 echo 'no-such-package* drs' >$drs_dispatch/diverts
833 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
836 t-policy-nonexist () {
837 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
840 t-make-hook-link () {
841 local hook=$1 # in infra/
843 hook=${DGIT_INFRA_PFX}$hook
846 *) hook=`type -P $hook` ;;
848 ln -sf "$hook" $linkpath
853 t-make-hook-link $policyhook $drs_dispatch/policy-hook
858 t-policy dgit-repos-policy-debian
861 t-policy-admin create-db
864 t-policy-periodic () {
865 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
866 test-dummy $drs_dispatch '' --cron
871 (cd $root; t-restriction-$restriction >&2)
875 : "Hopefully installed: $*"
882 export DGIT_TEST_TESTNAME="$testname"
890 t-chain-test "${t#*-}"