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
45 elif [ "x$DGIT_TEST_TMPBASE" != x ]; then
46 tmpbase="$DGIT_TEST_TMPBASE"
54 env -0 >$tmp/.save-env
59 cp $troot/gnupg/* $tmp/gnupg
60 chmod go-rw $tmp/gnupg/*
62 export DEBCHANGE_VENDOR=dpkg
64 mkdir -p $tmp/incoming
65 cat <<END >$tmp/dput.cf
68 incoming = $tmp/incoming
72 : ${tagpfx:=test-dummy}
73 : ${suitespecs:=sid:unstable}
76 GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
77 GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
81 local mpat="$1"; shift
84 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
85 local ps="${PIPESTATUS[*]}"
89 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
91 *) fail "tee failed" ;;
94 t-grep-mpat "$mpat" $tmp/t.output
105 E:*) grepper=egrep ;;
106 F:*) grepper=fgrep ;;
107 *) fail "bad mpat prefix in $mpat";;
113 $grepper -e "$mpat" "$file" ||
114 fail "message not found"
117 t-expect-push-fail () {
118 local mpat="$1"; shift
120 local triedpush=`git rev-parse HEAD`
123 t-expect-fail "$mpat" "$@"
125 diff $tmp/show-refs.{pre,post}-push
127 t-git-objects-not-present '' $triedpush
129 eval "$t_expect_push_fail_hook"
132 t-git-objects-not-present () {
133 # t-git-objects-not-present GITDIR|'' OBJID [...]
134 # specifying '' means the repo for package $p
135 local gitdir="${1-$dgitrepo}"
137 if ! [ -e "$gitdir" ]; then return; fi
140 t-expect-fail 'unable to find' \
146 local whichoutput=$1; shift
147 local whichrepo=${1-$dgitrepo}
148 local outputfile="$tmp/show-refs.$whichoutput"
151 if test -d $whichrepo; then
159 local edittree=$1.edit
160 if test -d "$edittree"; then
161 cp -a "$edittree"/* .
169 t-untar $troot/worktrees/${p}_$1
172 t-select-package () {
174 dgitrepo=$tmp/git/$p.git
181 local gs=$troot/git-srcs/${p}_$v.git
182 (set -e; cd $tmp/git; t-untar $gs)
187 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
190 t-git-merge-base () {
191 git merge-base $1 $2 || test $? = 1
195 local now=`git rev-parse HEAD`
196 local ancestor=`git rev-parse $1^{}`
197 local mbase=`t-git-merge-base $ancestor $now`
198 if [ x$mbase != x$ancestor ]; then
199 fail "not ff $ancestor..$now, $mbase != $ancestor"
203 t-prep-newpackage () {
210 if ! git show-ref --verify --quiet refs/heads/master; then
211 git branch -m dgit/sid master
219 mkdir -p $tmp/aq/dsc_in_suite $tmp/mirror/pool/main
225 for suitespec in $suitespecs; do
226 local suite=${suitespec%%:*}
227 local sname=${suitespec#*:}
229 >$tmp/aq/package.$suite.$p
230 t-archive-updated $suite $p
232 >$tmp/aq/package.new.$p
233 t-archive-updated new $p
235 ln -sf $suite $tmp/aq/dsc_in_suite/$sname
237 cat <<END >>$tmp/aq/suites
240 "archive" : "ftp-master",
241 "codename" : "$suite",
254 cat <<END >>$tmp/aq/suites
260 t-archive-updated () {
263 local suitedir=$tmp/aq/dsc_in_suite/$suite
265 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
269 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
277 my $json = JSON->new->canonical();
278 print $json->encode(\@v) or die $!;
283 t-archive-process-incoming () {
285 mv $tmp/incoming/${p}_${v}[._]* $tmp/mirror/pool/main/
286 t-archive-query "$suite"
291 local dscf=main/${p}_${v}.dsc
292 local sha=`sha256sum <$tmp/mirror/pool/$dscf`
293 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
294 t-archive-updated $suite $p
300 local dscf=${p}_$2.dsc
301 rm -f $tmp/mirror/pool/main/${p}_*
302 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
306 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
309 t-git-dir-time-passes () {
310 touch -d 'last year' $dgitrepo
314 local gitdir=$dgitrepo
317 if test -e "$gitdir"; then fail "$gitdir exists"; fi
320 public) wantstat='7[75]5' ;;
321 secret) wantstat='7[70]0' ;;
322 *) fail "$1 t-git-dir-check ?" ;;
324 gotstat=`stat -c%a $gitdir`
326 *$wantstat) return ;;
327 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
331 t-rm-dput-dropping () {
332 rm -f $tmp/${p}_${v}_*.upload
336 local dgit=${DGIT_TEST-dgit}
339 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
340 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
341 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
342 -k39B13D8A $t_dgit_xopts "$@"
343 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
348 diff --exclude=.git --exclude=.pc -ruN $*
351 t-files-notexist () {
360 t-cloned-fetched-good () {
361 t-diff-nogit ../extract/$p-${v%-*} .
362 t-clean-on-branch dgit/sid
365 refs/heads/dgit/sid \
366 refs/remotes/dgit/dgit/sid
367 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
371 printf "%s${1:+\n}" "$1" >$tmp/t.want
374 diff $tmp/t.want $tmp/t.got
377 t-clean-on-branch () {
378 t-output "## $1" git status -b --porcelain
386 local import=IMPORT.${0##*/}
387 exec 4>$tmp/$import.new
390 for vn in $savevars; do
391 perl >&4 -I. -MDebian::Dgit -e '
392 printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
393 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
396 (set -e; cd $tmp; tar cf $import.tar $savedirs)
398 printf >&4 "\n%s\n" "$importeval"
400 mv -f $tmp/$import.new $tmp/$import
408 if [ "x$tmpbase" = x ]; then
409 # ADTTMP was set on entry to tests/lib, so we
410 # are not sharing tmp area between tests
412 lock="$tmp/.dummy.lock"
414 setupsrc="$tmpbase/$setupname"
415 lock="$setupsrc.lock"
418 local simport="$setupsrc/IMPORT.$setupname"
420 if ! [ -e "$simport" ]; then
421 with-lock-ex -w "$lock" \
422 xargs -0 -a $tmp/.save-env \
425 setupname="$1"; shift
427 if [ -e "$simport" ]; then exit 0; fi
429 "tests/setup/$setupname"
430 ' x "$root" "$setupname" "$simport"
433 if [ "x$setupsrc" != "x$tmp" ]; then
434 (set -e; cd $tmp; tar xf "$simport.tar")
440 t-git-get-ref-exact () {
442 # does not dereference, unlike t-git-get-ref
445 *) fail "t-git-get-ref-exact bad $ref" ;;
447 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
454 *) fail "t-git-get-ref bad $ref" ;;
456 (git show-ref -d $1 || test $? = 1) | perl -ne '
457 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
458 END { print "$x\n" if length $x; }
462 t-ref-same-exact () {
464 local val=`t-git-get-ref-exact $name`
465 t-ref-same-val "$name" $val
470 local val=`t-git-get-ref $name`
471 t-ref-same-val "$name" $val
475 local val=`git rev-parse HEAD`
476 t-ref-same-val HEAD $val
485 *) fail "ref varies: $name:\
486 ${val:-nothing} != ${t_ref_val:-nothing}" ;;
491 t-refs-same-start () {
505 val=`t-git-get-ref $g`
506 if [ "x$val" != x ]; then
507 fail "ref $g unexpectedly exists ($val)"
513 echo refs/tags/$tagpfx/${v//\~/_}
517 git log -n1 --pretty=format:"$1" "$2"
520 t-sametree-parent () {
523 local ctree=$(t-format-ref '%T' "$ref")
526 for parent in $(t-format-ref '%P' "$ref"); do
527 local ptree=$(t-format-ref '%T' "$parent")
528 if [ "x$ptree" = "x$ctree" ]; then
532 case "$psame" in ""|" * *") break ;; esac
538 t-check-pushed-master () {
539 local master=`t-git-get-ref refs/heads/master`
540 if [ x$master = x$t_ref_val ]; then return; fi
541 if [ x$master = x ]; then fail "failed to push master"; fi
542 # didn't update master, it must be not FF
543 local mbase=`t-git-merge-base $master $t_ref_val`
544 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
549 local suite=${2:-sid}
555 t-pushed-good-core () {
559 refs/remotes/dgit/dgit/$suite
561 refs/heads/dgit/unstable \
562 refs/remotes/dgit/dgit/unstable
563 (set -e; cd $dgitrepo
567 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
571 git verify-tag `t-v-tag`
574 t-splitbrain-pushed-good--unpack () {
579 ln -s $tmp/mirror/pool/main/*.orig*.tar* .
580 ln -s $incoming_dsc .
581 ln -s ${incoming_dsc/.dsc/.debian.tar}* .
582 dpkg-source "$@" -x *.dsc
585 git fetch ../../$p "refs/tags/*:refs/tags/*"
588 t-splitbrain-pushed-good--checkprep () {
590 git rm --cached -r --ignore-unmatch .pc
593 t-splitbrain-pushed-good--checkdiff () {
595 t-splitbrain-pushed-good--checkprep
596 t-output "" git diff --stat --cached $tag
599 t-splitbrain-pushed-good-start () {
600 dep14tag=refs/tags/test-dummy/${v//\~/_}
602 t-output "" git status --porcelain
604 t-refs-same $dep14tag
605 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
606 git merge-base --is-ancestor $dep14tag $dgittag
613 t-splitbrain-pushed-good--unpack
614 t-splitbrain-pushed-good--checkdiff $dgittag
616 t-splitbrain-pushed-good-end-made-dep14 () {
617 t-splitbrain-pushed-good--checkdiff $dep14tag
621 t-splitbrain-rm-gitignore-patch () {
623 next unless $_ eq "auto-gitignore\n";
626 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
628 ' debian/patches/series
631 t-gbp-pushed-good () {
632 local suite=${1:-sid}
633 t-splitbrain-pushed-good-start
635 # Right, now we want to check that the maintainer tree and
636 # the dgit tree differ in exactly the ways we expect. We
637 # achieve this by trying to reconstruct the maintainer tree
638 # from the dgit tree.
640 # So, unpack it withut the patches applied
641 t-splitbrain-pushed-good--unpack --skip-patches
643 # dgit might have added a .gitignore patch, which we need to
645 t-splitbrain-rm-gitignore-patch
647 # Now the result should differ only in non-debian/ .gitignores
648 t-splitbrain-pushed-good--checkprep
649 git diff --cached --name-only $dep14tag >../changed
651 next if !m#^debian/# && m#(^|/)\.gitignore#;
655 # If we actually apply the gitignore patch by hand, it
657 if [ -f ../t-auto-gitignore ]; then
658 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
661 t-splitbrain-pushed-good-end-made-dep14
664 t-unapplied-pushed-good () {
665 t-splitbrain-pushed-good-start
666 t-splitbrain-pushed-good--unpack --skip-patches
667 t-splitbrain-pushed-good-end-made-dep14
670 t-dpm-pushed-good () {
671 t-splitbrain-pushed-good-start
672 t-splitbrain-pushed-good--unpack
673 t-splitbrain-rm-gitignore-patch
674 t-splitbrain-pushed-good-end-made-dep14
677 t-commit-build-push-expect-log () {
683 t-dgit push --new 2>&1 |tee $tmp/push.log
684 t-grep-mpat "$mpat" $tmp/push.log
691 use Dpkg::Control::Hash;
692 my $h = new Dpkg::Control::Hash allow_pgp=>1;
693 $h->parse(\*STDIN,"'"$file"'");
694 my $val = $h->{"'$field'"},"\n";
695 die "'"$file $field"'" unless defined $val;
707 "") '$var'="$tstunt" ;;
708 *) '$var'="$tstunt:$'$var'" ;;
715 local tstunt=$tmp/tstunt
716 t-stunt-envvar PATH $tstunt
717 t-stunt-envvar PERLLIB $tstunt
721 local d="$tstunt/${f%/*}"
723 ln -sf "$troot/tstunt/$f" "$d"/.
727 t-tstunt-parsechangelog () {
728 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
732 local dsc=${p}_${v}.dsc
733 incoming_dsc=$tmp/incoming/$dsc
738 local val=`t-822-field $incoming_dsc Dgit`
739 perl -e '$_=shift @ARGV; die "Dgit $_ ?" unless m/^\w+\b/;' "$val"
740 t-ref-same-val $incoming_dsc "$val"
747 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
751 t-gbp-unapplied-pq2qc () {
752 # does `gbp pq export'
753 # commits the resulting debian/patches on qc/BRANCH
754 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
755 # qc/BRANCH is not fast-forwarding
759 branch=`git symbolic-ref HEAD`
760 branch=${branch#refs/heads/}
763 */*) fail "unexpected branch $branch" ;;
766 git branch -f qc/$branch
767 git checkout qc/$branch
768 git add debian/patches
769 git commit -m 'Commit patch queue'
772 t-git-pseudo-merge () {
773 # like git merge -s ours
774 if [ ! "$git_pseuomerge_opts" ]; then
775 if git merge --help \
776 | grep -q allow-unrelated-histories; then
777 git_pseuomerge_opts='--allow-unrelated-histories'
779 git_pseuomerge_opts+=' -s ours'
781 git merge $git_pseuomerge_opts "$@"
784 t-gbp-example-prep-no-ff () {
785 t-tstunt-parsechangelog
786 t-archive example 1.0-1
794 git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
797 echo '/* some comment */' >>src.c
799 git commit -m 'Add a comment to an upstream file'
801 t-gbp-unapplied-pq2qc
803 t-commit 'some updates' 1.0-2
806 t-gbp-example-prep () {
807 t-gbp-example-prep-no-ff
810 -m 'Pseudo-merge to make descendant of archive' \
811 remotes/dgit/dgit/sid
816 v=${2:-${majorv:-1}.$revision}
817 dch -v$v --distribution ${3:-unstable} "$1"
818 git add debian/changelog
820 revision=$(( ${revision-0} + 1 ))
824 git config --global "$@"
828 export DGIT_TEST_TROOT=$troot
829 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
830 t-git-config dgit-distro.test-dummy.git-check true
831 t-git-config dgit-distro.test-dummy.git-create true
832 t-git-config dgit-distro.test-dummy.dgit-tag-format old,new
833 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
834 cp $troot/suites $tmp/.
835 cp $troot/suites $tmp/suites-master
837 export t_check_pushed_master=t-check-pushed-master
839 drs_dispatch=$tmp/distro=test-dummy
842 if [ "x$DGIT_TEST_INTREE" != x ]; then
843 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
846 ln -sf $tmp/git $drs_dispatch/repos
847 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
848 mkdir -p $drs_dispatch/keyrings
849 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
850 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
851 ln -sf /bin/true $drs_dispatch/policy-hook
855 export tagpfx=archive/test-dummy
856 t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
859 t-git-config dgit-distro.test-dummy.dgit-tag-format old
864 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
865 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
866 t-git-config dgit-distro.test-dummy.git-create true
867 t-git-config dgit-distro.test-dummy.git-url \
868 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
870 t-git-config dgit-distro.test-dummy.diverts.drs /drs
871 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
872 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
873 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
874 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
876 echo 'no-such-package* drs' >$drs_dispatch/diverts
880 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
883 t-policy-nonexist () {
884 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
887 t-make-hook-link () {
888 local hook=$1 # in infra/
890 hook=${DGIT_INFRA_PFX}$hook
893 *) hook=`type -P $hook` ;;
895 ln -sf "$hook" $linkpath
900 t-make-hook-link $policyhook $drs_dispatch/policy-hook
905 t-policy dgit-repos-policy-debian
908 t-policy-admin create-db
911 t-policy-periodic () {
912 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
913 test-dummy $drs_dispatch '' --cron
918 (cd $root; t-restriction-$restriction >&2)
922 : "Hopefully installed: $*"
929 export DGIT_TEST_TESTNAME="$testname"
930 export DGIT_TEST_TMPBASE="$tmpbase"
938 t-chain-test "${t#*-}"