16 lines: ${BASH_LINENO[*]}
17 files: ${BASH_SOURCE[*]}
22 trap 'test $? = 0 || t-report-failure' EXIT
24 t-filter-out-git-hyphen-dir
28 : ${DGIT_TEST_DEBUG=-D}
29 export DGIT_TEST_DEBUG
31 export GIT_COMMITTER_DATE='1440253867 +0100'
32 export GIT_AUTHOR_DATE='1440253867 +0100'
36 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
39 if [ x"$tmp" = x ]; then
42 tmp=tests/tmp/$testname
52 env -0 >$tmp/.save-env
57 cp $troot/gnupg/* $tmp/gnupg
58 chmod go-rw $tmp/gnupg/*
60 export DEBCHANGE_VENDOR=dpkg
62 mkdir -p $tmp/incoming
63 cat <<END >$tmp/dput.cf
66 incoming = $tmp/incoming
70 : ${tagpfx:=test-dummy}
71 : ${suitespecs:=sid:unstable}
74 GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
75 GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
79 local mpat="$1"; shift
82 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
83 local ps="${PIPESTATUS[*]}"
87 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
89 *) fail "tee failed" ;;
92 t-grep-mpat "$mpat" $tmp/t.output
103 E:*) grepper=egrep ;;
104 F:*) grepper=fgrep ;;
105 *) fail "bad mpat prefix in $mpat";;
111 $grepper -e "$mpat" "$file" ||
112 fail "message not found"
115 t-expect-push-fail () {
116 local mpat="$1"; shift
118 local triedpush=`git rev-parse HEAD`
121 t-expect-fail "$mpat" "$@"
123 diff $tmp/show-refs.{pre,post}-push
125 t-git-objects-not-present '' $triedpush
127 eval "$t_expect_push_fail_hook"
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}"
135 if ! [ -e "$gitdir" ]; then return; fi
138 t-expect-fail 'unable to find' \
144 local whichoutput=$1; shift
145 local whichrepo=${1-$dgitrepo}
146 local outputfile="$tmp/show-refs.$whichoutput"
149 if test -d $whichrepo; then
157 local edittree=$1.edit
158 if test -d "$edittree"; then
159 cp -a "$edittree"/* .
167 t-untar $troot/worktrees/${p}_$1
170 t-select-package () {
172 dgitrepo=$tmp/git/$p.git
179 local gs=$troot/git-srcs/${p}_$v.git
180 (set -e; cd $tmp/git; t-untar $gs)
185 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
188 t-git-merge-base () {
189 git merge-base $1 $2 || test $? = 1
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"
201 t-prep-newpackage () {
208 if ! git show-ref --verify --quiet refs/heads/master; then
209 git branch -m dgit/sid master
217 mkdir -p $tmp/aq/dsc_in_suite $tmp/mirror/pool/main
223 for suitespec in $suitespecs; do
224 local suite=${suitespec%%:*}
225 local sname=${suitespec#*:}
227 >$tmp/aq/package.$suite.$p
228 t-archive-updated $suite $p
230 >$tmp/aq/package.new.$p
231 t-archive-updated new $p
233 ln -sf $suite $tmp/aq/dsc_in_suite/$sname
235 cat <<END >>$tmp/aq/suites
238 "archive" : "ftp-master",
239 "codename" : "$suite",
252 cat <<END >>$tmp/aq/suites
258 t-archive-updated () {
261 local suitedir=$tmp/aq/dsc_in_suite/$suite
263 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
267 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
275 my $json = JSON->new->canonical();
276 print $json->encode(\@v) or die $!;
281 t-archive-process-incoming () {
283 mv $tmp/incoming/${p}_${v}[._]* $tmp/mirror/pool/main/
284 t-archive-query "$suite"
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
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/
304 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
307 t-git-dir-time-passes () {
308 touch -d 'last year' $dgitrepo
312 local gitdir=$dgitrepo
315 if test -e "$gitdir"; then fail "$gitdir exists"; fi
318 public) wantstat='7[75]5' ;;
319 secret) wantstat='7[70]0' ;;
320 *) fail "$1 t-git-dir-check ?" ;;
322 gotstat=`stat -c%a $gitdir`
324 *$wantstat) return ;;
325 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
329 t-rm-dput-dropping () {
330 rm -f $tmp/${p}_${v}_*.upload
334 local dgit=${DGIT_TEST-dgit}
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 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
346 diff --exclude=.git --exclude=.pc -ruN $*
349 t-files-notexist () {
358 t-cloned-fetched-good () {
359 t-diff-nogit ../extract/$p-${v%-*} .
360 t-clean-on-branch dgit/sid
363 refs/heads/dgit/sid \
364 refs/remotes/dgit/dgit/sid
365 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
369 printf "%s${1:+\n}" "$1" >$tmp/t.want
372 diff $tmp/t.want $tmp/t.got
375 t-clean-on-branch () {
376 t-output "## $1" git status -b --porcelain
384 local import=IMPORT.${0##*/}
385 exec 4>$tmp/$import.new
388 for vn in $savevars; do
389 perl >&4 -I. -MDebian::Dgit -e '
390 printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
391 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
394 (set -e; cd $tmp; tar cf $import.tar $savedirs)
396 printf >&4 "\n%s\n" "$importeval"
398 mv -f $tmp/$import.new $tmp/$import
406 if [ "x$tmpbase" = x ]; then
407 # ADTTMP was set on entry to tests/lib, so we
408 # are not sharing tmp area between tests
410 lock="$tmp/.dummy.lock"
412 setupsrc="$tmpbase/$setupname"
413 lock="$setupsrc.lock"
416 local simport="$setupsrc/IMPORT.$setupname"
418 if ! [ -e "$simport" ]; then
419 with-lock-ex -w "$lock" \
420 xargs -0 -a $tmp/.save-env \
423 setupname="$1"; shift
425 if [ -e "$simport" ]; then exit 0; fi
427 "tests/setup/$setupname"
428 ' x "$root" "$setupname" "$simport"
431 if [ "x$setupsrc" != "x$tmp" ]; then
432 (set -e; cd $tmp; tar xf "$simport.tar")
438 t-git-get-ref-exact () {
440 # does not dereference, unlike t-git-get-ref
443 *) fail "t-git-get-ref-exact bad $ref" ;;
445 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
452 *) fail "t-git-get-ref bad $ref" ;;
454 (git show-ref -d $1 || test $? = 1) | perl -ne '
455 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
456 END { print "$x\n" if length $x; }
460 t-ref-same-exact () {
462 local val=`t-git-get-ref-exact $name`
463 t-ref-same-val "$name" $val
468 local val=`t-git-get-ref $name`
469 t-ref-same-val "$name" $val
473 local val=`git rev-parse HEAD`
474 t-ref-same-val HEAD $val
483 *) fail "ref varies: $name:\
484 ${val:-nothing} != ${t_ref_val:-nothing}" ;;
489 t-refs-same-start () {
503 val=`t-git-get-ref $g`
504 if [ "x$val" != x ]; then
505 fail "ref $g unexpectedly exists ($val)"
511 echo refs/tags/$tagpfx/${v//\~/_}
515 git log -n1 --pretty=format:"$1" "$2"
518 t-sametree-parent () {
521 local ctree=$(t-format-ref '%T' "$ref")
524 for parent in $(t-format-ref '%P' "$ref"); do
525 local ptree=$(t-format-ref '%T' "$parent")
526 if [ "x$ptree" = "x$ctree" ]; then
530 case "$psame" in ""|" * *") break ;; esac
536 t-check-pushed-master () {
537 local master=`t-git-get-ref refs/heads/master`
538 if [ x$master = x$t_ref_val ]; then return; fi
539 if [ x$master = x ]; then fail "failed to push master"; fi
540 # didn't update master, it must be not FF
541 local mbase=`t-git-merge-base $master $t_ref_val`
542 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
547 local suite=${2:-sid}
553 t-pushed-good-core () {
557 refs/remotes/dgit/dgit/$suite
559 refs/heads/dgit/unstable \
560 refs/remotes/dgit/dgit/unstable
561 (set -e; cd $dgitrepo
565 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
569 git verify-tag `t-v-tag`
572 t-splitbrain-pushed-good--unpack () {
577 ln -s $tmp/mirror/pool/main/*.orig*.tar* .
578 ln -s $incoming_dsc .
579 ln -s ${incoming_dsc/.dsc/.debian.tar}* .
580 dpkg-source "$@" -x *.dsc
583 git fetch ../../$p "refs/tags/*:refs/tags/*"
586 t-splitbrain-pushed-good--checkprep () {
588 git rm --cached -r --ignore-unmatch .pc
591 t-splitbrain-pushed-good--checkdiff () {
593 t-splitbrain-pushed-good--checkprep
594 t-output "" git diff --stat --cached $tag
597 t-splitbrain-pushed-good-start () {
598 dep14tag=refs/tags/test-dummy/${v//\~/_}
600 t-output "" git status --porcelain
602 t-refs-same $dep14tag
603 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
604 git merge-base --is-ancestor $dep14tag $dgittag
611 t-splitbrain-pushed-good--unpack
612 t-splitbrain-pushed-good--checkdiff $dgittag
614 t-splitbrain-pushed-good-end-made-dep14 () {
615 t-splitbrain-pushed-good--checkdiff $dep14tag
619 t-splitbrain-rm-gitignore-patch () {
621 next unless $_ eq "auto-gitignore\n";
624 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
626 ' debian/patches/series
629 t-gbp-pushed-good () {
630 local suite=${1:-sid}
631 t-splitbrain-pushed-good-start
633 # Right, now we want to check that the maintainer tree and
634 # the dgit tree differ in exactly the ways we expect. We
635 # achieve this by trying to reconstruct the maintainer tree
636 # from the dgit tree.
638 # So, unpack it withut the patches applied
639 t-splitbrain-pushed-good--unpack --skip-patches
641 # dgit might have added a .gitignore patch, which we need to
643 t-splitbrain-rm-gitignore-patch
645 # Now the result should differ only in non-debian/ .gitignores
646 t-splitbrain-pushed-good--checkprep
647 git diff --cached --name-only $dep14tag >../changed
649 next if !m#^debian/# && m#(^|/)\.gitignore#;
653 # If we actually apply the gitignore patch by hand, it
655 if [ -f ../t-auto-gitignore ]; then
656 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
659 t-splitbrain-pushed-good-end-made-dep14
662 t-unapplied-pushed-good () {
663 t-splitbrain-pushed-good-start
664 t-splitbrain-pushed-good--unpack --skip-patches
665 t-splitbrain-pushed-good-end-made-dep14
668 t-dpm-pushed-good () {
669 t-splitbrain-pushed-good-start
670 t-splitbrain-pushed-good--unpack
671 t-splitbrain-rm-gitignore-patch
672 t-splitbrain-pushed-good-end-made-dep14
675 t-commit-build-push-expect-log () {
681 t-dgit push --new 2>&1 |tee $tmp/push.log
682 t-grep-mpat "$mpat" $tmp/push.log
689 use Dpkg::Control::Hash;
690 my $h = new Dpkg::Control::Hash allow_pgp=>1;
691 $h->parse(\*STDIN,"'"$file"'");
692 my $val = $h->{"'$field'"},"\n";
693 die "'"$file $field"'" unless defined $val;
705 "") '$var'="$tstunt" ;;
706 *) '$var'="$tstunt:$'$var'" ;;
713 local tstunt=$tmp/tstunt
714 t-stunt-envvar PATH $tstunt
715 t-stunt-envvar PERLLIB $tstunt
719 local d="$tstunt/${f%/*}"
721 ln -sf "$troot/tstunt/$f" "$d"/.
725 t-tstunt-parsechangelog () {
726 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
730 local dsc=${p}_${v}.dsc
731 incoming_dsc=$tmp/incoming/$dsc
736 local val=`t-822-field $incoming_dsc Dgit`
737 perl -e '$_=shift @ARGV; die "Dgit $_ ?" unless m/^\w+\b/;' "$val"
738 t-ref-same-val $incoming_dsc "$val"
745 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
749 t-gbp-unapplied-pq2qc () {
750 # does `gbp pq export'
751 # commits the resulting debian/patches on qc/BRANCH
752 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
753 # qc/BRANCH is not fast-forwarding
757 branch=`git symbolic-ref HEAD`
758 branch=${branch#refs/heads/}
761 */*) fail "unexpected branch $branch" ;;
764 git branch -f qc/$branch
765 git checkout qc/$branch
766 git add debian/patches
767 git commit -m 'Commit patch queue'
770 t-git-pseudo-merge () {
771 # like git merge -s ours
772 if [ ! "$git_pseuomerge_opts" ]; then
773 if git merge --help \
774 | grep -q allow-unrelated-histories; then
775 git_pseuomerge_opts='--allow-unrelated-histories'
777 git_pseuomerge_opts+=' -s ours'
779 git merge $git_pseuomerge_opts "$@"
782 t-gbp-example-prep-no-ff () {
783 t-tstunt-parsechangelog
784 t-archive example 1.0-1
792 git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
795 echo '/* some comment */' >>src.c
797 git commit -m 'Add a comment to an upstream file'
799 t-gbp-unapplied-pq2qc
801 t-commit 'some updates' 1.0-2
804 t-gbp-example-prep () {
805 t-gbp-example-prep-no-ff
808 -m 'Pseudo-merge to make descendant of archive' \
809 remotes/dgit/dgit/sid
814 v=${2:-${majorv:-1}.$revision}
815 dch -v$v --distribution ${3:-unstable} "$1"
816 git add debian/changelog
818 revision=$(( ${revision-0} + 1 ))
822 git config --global "$@"
826 export DGIT_TEST_TROOT=$troot
827 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
828 t-git-config dgit-distro.test-dummy.git-check true
829 t-git-config dgit-distro.test-dummy.git-create true
830 t-git-config dgit-distro.test-dummy.dgit-tag-format old,new
831 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
832 cp $troot/suites $tmp/.
833 cp $troot/suites $tmp/suites-master
835 export t_check_pushed_master=t-check-pushed-master
837 drs_dispatch=$tmp/distro=test-dummy
840 if [ "x$DGIT_TEST_INTREE" != x ]; then
841 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
844 ln -sf $tmp/git $drs_dispatch/repos
845 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
846 mkdir -p $drs_dispatch/keyrings
847 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
848 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
849 ln -sf /bin/true $drs_dispatch/policy-hook
853 export tagpfx=archive/test-dummy
854 t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
857 t-git-config dgit-distro.test-dummy.dgit-tag-format old
862 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
863 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
864 t-git-config dgit-distro.test-dummy.git-create true
865 t-git-config dgit-distro.test-dummy.git-url \
866 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
868 t-git-config dgit-distro.test-dummy.diverts.drs /drs
869 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
870 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
871 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
872 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
874 echo 'no-such-package* drs' >$drs_dispatch/diverts
878 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
881 t-policy-nonexist () {
882 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
885 t-make-hook-link () {
886 local hook=$1 # in infra/
888 hook=${DGIT_INFRA_PFX}$hook
891 *) hook=`type -P $hook` ;;
893 ln -sf "$hook" $linkpath
898 t-make-hook-link $policyhook $drs_dispatch/policy-hook
903 t-policy dgit-repos-policy-debian
906 t-policy-admin create-db
909 t-policy-periodic () {
910 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
911 test-dummy $drs_dispatch '' --cron
916 (cd $root; t-restriction-$restriction >&2)
920 : "Hopefully installed: $*"
927 export DGIT_TEST_TESTNAME="$testname"
935 t-chain-test "${t#*-}"