17 lines: ${BASH_LINENO[*]}
18 files: ${BASH_SOURCE[*]}
23 trap 'test $? = 0 || t-report-failure' EXIT
25 t-filter-out-git-hyphen-dir
29 : ${DGIT_TEST_DEBUG=-D}
30 export DGIT_TEST_DEBUG
32 : ${DGIT_TEST_DISTRO+ ${distro=${DGIT_TEST_DISTRO}}}
34 export GIT_COMMITTER_DATE='1515000000 +0100'
35 export GIT_AUTHOR_DATE='1515000000 +0100'
39 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
40 export DGIT_TEST_TROOT=$troot
43 if [ x"$tmp" = x ]; then
46 tmp=tests/tmp/$testname
49 elif [ "x$DGIT_TEST_TMPBASE" != x ]; then
50 tmpbase="$DGIT_TEST_TMPBASE"
58 test -f $tmp/.save-env || \
59 env -0 >$tmp/.save-env
63 export DEBCHANGE_VENDOR=dpkg
65 mkdir -p $tmp/incoming
66 cat <<END >$tmp/dput.cf
69 incoming = $tmp/incoming
73 : ${t_archive_method:=aq}
74 : ${tagpfx:=archive/test-dummy}
75 : ${suitespecs:=sid:unstable}
78 GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
79 GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
83 local mpat="$1"; shift
86 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
87 local ps="${PIPESTATUS[*]}"
91 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
93 *) fail "tee failed" ;;
96 t-grep-mpat "$mpat" $tmp/t.output
107 E:*) grepper=egrep ;;
108 F:*) grepper=fgrep ;;
109 *) fail "bad mpat prefix in $mpat";;
115 $grepper -e "$mpat" "$file" ||
116 fail "message not found"
119 t-expect-push-fail () {
120 local mpat="$1"; shift
122 local triedpush; triedpush=`git rev-parse HEAD`
125 t-expect-fail "$mpat" "$@"
127 diff $tmp/show-refs.{pre,post}-push
129 t-git-objects-not-present '' $triedpush
131 eval "$t_expect_push_fail_hook"
134 t-git-objects-not-present () {
135 # t-git-objects-not-present GITDIR|'' OBJID [...]
136 # specifying '' means the repo for package $p
137 local gitdir="${1-$dgitrepo}"
139 if ! [ -e "$gitdir" ]; then return; fi
142 t-expect-fail 'unable to find' \
148 local whichoutput=$1; shift
149 local whichrepo=${1-$dgitrepo}
150 local outputfile="$tmp/show-refs.$whichoutput"
153 if test -d $whichrepo; then
161 local edittree=$1.edit
162 if test -d "$edittree"; then
163 cp -a "$edittree"/* .
171 t-untar $troot/worktrees/${p}_$1
174 t-select-package () {
176 dgitrepo=$tmp/git/$p.git
183 local gs=$troot/git-srcs/${p}_$v.git
184 (set -e; cd $tmp/git; t-untar $gs)
189 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
192 t-salsa-add-remote () {
193 local d=$tmp/salsa/$p
195 (set -e; cd $d; git init --bare)
196 git remote add ${1-origin} $d
199 t-git-merge-base () {
200 git merge-base $1 $2 || test $? = 1
204 # t-has-ancestor ANCESTOR
205 # (CHILD is implicit, HEAD)
206 local now; now=`git rev-parse HEAD`
207 local ancestor; ancestor=`git rev-parse $1^{}`
208 local mbase; mbase=`t-git-merge-base $ancestor $now`
209 if [ x$mbase != x$ancestor ]; then
210 fail "not ff $ancestor..$now, $mbase != $ancestor"
214 t-has-parent-or-is () {
215 # t-has-parent-or-is CHILD PARENT
219 parents=$(git show --pretty=format:' %P %H ' "$child")
220 parent=$(git rev-parse "$parent~0")
223 *) fail "child $child lacks parent $parent" ;;
227 t-prep-newpackage () {
234 if ! git show-ref --verify --quiet refs/heads/master; then
235 git branch -m dgit/sid master
243 t-archive-none-$t_archive_method
245 t-archive-none-aq () {
246 mkdir -p $tmp/aq/dsc_in_suite $tmp/mirror/pool/main
252 for suitespec in $suitespecs; do
253 local suite=${suitespec%%:*}
254 local sname=${suitespec#*:}
256 >$tmp/aq/package.$suite.$p
257 t-aq-archive-updated $suite $p
259 >$tmp/aq/package.new.$p
260 t-aq-archive-updated new $p
262 ln -sf $suite $tmp/aq/dsc_in_suite/$sname
264 cat <<END >>$tmp/aq/suites
267 "archive" : "ftp-master",
268 "codename" : "$suite",
281 cat <<END >>$tmp/aq/suites
287 t-aq-archive-updated () {
290 local suitedir=$tmp/aq/dsc_in_suite/$suite
292 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
296 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
304 my $json = JSON->new->canonical();
305 print $json->encode(\@v) or die $!;
310 t-archive-process-incoming () {
312 mv $tmp/incoming/${p}_* $tmp/mirror/pool/main/
313 t-archive-query "$suite"
318 local dscf=main/${p}_${v}.dsc
319 t-archive-query-$t_archive_method "$suite" "$p" "$v" "$dscf"
321 t-archive-query-aq () {
326 local sha; sha=`sha256sum <$tmp/mirror/pool/$dscf`
327 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
328 t-aq-archive-updated $suite $p
334 local dscf=${p}_$2.dsc
335 rm -f $tmp/mirror/pool/main/${p}_*
336 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
337 t-archive-query $suite
340 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
343 t-git-dir-time-passes () {
344 touch -d 'last year' $dgitrepo
348 local gitdir=$dgitrepo
351 if test -e "$gitdir"; then fail "$gitdir exists"; fi
354 public) wantstat='7[75]5' ;;
355 secret) wantstat='7[70]0' ;;
356 *) fail "$1 t-git-dir-check ?" ;;
358 gotstat=`stat -c%a $gitdir`
360 *$wantstat) return ;;
361 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
365 t-expect-fsck-fail () {
366 echo >>$tmp/fsck.expected-errors "$1"
370 local fsckerrs=$(git rev-parse --git-dir)/dgit-test-fsck.errs
373 LC_MESSAGES=C git fsck --no-dangling --strict 2>&1 \
375 ps="${PIPESTATUS[*]}"
379 if [ -f $tmp/fsck.expected-errors ]; then
380 pats=(-w -f $tmp/fsck.expected-errors)
384 pats+=(-e 'notice: HEAD points to an unborn branch')
385 pats+=(-e 'notice: No default references')
388 grep -v "${pats[@]}" $fsckerrs
392 1) ;; # no unexpected errors
393 0) fail "unexpected messages from git-fsck" ;;
394 *) fail "grep of git-fsck failed" ;;
401 for d in $tmp/*/.git $tmp/git/*.git; do
409 : '========================================'
414 t-rm-dput-dropping () {
415 rm -f $tmp/${p}_${v}_*.upload
419 local dgit=${DGIT_TEST-dgit}
422 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
423 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
424 ${dgit_config_debian_alias-"--config-lookup-explode=dgit-distro.debian.alias-canon"} \
425 ${distro+${distro:+-d}}${distro--dtest-dummy} \
426 $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
427 -kBCD22CD83243B79D3DFAC33EA3DBCBC039B13D8A $t_dgit_xopts "$@"
428 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
435 (export LC_ALL=C.UTF-8
436 if [ "$DGIT_TEST_INTREE" ]; then
437 make -C $DGIT_TEST_INTREE $page.$section.view
444 diff --exclude=.git --exclude=.pc -ruN $*
447 t-files-notexist () {
456 t-cloned-fetched-good () {
457 t-diff-nogit ../extract/$p-${v%-*} .
458 t-clean-on-branch dgit/sid
461 refs/heads/dgit/sid \
462 refs/remotes/dgit/dgit/sid
463 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
467 printf "%s${1:+\n}" "$1" >$tmp/t.want
470 diff $tmp/t.want $tmp/t.got
473 t-clean-on-branch () {
474 t-output "## $1" git status -b --porcelain
482 local import=IMPORT.${0##*/}
483 exec 4>$tmp/$import.new
486 for vn in $savevars; do
487 perl >&4 -I. -MDebian::Dgit -e '
488 printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
489 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
492 (set -e; cd $tmp; tar cf $import.tar $savedirs)
494 printf >&4 "\n%s\n" "$importeval"
496 mv -f $tmp/$import.new $tmp/$import
504 if [ "x$tmpbase" = x ]; then
505 # ADTTMP was set on entry to tests/lib, so we
506 # are not sharing tmp area between tests
508 lock="$tmp/.dummy.lock"
510 setupsrc="$tmpbase/$setupname"
511 lock="$setupsrc.lock"
514 local simport="$setupsrc/IMPORT.$setupname"
516 if ! [ -e "$simport" ]; then
517 with-lock-ex -w "$lock" \
518 xargs -0 -a $tmp/.save-env \
521 setupname="$1"; shift
523 if [ -e "$simport" ]; then exit 0; fi
525 "tests/setup/$setupname"
526 ' x "$root" "$setupname" "$simport"
529 if [ "x$setupsrc" != "x$tmp" ]; then
530 (set -e; cd $tmp; tar xf "$simport.tar")
536 t-git-get-ref-exact () {
538 # does not dereference, unlike t-git-get-ref
541 *) fail "t-git-get-ref-exact bad $ref" ;;
543 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
550 *) fail "t-git-get-ref bad $ref" ;;
552 (git show-ref -d $1 || test $? = 1) | perl -ne '
553 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
554 END { print "$x\n" if length $x; }
558 t-ref-same-exact () {
560 local val; val=`t-git-get-ref-exact $name`
561 t-ref-same-val "$name" $val
566 local val; val=`t-git-get-ref $name`
567 t-ref-same-val "$name" $val
571 local val; val=`git rev-parse HEAD`
572 t-ref-same-val HEAD $val
578 case "${t_ref_val-unset}" in
581 *) fail "ref varies: ($name)\
582 ${val:-nothing} != ${t_ref_val:-nothing} (${t_ref_names[*]})" ;;
585 t_ref_names+=("$name")
588 t-refs-same-start () {
603 val=`t-git-get-ref $g`
604 if [ "x$val" != x ]; then
605 fail "ref $g unexpectedly exists ($val)"
611 echo refs/tags/$tagpfx/${v//\~/_}
615 git log -n1 --pretty=format:"$1" "$2"
618 t-sametree-parent () {
621 local ctree; ctree=$(t-format-ref '%T' "$ref")
624 for parent in $(t-format-ref '%P' "$ref"); do
625 local ptree; ptree=$(t-format-ref '%T' "$parent")
626 if [ "x$ptree" = "x$ctree" ]; then
630 case "$psame" in ""|" * *") break ;; esac
636 t-check-pushed-master () {
637 local master; master=`t-git-get-ref refs/heads/master`
638 if [ x$master = x$t_ref_val ]; then return; fi
639 if [ x$master = x ]; then fail "failed to push master"; fi
640 # didn't update master, it must be not FF
641 local mbase; mbase=`t-git-merge-base $master $t_ref_val`
642 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
645 t-push-was-source-only () {
647 t-files-notexist $tmp/incoming/${p}_${v}_*.deb \
648 $tmp/incoming/${p}_${v}_*.udeb
649 # we permit _source.buildinfo files; see test_changes_source_only()
650 for f in $tmp/incoming/${p}_${v}_*.buildinfo; do
653 *_source.buildinfo) ;;
654 *) fail "non-source-only file $f exists!" ;;
662 local suite=${2:-sid}
668 t-pushed-good-core () {
672 refs/remotes/dgit/dgit/$suite
674 refs/heads/dgit/unstable \
675 refs/remotes/dgit/dgit/unstable
676 (set -e; cd $dgitrepo
680 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
684 git verify-tag `t-v-tag`
687 t-splitbrain-pushed-good--unpack () {
692 ln -s $tmp/mirror/pool/main/*.orig*.tar* .
693 ln -s $tmp/incoming/*.orig*.tar* . ||:
694 ln -s $incoming_dsc .
695 ln -s ${incoming_dsc/.dsc/.debian.tar}* .
696 dpkg-source "$@" -x *.dsc
699 git fetch ../../$p "refs/tags/*:refs/tags/*"
702 t-splitbrain-pushed-good--checkprep () {
704 git rm --cached -r --ignore-unmatch .pc
707 t-splitbrain-pushed-good--checkdiff () {
709 t-splitbrain-pushed-good--checkprep
710 t-output "" git diff --stat --cached $tag
713 t-splitbrain-pushed-good-start () {
714 dep14tag=refs/tags/test-dummy/${v//\~/_}
716 t-output "" git status --porcelain
718 t-refs-same $dep14tag
719 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
720 git merge-base --is-ancestor $dep14tag $dgittag
723 t-ref-same refs/heads/split.p
724 case "$(t-git-get-ref refs/heads/split.b)" in
726 "$(git rev-parse refs/heads/split.p^0)") ;;
727 "$(git rev-parse refs/heads/split.p^1)") ;;
734 t-splitbrain-pushed-good--unpack
735 t-splitbrain-pushed-good--checkdiff $dgittag
737 t-splitbrain-pushed-good-end-made-dep14 () {
738 t-splitbrain-pushed-good--checkdiff $dep14tag
742 t-splitbrain-rm-gitignore-patch () {
744 next unless $_ eq "auto-gitignore\n";
747 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
749 ' debian/patches/series
752 t-gbp-pushed-good () {
753 local suite=${1:-sid}
754 t-splitbrain-pushed-good-start
756 # Right, now we want to check that the maintainer tree and
757 # the dgit tree differ in exactly the ways we expect. We
758 # achieve this by trying to reconstruct the maintainer tree
759 # from the dgit tree.
761 # So, unpack it withut the patches applied
762 t-splitbrain-pushed-good--unpack --skip-patches
764 # dgit might have added a .gitignore patch, which we need to
766 t-splitbrain-rm-gitignore-patch
768 # Now the result should differ only in non-debian/ .gitignores
769 t-splitbrain-pushed-good--checkprep
770 git diff --cached --name-only $dep14tag >../changed
772 next if !m#^debian/# && m#(^|/)\.gitignore#;
776 # If we actually apply the gitignore patch by hand, it
778 if [ -f ../t-auto-gitignore ]; then
779 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
782 t-splitbrain-pushed-good-end-made-dep14
785 t-unapplied-pushed-good () {
786 t-splitbrain-pushed-good-start
787 t-splitbrain-pushed-good--unpack --skip-patches
788 t-splitbrain-pushed-good-end-made-dep14
791 t-dpm-pushed-good () {
792 t-splitbrain-pushed-good-start
793 t-splitbrain-pushed-good--unpack
794 t-splitbrain-rm-gitignore-patch
795 t-splitbrain-pushed-good-end-made-dep14
798 t-commit-build-push-expect-log () {
804 t-dgit push --new 2>&1 |tee $tmp/push.log
805 t-grep-mpat "$mpat" $tmp/push.log
812 use Dpkg::Control::Hash;
813 my $h = new Dpkg::Control::Hash allow_pgp=>1;
814 $h->parse(\*STDIN,"'"$file"'");
815 my $val = $h->{"'$field'"},"\n";
816 die "'"$file $field"'" unless defined $val;
822 export DGIT_TEST_DISTRO=''
824 t-git-config dgit-suite.unstable.distro test-dummy
834 "") '$var'="$tstunt" ;;
835 *) '$var'="$tstunt:$'$var'" ;;
841 t-tstunt--save-real () {
852 p="${p/:"$tmp/tstunt":/:}"
864 *) fail "did not find $f on PATH $PATH" ;;
867 local varname=${f//[^_0-9a-zA-Z]/_}
868 varname=DGIT_TEST_REAL_${varname^^}
871 : \${$varname:=\$real}
877 local tstunt=$tmp/tstunt
878 t-stunt-envvar PATH $tstunt
879 t-stunt-envvar PERLLIB $tstunt
882 t-tstunt--save-real $f
884 local d="$tstunt/${f%/*}"
886 ln -sf "$troot/tstunt/$f" "$d"/.
890 t-tstunt-parsechangelog () {
891 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
894 t-tstunt-lintian () {
898 t-tstunt-debuild () {
903 local dsc=${p}_${v}.dsc
904 incoming_dsc=$tmp/incoming/$dsc
909 local val; val=`t-822-field $incoming_dsc Dgit`
912 die "Dgit $_ ?" unless m/^\w+\b/;
913 print $&,"\n" or die $!;
915 t-ref-same-val $incoming_dsc "$val"
922 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
926 t-gbp-unapplied-pq2qc () {
927 # does `gbp pq export'
928 # commits the resulting debian/patches on qc/BRANCH
929 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
930 # qc/BRANCH is not fast-forwarding
934 branch=`git symbolic-ref HEAD`
935 branch=${branch#refs/heads/}
938 */*) fail "unexpected branch $branch" ;;
941 git branch -f qc/$branch
942 git checkout qc/$branch
943 git add debian/patches
944 git commit -m 'Commit patch queue'
947 t-git-pseudo-merge () {
948 # like git merge -s ours
949 if [ ! "$git_pseuomerge_opts" ]; then
950 if git merge --help \
951 | grep -q allow-unrelated-histories; then
952 git_pseuomerge_opts='--allow-unrelated-histories'
954 git_pseuomerge_opts+=' -s ours'
956 git merge $git_pseuomerge_opts "$@"
959 t-gbp-example-prep-no-ff () {
960 t-tstunt-parsechangelog
961 t-archive example 1.0-1
969 git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
972 echo '/* some comment */' >>src.c
974 git commit -m 'Add a comment to an upstream file'
976 t-gbp-unapplied-pq2qc
978 t-commit 'some updates' 1.0-2
981 t-gbp-example-prep () {
982 t-gbp-example-prep-no-ff
985 -m 'Pseudo-merge to make descendant of archive' \
986 remotes/dgit/dgit/sid
989 t-make-badcommit () {
991 git cat-file commit HEAD | \
992 perl -pe 's/^committer /commiter /' | \
993 git hash-object -w -t commit --stdin
995 t-expect-fsck-fail $badcommit
1000 v=${2:-${majorv:-1}.$revision}
1001 dch --force-distribution -v$v --distribution ${3:-unstable} "$1"
1002 git add debian/changelog
1004 revision=$(( ${revision-0} + 1 ))
1008 faketime @"${GIT_AUTHOR_DATE% *}" dch "$@"
1009 git commit -m "dch $*" debian/changelog
1013 git config --global "$@"
1017 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
1018 t-git-config dgit-distro.test-dummy.git-check true
1019 t-git-config dgit-distro.test-dummy.git-create true
1020 t-git-config dgit-distro.test-dummy.dgit-tag-format new,old,maint
1021 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
1022 cp $troot/suites $tmp/.
1023 cp $troot/suites $tmp/suites-master
1025 export t_check_pushed_master=t-check-pushed-master
1027 drs_dispatch=$tmp/distro=test-dummy
1030 if [ "x$DGIT_TEST_INTREE" != x ]; then
1031 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
1034 ln -sf $tmp/git $drs_dispatch/repos
1035 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
1036 mkdir -p $drs_dispatch/keyrings
1037 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
1038 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
1039 ln -sf /bin/true $drs_dispatch/policy-hook
1043 export tagpfx=archive/test-dummy
1044 t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
1047 export tagpfx=test-dummy
1048 t-git-config dgit-distro.test-dummy.dgit-tag-format old
1053 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
1054 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
1055 t-git-config dgit-distro.test-dummy.git-create true
1056 t-git-config dgit-distro.test-dummy.git-url \
1057 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
1059 t-git-config dgit-distro.test-dummy.diverts.drs /drs
1060 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
1061 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
1062 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
1063 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
1065 echo 'no-such-package* drs' >$drs_dispatch/diverts
1069 : '(((((((((((((((((((((((((((((((((((((((('
1070 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
1071 : '))))))))))))))))))))))))))))))))))))))))'
1074 t-policy-nonexist () {
1075 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
1078 t-make-hook-link () {
1079 local hook=$1 # in infra/
1081 hook=${DGIT_INFRA_PFX}$hook
1084 *) hook=`type -P $hook` ;;
1086 ln -sf "$hook" $linkpath
1091 t-make-hook-link $policyhook $drs_dispatch/policy-hook
1096 t-policy dgit-repos-policy-debian
1099 t-policy-admin create-db
1102 t-policy-periodic () {
1103 : '(((((((((((((((((((((((((((((((((((((((('
1104 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
1105 test-dummy $drs_dispatch '' --cron
1106 : '))))))))))))))))))))))))))))))))))))))))'
1110 local restriction=$1
1111 (cd $root; t-restriction-$restriction >&2)
1115 : "Hopefully installed: $*"
1122 export DGIT_TEST_TESTNAME="$testname"
1123 export DGIT_TEST_TMPBASE="$tmpbase"
1131 t-chain-test "${t#*-}"
1134 t-git-config dgit.default.old-dsc-distro test-dummy
1138 *) t-setup-import gnupg ;;