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 exec 4>$tmp/IMPORT.new
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\"")"
393 (set -e; cd $tmp; tar cf IMPORT.tar $savedirs)
395 printf >&4 "\n%s\n" "$importeval"
397 mv -f $tmp/IMPORT.new $tmp/IMPORT
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
409 lock="$tmp/.dummy.lock"
411 setupsrc="$tmpbase/$setupname"
412 lock="$setupsrc.lock"
415 local simport="$setupsrc/IMPORT"
417 if ! [ -e "$simport" ]; then
418 with-lock-ex -w "$lock" \
419 xargs -0 -a $tmp/.save-env \
422 setupname="$1"; shift
424 if [ -e "$simport" ]; then exit 0; fi
426 "tests/setup/$setupname"
427 ' x "$root" "$setupname" "$simport"
430 if [ "x$setupsrc" != "x$tmp" ]; then
431 (set -e; cd $tmp; tar xf "$simport.tar")
437 t-git-get-ref-exact () {
439 # does not dereference, unlike t-git-get-ref
442 *) fail "t-git-get-ref-exact bad $ref" ;;
444 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
451 *) fail "t-git-get-ref bad $ref" ;;
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; }
459 t-ref-same-exact () {
461 local val=`t-git-get-ref-exact $name`
462 t-ref-same-val "$name" $val
467 local val=`t-git-get-ref $name`
468 t-ref-same-val "$name" $val
472 local val=`git rev-parse HEAD`
473 t-ref-same-val HEAD $val
482 *) fail "ref varies: $name:\
483 ${val:-nothing} != ${t_ref_val:-nothing}" ;;
488 t-refs-same-start () {
502 val=`t-git-get-ref $g`
503 if [ "x$val" != x ]; then
504 fail "ref $g unexpectedly exists ($val)"
510 echo refs/tags/$tagpfx/${v//\~/_}
514 git log -n1 --pretty=format:"$1" "$2"
517 t-sametree-parent () {
520 local ctree=$(t-format-ref '%T' "$ref")
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
529 case "$psame" in ""|" * *") break ;; esac
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
546 local suite=${2:-sid}
552 t-pushed-good-core () {
556 refs/remotes/dgit/dgit/$suite
558 refs/heads/dgit/unstable \
559 refs/remotes/dgit/dgit/unstable
560 (set -e; cd $dgitrepo
564 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
568 git verify-tag `t-v-tag`
571 t-splitbrain-pushed-good--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
582 git fetch ../../$p "refs/tags/*:refs/tags/*"
585 t-splitbrain-pushed-good--checkprep () {
587 git rm --cached -r --ignore-unmatch .pc
590 t-splitbrain-pushed-good--checkdiff () {
592 t-splitbrain-pushed-good--checkprep
593 t-output "" git diff --stat --cached $tag
596 t-splitbrain-pushed-good-start () {
597 dep14tag=refs/tags/test-dummy/${v//\~/_}
599 t-output "" git status --porcelain
601 t-refs-same $dep14tag
602 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
603 git merge-base --is-ancestor $dep14tag $dgittag
610 t-splitbrain-pushed-good--unpack
611 t-splitbrain-pushed-good--checkdiff $dgittag
613 t-splitbrain-pushed-good-end-made-dep14 () {
614 t-splitbrain-pushed-good--checkdiff $dep14tag
618 t-splitbrain-rm-gitignore-patch () {
620 next unless $_ eq "auto-gitignore\n";
623 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
625 ' debian/patches/series
628 t-gbp-pushed-good () {
629 local suite=${1:-sid}
630 t-splitbrain-pushed-good-start
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.
637 # So, unpack it withut the patches applied
638 t-splitbrain-pushed-good--unpack --skip-patches
640 # dgit might have added a .gitignore patch, which we need to
642 t-splitbrain-rm-gitignore-patch
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
648 next if !m#^debian/# && m#(^|/)\.gitignore#;
652 # If we actually apply the gitignore patch by hand, it
654 if [ -f ../t-auto-gitignore ]; then
655 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
658 t-splitbrain-pushed-good-end-made-dep14
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
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
674 t-commit-build-push-expect-log () {
680 t-dgit push --new 2>&1 |tee $tmp/push.log
681 t-grep-mpat "$mpat" $tmp/push.log
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;
704 "") '$var'="$tstunt" ;;
705 *) '$var'="$tstunt:$'$var'" ;;
712 local tstunt=$tmp/tstunt
713 t-stunt-envvar PATH $tstunt
714 t-stunt-envvar PERLLIB $tstunt
718 local d="$tstunt/${f%/*}"
720 ln -sf "$troot/tstunt/$f" "$d"/.
724 t-tstunt-parsechangelog () {
725 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
729 local dsc=${p}_${v}.dsc
730 incoming_dsc=$tmp/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"
744 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
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
756 branch=`git symbolic-ref HEAD`
757 branch=${branch#refs/heads/}
760 */*) fail "unexpected branch $branch" ;;
763 git branch -f qc/$branch
764 git checkout qc/$branch
765 git add debian/patches
766 git commit -m 'Commit patch queue'
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'
776 git_pseuomerge_opts+=' -s ours'
778 git merge $git_pseuomerge_opts "$@"
781 t-gbp-example-prep () {
782 t-tstunt-parsechangelog
783 t-archive example 1.0-1
791 git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
794 echo '/* some comment */' >>src.c
796 git commit -m 'Add a comment to an upstream file'
798 t-gbp-unapplied-pq2qc
800 t-commit 'some updates' 1.0-2
803 -m 'Pseudo-merge to make descendant of archive' \
804 remotes/dgit/dgit/sid
809 v=${2:-${majorv:-1}.$revision}
810 dch -v$v --distribution ${3:-unstable} "$1"
811 git add debian/changelog
813 revision=$(( ${revision-0} + 1 ))
817 git config --global "$@"
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
830 export t_check_pushed_master=t-check-pushed-master
832 drs_dispatch=$tmp/distro=test-dummy
835 if [ "x$DGIT_TEST_INTREE" != x ]; then
836 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
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
848 export tagpfx=archive/test-dummy
849 t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
852 t-git-config dgit-distro.test-dummy.dgit-tag-format old
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"
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
869 echo 'no-such-package* drs' >$drs_dispatch/diverts
873 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
876 t-policy-nonexist () {
877 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
880 t-make-hook-link () {
881 local hook=$1 # in infra/
883 hook=${DGIT_INFRA_PFX}$hook
886 *) hook=`type -P $hook` ;;
888 ln -sf "$hook" $linkpath
893 t-make-hook-link $policyhook $drs_dispatch/policy-hook
898 t-policy dgit-repos-policy-debian
901 t-policy-admin create-db
904 t-policy-periodic () {
905 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
906 test-dummy $drs_dispatch '' --cron
911 (cd $root; t-restriction-$restriction >&2)
915 : "Hopefully installed: $*"
922 export DGIT_TEST_TESTNAME="$testname"
930 t-chain-test "${t#*-}"