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 : ${t_archive_method:=aq}
69 : ${tagpfx:=archive/test-dummy}
70 : ${suitespecs:=sid:unstable}
73 GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
74 GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
78 local mpat="$1"; shift
81 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
82 local ps="${PIPESTATUS[*]}"
86 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
88 *) fail "tee failed" ;;
91 t-grep-mpat "$mpat" $tmp/t.output
102 E:*) grepper=egrep ;;
103 F:*) grepper=fgrep ;;
104 *) fail "bad mpat prefix in $mpat";;
110 $grepper -e "$mpat" "$file" ||
111 fail "message not found"
114 t-expect-push-fail () {
115 local mpat="$1"; shift
117 local triedpush=`git rev-parse HEAD`
120 t-expect-fail "$mpat" "$@"
122 diff $tmp/show-refs.{pre,post}-push
124 t-git-objects-not-present '' $triedpush
126 eval "$t_expect_push_fail_hook"
129 t-git-objects-not-present () {
130 # t-git-objects-not-present GITDIR|'' OBJID [...]
131 # specifying '' means the repo for package $p
132 local gitdir="${1-$dgitrepo}"
134 if ! [ -e "$gitdir" ]; then return; fi
137 t-expect-fail 'unable to find' \
143 local whichoutput=$1; shift
144 local whichrepo=${1-$dgitrepo}
145 local outputfile="$tmp/show-refs.$whichoutput"
148 if test -d $whichrepo; then
156 local edittree=$1.edit
157 if test -d "$edittree"; then
158 cp -a "$edittree"/* .
166 t-untar $troot/worktrees/${p}_$1
169 t-select-package () {
171 dgitrepo=$tmp/git/$p.git
178 local gs=$troot/git-srcs/${p}_$v.git
179 (set -e; cd $tmp/git; t-untar $gs)
184 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
187 t-git-merge-base () {
188 git merge-base $1 $2 || test $? = 1
192 # t-has-ancestor ANCESTOR
193 # (CHILD is implicit, HEAD)
194 local now=`git rev-parse HEAD`
195 local ancestor=`git rev-parse $1^{}`
196 local mbase=`t-git-merge-base $ancestor $now`
197 if [ x$mbase != x$ancestor ]; then
198 fail "not ff $ancestor..$now, $mbase != $ancestor"
202 t-has-parent-or-is () {
203 # t-has-parent-or-is CHILD PARENT
206 local parents=$(git show --pretty=format:' %P %H ' "$child")
207 parent=$(git rev-parse "$parent~0")
210 *) fail "child $child lacks parent $parent" ;;
214 t-prep-newpackage () {
221 if ! git show-ref --verify --quiet refs/heads/master; then
222 git branch -m dgit/sid master
230 t-archive-none-$t_archive_method
232 t-archive-none-aq () {
233 mkdir -p $tmp/aq/dsc_in_suite $tmp/mirror/pool/main
239 for suitespec in $suitespecs; do
240 local suite=${suitespec%%:*}
241 local sname=${suitespec#*:}
243 >$tmp/aq/package.$suite.$p
244 t-aq-archive-updated $suite $p
246 >$tmp/aq/package.new.$p
247 t-aq-archive-updated new $p
249 ln -sf $suite $tmp/aq/dsc_in_suite/$sname
251 cat <<END >>$tmp/aq/suites
254 "archive" : "ftp-master",
255 "codename" : "$suite",
268 cat <<END >>$tmp/aq/suites
274 t-aq-archive-updated () {
277 local suitedir=$tmp/aq/dsc_in_suite/$suite
279 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
283 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
291 my $json = JSON->new->canonical();
292 print $json->encode(\@v) or die $!;
297 t-archive-process-incoming () {
299 mv $tmp/incoming/${p}_* $tmp/mirror/pool/main/
300 t-archive-query "$suite"
305 local dscf=main/${p}_${v}.dsc
306 t-archive-query-$t_archive_method "$suite" "$p" "$v" "$dscf"
308 t-archive-query-aq () {
313 local sha=`sha256sum <$tmp/mirror/pool/$dscf`
314 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
315 t-aq-archive-updated $suite $p
321 local dscf=${p}_$2.dsc
322 rm -f $tmp/mirror/pool/main/${p}_*
323 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
327 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
330 t-git-dir-time-passes () {
331 touch -d 'last year' $dgitrepo
335 local gitdir=$dgitrepo
338 if test -e "$gitdir"; then fail "$gitdir exists"; fi
341 public) wantstat='7[75]5' ;;
342 secret) wantstat='7[70]0' ;;
343 *) fail "$1 t-git-dir-check ?" ;;
345 gotstat=`stat -c%a $gitdir`
347 *$wantstat) return ;;
348 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
352 t-rm-dput-dropping () {
353 rm -f $tmp/${p}_${v}_*.upload
357 local dgit=${DGIT_TEST-dgit}
360 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
361 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
362 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
363 -k39B13D8A $t_dgit_xopts "$@"
364 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
369 diff --exclude=.git --exclude=.pc -ruN $*
372 t-files-notexist () {
381 t-cloned-fetched-good () {
382 t-diff-nogit ../extract/$p-${v%-*} .
383 t-clean-on-branch dgit/sid
386 refs/heads/dgit/sid \
387 refs/remotes/dgit/dgit/sid
388 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
392 printf "%s${1:+\n}" "$1" >$tmp/t.want
395 diff $tmp/t.want $tmp/t.got
398 t-clean-on-branch () {
399 t-output "## $1" git status -b --porcelain
407 local import=IMPORT.${0##*/}
408 exec 4>$tmp/$import.new
411 for vn in $savevars; do
412 perl >&4 -I. -MDebian::Dgit -e '
413 printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
414 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
417 (set -e; cd $tmp; tar cf $import.tar $savedirs)
419 printf >&4 "\n%s\n" "$importeval"
421 mv -f $tmp/$import.new $tmp/$import
429 if [ "x$tmpbase" = x ]; then
430 # ADTTMP was set on entry to tests/lib, so we
431 # are not sharing tmp area between tests
433 lock="$tmp/.dummy.lock"
435 setupsrc="$tmpbase/$setupname"
436 lock="$setupsrc.lock"
439 local simport="$setupsrc/IMPORT.$setupname"
441 if ! [ -e "$simport" ]; then
442 with-lock-ex -w "$lock" \
443 xargs -0 -a $tmp/.save-env \
446 setupname="$1"; shift
448 if [ -e "$simport" ]; then exit 0; fi
450 "tests/setup/$setupname"
451 ' x "$root" "$setupname" "$simport"
454 if [ "x$setupsrc" != "x$tmp" ]; then
455 (set -e; cd $tmp; tar xf "$simport.tar")
461 t-git-get-ref-exact () {
463 # does not dereference, unlike t-git-get-ref
466 *) fail "t-git-get-ref-exact bad $ref" ;;
468 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
475 *) fail "t-git-get-ref bad $ref" ;;
477 (git show-ref -d $1 || test $? = 1) | perl -ne '
478 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
479 END { print "$x\n" if length $x; }
483 t-ref-same-exact () {
485 local val=`t-git-get-ref-exact $name`
486 t-ref-same-val "$name" $val
491 local val=`t-git-get-ref $name`
492 t-ref-same-val "$name" $val
496 local val=`git rev-parse HEAD`
497 t-ref-same-val HEAD $val
503 case "${t_ref_val-unset}" in
506 *) fail "ref varies: ($name)\
507 ${val:-nothing} != ${t_ref_val:-nothing} (${t_ref_names[*]})" ;;
510 t_ref_names+=("$name")
513 t-refs-same-start () {
528 val=`t-git-get-ref $g`
529 if [ "x$val" != x ]; then
530 fail "ref $g unexpectedly exists ($val)"
536 echo refs/tags/$tagpfx/${v//\~/_}
540 git log -n1 --pretty=format:"$1" "$2"
543 t-sametree-parent () {
546 local ctree=$(t-format-ref '%T' "$ref")
549 for parent in $(t-format-ref '%P' "$ref"); do
550 local ptree=$(t-format-ref '%T' "$parent")
551 if [ "x$ptree" = "x$ctree" ]; then
555 case "$psame" in ""|" * *") break ;; esac
561 t-check-pushed-master () {
562 local master=`t-git-get-ref refs/heads/master`
563 if [ x$master = x$t_ref_val ]; then return; fi
564 if [ x$master = x ]; then fail "failed to push master"; fi
565 # didn't update master, it must be not FF
566 local mbase=`t-git-merge-base $master $t_ref_val`
567 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
572 local suite=${2:-sid}
578 t-pushed-good-core () {
582 refs/remotes/dgit/dgit/$suite
584 refs/heads/dgit/unstable \
585 refs/remotes/dgit/dgit/unstable
586 (set -e; cd $dgitrepo
590 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
594 git verify-tag `t-v-tag`
597 t-splitbrain-pushed-good--unpack () {
602 ln -s $tmp/mirror/pool/main/*.orig*.tar* .
603 ln -s $tmp/incoming/*.orig*.tar* . ||:
604 ln -s $incoming_dsc .
605 ln -s ${incoming_dsc/.dsc/.debian.tar}* .
606 dpkg-source "$@" -x *.dsc
609 git fetch ../../$p "refs/tags/*:refs/tags/*"
612 t-splitbrain-pushed-good--checkprep () {
614 git rm --cached -r --ignore-unmatch .pc
617 t-splitbrain-pushed-good--checkdiff () {
619 t-splitbrain-pushed-good--checkprep
620 t-output "" git diff --stat --cached $tag
623 t-splitbrain-pushed-good-start () {
624 dep14tag=refs/tags/test-dummy/${v//\~/_}
626 t-output "" git status --porcelain
628 t-refs-same $dep14tag
629 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
630 git merge-base --is-ancestor $dep14tag $dgittag
633 t-ref-same refs/heads/split.p
634 case "$(t-git-get-ref refs/heads/split.b)" in
636 "$(git rev-parse refs/heads/split.p^0)") ;;
637 "$(git rev-parse refs/heads/split.p^1)") ;;
644 t-splitbrain-pushed-good--unpack
645 t-splitbrain-pushed-good--checkdiff $dgittag
647 t-splitbrain-pushed-good-end-made-dep14 () {
648 t-splitbrain-pushed-good--checkdiff $dep14tag
652 t-splitbrain-rm-gitignore-patch () {
654 next unless $_ eq "auto-gitignore\n";
657 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
659 ' debian/patches/series
662 t-gbp-pushed-good () {
663 local suite=${1:-sid}
664 t-splitbrain-pushed-good-start
666 # Right, now we want to check that the maintainer tree and
667 # the dgit tree differ in exactly the ways we expect. We
668 # achieve this by trying to reconstruct the maintainer tree
669 # from the dgit tree.
671 # So, unpack it withut the patches applied
672 t-splitbrain-pushed-good--unpack --skip-patches
674 # dgit might have added a .gitignore patch, which we need to
676 t-splitbrain-rm-gitignore-patch
678 # Now the result should differ only in non-debian/ .gitignores
679 t-splitbrain-pushed-good--checkprep
680 git diff --cached --name-only $dep14tag >../changed
682 next if !m#^debian/# && m#(^|/)\.gitignore#;
686 # If we actually apply the gitignore patch by hand, it
688 if [ -f ../t-auto-gitignore ]; then
689 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
692 t-splitbrain-pushed-good-end-made-dep14
695 t-unapplied-pushed-good () {
696 t-splitbrain-pushed-good-start
697 t-splitbrain-pushed-good--unpack --skip-patches
698 t-splitbrain-pushed-good-end-made-dep14
701 t-dpm-pushed-good () {
702 t-splitbrain-pushed-good-start
703 t-splitbrain-pushed-good--unpack
704 t-splitbrain-rm-gitignore-patch
705 t-splitbrain-pushed-good-end-made-dep14
708 t-commit-build-push-expect-log () {
714 t-dgit push --new 2>&1 |tee $tmp/push.log
715 t-grep-mpat "$mpat" $tmp/push.log
722 use Dpkg::Control::Hash;
723 my $h = new Dpkg::Control::Hash allow_pgp=>1;
724 $h->parse(\*STDIN,"'"$file"'");
725 my $val = $h->{"'$field'"},"\n";
726 die "'"$file $field"'" unless defined $val;
738 "") '$var'="$tstunt" ;;
739 *) '$var'="$tstunt:$'$var'" ;;
746 local tstunt=$tmp/tstunt
747 t-stunt-envvar PATH $tstunt
748 t-stunt-envvar PERLLIB $tstunt
752 local d="$tstunt/${f%/*}"
754 ln -sf "$troot/tstunt/$f" "$d"/.
758 t-tstunt-parsechangelog () {
759 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
763 local dsc=${p}_${v}.dsc
764 incoming_dsc=$tmp/incoming/$dsc
769 local val=`t-822-field $incoming_dsc Dgit`
770 perl -e '$_=shift @ARGV; die "Dgit $_ ?" unless m/^\w+\b/;' "$val"
771 t-ref-same-val $incoming_dsc "$val"
778 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
782 t-gbp-unapplied-pq2qc () {
783 # does `gbp pq export'
784 # commits the resulting debian/patches on qc/BRANCH
785 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
786 # qc/BRANCH is not fast-forwarding
790 branch=`git symbolic-ref HEAD`
791 branch=${branch#refs/heads/}
794 */*) fail "unexpected branch $branch" ;;
797 git branch -f qc/$branch
798 git checkout qc/$branch
799 git add debian/patches
800 git commit -m 'Commit patch queue'
803 t-git-pseudo-merge () {
804 # like git merge -s ours
805 if [ ! "$git_pseuomerge_opts" ]; then
806 if git merge --help \
807 | grep -q allow-unrelated-histories; then
808 git_pseuomerge_opts='--allow-unrelated-histories'
810 git_pseuomerge_opts+=' -s ours'
812 git merge $git_pseuomerge_opts "$@"
815 t-gbp-example-prep-no-ff () {
816 t-tstunt-parsechangelog
817 t-archive example 1.0-1
825 git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
828 echo '/* some comment */' >>src.c
830 git commit -m 'Add a comment to an upstream file'
832 t-gbp-unapplied-pq2qc
834 t-commit 'some updates' 1.0-2
837 t-gbp-example-prep () {
838 t-gbp-example-prep-no-ff
841 -m 'Pseudo-merge to make descendant of archive' \
842 remotes/dgit/dgit/sid
847 v=${2:-${majorv:-1}.$revision}
848 dch -v$v --distribution ${3:-unstable} "$1"
849 git add debian/changelog
851 revision=$(( ${revision-0} + 1 ))
855 git config --global "$@"
859 export DGIT_TEST_TROOT=$troot
860 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
861 t-git-config dgit-distro.test-dummy.git-check true
862 t-git-config dgit-distro.test-dummy.git-create true
863 t-git-config dgit-distro.test-dummy.dgit-tag-format new,old,maint
864 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
865 cp $troot/suites $tmp/.
866 cp $troot/suites $tmp/suites-master
868 export t_check_pushed_master=t-check-pushed-master
870 drs_dispatch=$tmp/distro=test-dummy
873 if [ "x$DGIT_TEST_INTREE" != x ]; then
874 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
877 ln -sf $tmp/git $drs_dispatch/repos
878 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
879 mkdir -p $drs_dispatch/keyrings
880 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
881 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
882 ln -sf /bin/true $drs_dispatch/policy-hook
886 export tagpfx=archive/test-dummy
887 t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
890 export tagpfx=test-dummy
891 t-git-config dgit-distro.test-dummy.dgit-tag-format old
896 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
897 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
898 t-git-config dgit-distro.test-dummy.git-create true
899 t-git-config dgit-distro.test-dummy.git-url \
900 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
902 t-git-config dgit-distro.test-dummy.diverts.drs /drs
903 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
904 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
905 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
906 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
908 echo 'no-such-package* drs' >$drs_dispatch/diverts
912 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
915 t-policy-nonexist () {
916 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
919 t-make-hook-link () {
920 local hook=$1 # in infra/
922 hook=${DGIT_INFRA_PFX}$hook
925 *) hook=`type -P $hook` ;;
927 ln -sf "$hook" $linkpath
932 t-make-hook-link $policyhook $drs_dispatch/policy-hook
937 t-policy dgit-repos-policy-debian
940 t-policy-admin create-db
943 t-policy-periodic () {
944 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
945 test-dummy $drs_dispatch '' --cron
950 (cd $root; t-restriction-$restriction >&2)
954 : "Hopefully installed: $*"
961 export DGIT_TEST_TESTNAME="$testname"
962 export DGIT_TEST_TMPBASE="$tmpbase"
970 t-chain-test "${t#*-}"
975 *) t-setup-import gnupg ;;