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
58 export DEBCHANGE_VENDOR=dpkg
60 mkdir -p $tmp/incoming
61 cat <<END >$tmp/dput.cf
64 incoming = $tmp/incoming
68 : ${tagpfx:=archive/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 # t-has-ancestor ANCESTOR
192 # (CHILD is implicit, HEAD)
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"
202 # t-has-parent CHILD PARENT
205 local parents=$(git show --pretty=format:' %P ' "$child")
206 parent=$(git rev-parse "$parent~0")
209 *) fail "child $child lacks parent $parent" ;;
213 t-prep-newpackage () {
220 if ! git show-ref --verify --quiet refs/heads/master; then
221 git branch -m dgit/sid master
229 mkdir -p $tmp/aq/dsc_in_suite $tmp/mirror/pool/main
235 for suitespec in $suitespecs; do
236 local suite=${suitespec%%:*}
237 local sname=${suitespec#*:}
239 >$tmp/aq/package.$suite.$p
240 t-archive-updated $suite $p
242 >$tmp/aq/package.new.$p
243 t-archive-updated new $p
245 ln -sf $suite $tmp/aq/dsc_in_suite/$sname
247 cat <<END >>$tmp/aq/suites
250 "archive" : "ftp-master",
251 "codename" : "$suite",
264 cat <<END >>$tmp/aq/suites
270 t-archive-updated () {
273 local suitedir=$tmp/aq/dsc_in_suite/$suite
275 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
279 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
287 my $json = JSON->new->canonical();
288 print $json->encode(\@v) or die $!;
293 t-archive-process-incoming () {
295 mv $tmp/incoming/${p}_* $tmp/mirror/pool/main/
296 t-archive-query "$suite"
301 local dscf=main/${p}_${v}.dsc
302 local sha=`sha256sum <$tmp/mirror/pool/$dscf`
303 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
304 t-archive-updated $suite $p
310 local dscf=${p}_$2.dsc
311 rm -f $tmp/mirror/pool/main/${p}_*
312 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
316 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
319 t-git-dir-time-passes () {
320 touch -d 'last year' $dgitrepo
324 local gitdir=$dgitrepo
327 if test -e "$gitdir"; then fail "$gitdir exists"; fi
330 public) wantstat='7[75]5' ;;
331 secret) wantstat='7[70]0' ;;
332 *) fail "$1 t-git-dir-check ?" ;;
334 gotstat=`stat -c%a $gitdir`
336 *$wantstat) return ;;
337 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
341 t-rm-dput-dropping () {
342 rm -f $tmp/${p}_${v}_*.upload
346 local dgit=${DGIT_TEST-dgit}
349 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
350 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
351 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
352 -k39B13D8A $t_dgit_xopts "$@"
353 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
358 diff --exclude=.git --exclude=.pc -ruN $*
361 t-files-notexist () {
370 t-cloned-fetched-good () {
371 t-diff-nogit ../extract/$p-${v%-*} .
372 t-clean-on-branch dgit/sid
375 refs/heads/dgit/sid \
376 refs/remotes/dgit/dgit/sid
377 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
381 printf "%s${1:+\n}" "$1" >$tmp/t.want
384 diff $tmp/t.want $tmp/t.got
387 t-clean-on-branch () {
388 t-output "## $1" git status -b --porcelain
396 local import=IMPORT.${0##*/}
397 exec 4>$tmp/$import.new
400 for vn in $savevars; do
401 perl >&4 -I. -MDebian::Dgit -e '
402 printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
403 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
406 (set -e; cd $tmp; tar cf $import.tar $savedirs)
408 printf >&4 "\n%s\n" "$importeval"
410 mv -f $tmp/$import.new $tmp/$import
418 if [ "x$tmpbase" = x ]; then
419 # ADTTMP was set on entry to tests/lib, so we
420 # are not sharing tmp area between tests
422 lock="$tmp/.dummy.lock"
424 setupsrc="$tmpbase/$setupname"
425 lock="$setupsrc.lock"
428 local simport="$setupsrc/IMPORT.$setupname"
430 if ! [ -e "$simport" ]; then
431 with-lock-ex -w "$lock" \
432 xargs -0 -a $tmp/.save-env \
435 setupname="$1"; shift
437 if [ -e "$simport" ]; then exit 0; fi
439 "tests/setup/$setupname"
440 ' x "$root" "$setupname" "$simport"
443 if [ "x$setupsrc" != "x$tmp" ]; then
444 (set -e; cd $tmp; tar xf "$simport.tar")
450 t-git-get-ref-exact () {
452 # does not dereference, unlike t-git-get-ref
455 *) fail "t-git-get-ref-exact bad $ref" ;;
457 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
464 *) fail "t-git-get-ref bad $ref" ;;
466 (git show-ref -d $1 || test $? = 1) | perl -ne '
467 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
468 END { print "$x\n" if length $x; }
472 t-ref-same-exact () {
474 local val=`t-git-get-ref-exact $name`
475 t-ref-same-val "$name" $val
480 local val=`t-git-get-ref $name`
481 t-ref-same-val "$name" $val
485 local val=`git rev-parse HEAD`
486 t-ref-same-val HEAD $val
492 case "${t_ref_val-unset}" in
495 *) fail "ref varies: ($name)\
496 ${val:-nothing} != ${t_ref_val:-nothing} (${t_ref_names[*]})" ;;
499 t_ref_names+=("$name")
502 t-refs-same-start () {
517 val=`t-git-get-ref $g`
518 if [ "x$val" != x ]; then
519 fail "ref $g unexpectedly exists ($val)"
525 echo refs/tags/$tagpfx/${v//\~/_}
529 git log -n1 --pretty=format:"$1" "$2"
532 t-sametree-parent () {
535 local ctree=$(t-format-ref '%T' "$ref")
538 for parent in $(t-format-ref '%P' "$ref"); do
539 local ptree=$(t-format-ref '%T' "$parent")
540 if [ "x$ptree" = "x$ctree" ]; then
544 case "$psame" in ""|" * *") break ;; esac
550 t-check-pushed-master () {
551 local master=`t-git-get-ref refs/heads/master`
552 if [ x$master = x$t_ref_val ]; then return; fi
553 if [ x$master = x ]; then fail "failed to push master"; fi
554 # didn't update master, it must be not FF
555 local mbase=`t-git-merge-base $master $t_ref_val`
556 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
561 local suite=${2:-sid}
567 t-pushed-good-core () {
571 refs/remotes/dgit/dgit/$suite
573 refs/heads/dgit/unstable \
574 refs/remotes/dgit/dgit/unstable
575 (set -e; cd $dgitrepo
579 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
583 git verify-tag `t-v-tag`
586 t-splitbrain-pushed-good--unpack () {
591 ln -s $tmp/mirror/pool/main/*.orig*.tar* .
592 ln -s $incoming_dsc .
593 ln -s ${incoming_dsc/.dsc/.debian.tar}* .
594 dpkg-source "$@" -x *.dsc
597 git fetch ../../$p "refs/tags/*:refs/tags/*"
600 t-splitbrain-pushed-good--checkprep () {
602 git rm --cached -r --ignore-unmatch .pc
605 t-splitbrain-pushed-good--checkdiff () {
607 t-splitbrain-pushed-good--checkprep
608 t-output "" git diff --stat --cached $tag
611 t-splitbrain-pushed-good-start () {
612 dep14tag=refs/tags/test-dummy/${v//\~/_}
614 t-output "" git status --porcelain
616 t-refs-same $dep14tag
617 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
618 git merge-base --is-ancestor $dep14tag $dgittag
625 t-splitbrain-pushed-good--unpack
626 t-splitbrain-pushed-good--checkdiff $dgittag
628 t-splitbrain-pushed-good-end-made-dep14 () {
629 t-splitbrain-pushed-good--checkdiff $dep14tag
633 t-splitbrain-rm-gitignore-patch () {
635 next unless $_ eq "auto-gitignore\n";
638 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
640 ' debian/patches/series
643 t-gbp-pushed-good () {
644 local suite=${1:-sid}
645 t-splitbrain-pushed-good-start
647 # Right, now we want to check that the maintainer tree and
648 # the dgit tree differ in exactly the ways we expect. We
649 # achieve this by trying to reconstruct the maintainer tree
650 # from the dgit tree.
652 # So, unpack it withut the patches applied
653 t-splitbrain-pushed-good--unpack --skip-patches
655 # dgit might have added a .gitignore patch, which we need to
657 t-splitbrain-rm-gitignore-patch
659 # Now the result should differ only in non-debian/ .gitignores
660 t-splitbrain-pushed-good--checkprep
661 git diff --cached --name-only $dep14tag >../changed
663 next if !m#^debian/# && m#(^|/)\.gitignore#;
667 # If we actually apply the gitignore patch by hand, it
669 if [ -f ../t-auto-gitignore ]; then
670 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
673 t-splitbrain-pushed-good-end-made-dep14
676 t-unapplied-pushed-good () {
677 t-splitbrain-pushed-good-start
678 t-splitbrain-pushed-good--unpack --skip-patches
679 t-splitbrain-pushed-good-end-made-dep14
682 t-dpm-pushed-good () {
683 t-splitbrain-pushed-good-start
684 t-splitbrain-pushed-good--unpack
685 t-splitbrain-rm-gitignore-patch
686 t-splitbrain-pushed-good-end-made-dep14
689 t-commit-build-push-expect-log () {
695 t-dgit push --new 2>&1 |tee $tmp/push.log
696 t-grep-mpat "$mpat" $tmp/push.log
703 use Dpkg::Control::Hash;
704 my $h = new Dpkg::Control::Hash allow_pgp=>1;
705 $h->parse(\*STDIN,"'"$file"'");
706 my $val = $h->{"'$field'"},"\n";
707 die "'"$file $field"'" unless defined $val;
719 "") '$var'="$tstunt" ;;
720 *) '$var'="$tstunt:$'$var'" ;;
727 local tstunt=$tmp/tstunt
728 t-stunt-envvar PATH $tstunt
729 t-stunt-envvar PERLLIB $tstunt
733 local d="$tstunt/${f%/*}"
735 ln -sf "$troot/tstunt/$f" "$d"/.
739 t-tstunt-parsechangelog () {
740 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
744 local dsc=${p}_${v}.dsc
745 incoming_dsc=$tmp/incoming/$dsc
750 local val=`t-822-field $incoming_dsc Dgit`
751 perl -e '$_=shift @ARGV; die "Dgit $_ ?" unless m/^\w+\b/;' "$val"
752 t-ref-same-val $incoming_dsc "$val"
759 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
763 t-gbp-unapplied-pq2qc () {
764 # does `gbp pq export'
765 # commits the resulting debian/patches on qc/BRANCH
766 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
767 # qc/BRANCH is not fast-forwarding
771 branch=`git symbolic-ref HEAD`
772 branch=${branch#refs/heads/}
775 */*) fail "unexpected branch $branch" ;;
778 git branch -f qc/$branch
779 git checkout qc/$branch
780 git add debian/patches
781 git commit -m 'Commit patch queue'
784 t-git-pseudo-merge () {
785 # like git merge -s ours
786 if [ ! "$git_pseuomerge_opts" ]; then
787 if git merge --help \
788 | grep -q allow-unrelated-histories; then
789 git_pseuomerge_opts='--allow-unrelated-histories'
791 git_pseuomerge_opts+=' -s ours'
793 git merge $git_pseuomerge_opts "$@"
796 t-gbp-example-prep-no-ff () {
797 t-tstunt-parsechangelog
798 t-archive example 1.0-1
806 git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
809 echo '/* some comment */' >>src.c
811 git commit -m 'Add a comment to an upstream file'
813 t-gbp-unapplied-pq2qc
815 t-commit 'some updates' 1.0-2
818 t-gbp-example-prep () {
819 t-gbp-example-prep-no-ff
822 -m 'Pseudo-merge to make descendant of archive' \
823 remotes/dgit/dgit/sid
828 v=${2:-${majorv:-1}.$revision}
829 dch -v$v --distribution ${3:-unstable} "$1"
830 git add debian/changelog
832 revision=$(( ${revision-0} + 1 ))
836 git config --global "$@"
840 export DGIT_TEST_TROOT=$troot
841 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
842 t-git-config dgit-distro.test-dummy.git-check true
843 t-git-config dgit-distro.test-dummy.git-create true
844 t-git-config dgit-distro.test-dummy.dgit-tag-format new,old,maint
845 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
846 cp $troot/suites $tmp/.
847 cp $troot/suites $tmp/suites-master
849 export t_check_pushed_master=t-check-pushed-master
851 drs_dispatch=$tmp/distro=test-dummy
854 if [ "x$DGIT_TEST_INTREE" != x ]; then
855 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
858 ln -sf $tmp/git $drs_dispatch/repos
859 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
860 mkdir -p $drs_dispatch/keyrings
861 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
862 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
863 ln -sf /bin/true $drs_dispatch/policy-hook
867 export tagpfx=archive/test-dummy
868 t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
871 export tagpfx=test-dummy
872 t-git-config dgit-distro.test-dummy.dgit-tag-format old
877 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
878 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
879 t-git-config dgit-distro.test-dummy.git-create true
880 t-git-config dgit-distro.test-dummy.git-url \
881 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
883 t-git-config dgit-distro.test-dummy.diverts.drs /drs
884 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
885 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
886 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
887 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
889 echo 'no-such-package* drs' >$drs_dispatch/diverts
893 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
896 t-policy-nonexist () {
897 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
900 t-make-hook-link () {
901 local hook=$1 # in infra/
903 hook=${DGIT_INFRA_PFX}$hook
906 *) hook=`type -P $hook` ;;
908 ln -sf "$hook" $linkpath
913 t-make-hook-link $policyhook $drs_dispatch/policy-hook
918 t-policy dgit-repos-policy-debian
921 t-policy-admin create-db
924 t-policy-periodic () {
925 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
926 test-dummy $drs_dispatch '' --cron
931 (cd $root; t-restriction-$restriction >&2)
935 : "Hopefully installed: $*"
942 export DGIT_TEST_TESTNAME="$testname"
943 export DGIT_TEST_TMPBASE="$tmpbase"
951 t-chain-test "${t#*-}"
956 *) t-setup-import gnupg ;;