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/
324 t-archive-query $suite
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-expect-fsck-fail () {
353 echo >>$tmp/fsck.expected-errors "$1"
358 LC_MESSAGES=C git fsck --no-dangling --strict 2>&1 \
359 | tee dgit-test-fsck.errs
360 ps="${PIPESTATUS[*]}"
364 if [ -f $tmp/fsck.expected-errors ]; then
365 pats=(-w -f $tmp/fsck.expected-errors)
369 pats+=(-e 'notice: HEAD points to an unborn branch')
370 pats+=(-e 'notice: No default references')
373 grep -v "${pats[@]}" dgit-test-fsck.errs
377 1) ;; # no unexpected errors
378 0) fail "unexpected messages from git-fsck" ;;
379 *) fail "grep of git-fsck failed" ;;
386 for d in $tmp/*/.git $tmp/git/*.git; do
398 t-rm-dput-dropping () {
399 rm -f $tmp/${p}_${v}_*.upload
403 local dgit=${DGIT_TEST-dgit}
406 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
407 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
408 -dtest-dummy $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
409 -k39B13D8A $t_dgit_xopts "$@"
410 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
415 diff --exclude=.git --exclude=.pc -ruN $*
418 t-files-notexist () {
427 t-cloned-fetched-good () {
428 t-diff-nogit ../extract/$p-${v%-*} .
429 t-clean-on-branch dgit/sid
432 refs/heads/dgit/sid \
433 refs/remotes/dgit/dgit/sid
434 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
438 printf "%s${1:+\n}" "$1" >$tmp/t.want
441 diff $tmp/t.want $tmp/t.got
444 t-clean-on-branch () {
445 t-output "## $1" git status -b --porcelain
453 local import=IMPORT.${0##*/}
454 exec 4>$tmp/$import.new
457 for vn in $savevars; do
458 perl >&4 -I. -MDebian::Dgit -e '
459 printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
460 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
463 (set -e; cd $tmp; tar cf $import.tar $savedirs)
465 printf >&4 "\n%s\n" "$importeval"
467 mv -f $tmp/$import.new $tmp/$import
475 if [ "x$tmpbase" = x ]; then
476 # ADTTMP was set on entry to tests/lib, so we
477 # are not sharing tmp area between tests
479 lock="$tmp/.dummy.lock"
481 setupsrc="$tmpbase/$setupname"
482 lock="$setupsrc.lock"
485 local simport="$setupsrc/IMPORT.$setupname"
487 if ! [ -e "$simport" ]; then
488 with-lock-ex -w "$lock" \
489 xargs -0 -a $tmp/.save-env \
492 setupname="$1"; shift
494 if [ -e "$simport" ]; then exit 0; fi
496 "tests/setup/$setupname"
497 ' x "$root" "$setupname" "$simport"
500 if [ "x$setupsrc" != "x$tmp" ]; then
501 (set -e; cd $tmp; tar xf "$simport.tar")
507 t-git-get-ref-exact () {
509 # does not dereference, unlike t-git-get-ref
512 *) fail "t-git-get-ref-exact bad $ref" ;;
514 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
521 *) fail "t-git-get-ref bad $ref" ;;
523 (git show-ref -d $1 || test $? = 1) | perl -ne '
524 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
525 END { print "$x\n" if length $x; }
529 t-ref-same-exact () {
531 local val=`t-git-get-ref-exact $name`
532 t-ref-same-val "$name" $val
537 local val=`t-git-get-ref $name`
538 t-ref-same-val "$name" $val
542 local val=`git rev-parse HEAD`
543 t-ref-same-val HEAD $val
549 case "${t_ref_val-unset}" in
552 *) fail "ref varies: ($name)\
553 ${val:-nothing} != ${t_ref_val:-nothing} (${t_ref_names[*]})" ;;
556 t_ref_names+=("$name")
559 t-refs-same-start () {
574 val=`t-git-get-ref $g`
575 if [ "x$val" != x ]; then
576 fail "ref $g unexpectedly exists ($val)"
582 echo refs/tags/$tagpfx/${v//\~/_}
586 git log -n1 --pretty=format:"$1" "$2"
589 t-sametree-parent () {
592 local ctree=$(t-format-ref '%T' "$ref")
595 for parent in $(t-format-ref '%P' "$ref"); do
596 local ptree=$(t-format-ref '%T' "$parent")
597 if [ "x$ptree" = "x$ctree" ]; then
601 case "$psame" in ""|" * *") break ;; esac
607 t-check-pushed-master () {
608 local master=`t-git-get-ref refs/heads/master`
609 if [ x$master = x$t_ref_val ]; then return; fi
610 if [ x$master = x ]; then fail "failed to push master"; fi
611 # didn't update master, it must be not FF
612 local mbase=`t-git-merge-base $master $t_ref_val`
613 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
618 local suite=${2:-sid}
624 t-pushed-good-core () {
628 refs/remotes/dgit/dgit/$suite
630 refs/heads/dgit/unstable \
631 refs/remotes/dgit/dgit/unstable
632 (set -e; cd $dgitrepo
636 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
640 git verify-tag `t-v-tag`
643 t-splitbrain-pushed-good--unpack () {
648 ln -s $tmp/mirror/pool/main/*.orig*.tar* .
649 ln -s $tmp/incoming/*.orig*.tar* . ||:
650 ln -s $incoming_dsc .
651 ln -s ${incoming_dsc/.dsc/.debian.tar}* .
652 dpkg-source "$@" -x *.dsc
655 git fetch ../../$p "refs/tags/*:refs/tags/*"
658 t-splitbrain-pushed-good--checkprep () {
660 git rm --cached -r --ignore-unmatch .pc
663 t-splitbrain-pushed-good--checkdiff () {
665 t-splitbrain-pushed-good--checkprep
666 t-output "" git diff --stat --cached $tag
669 t-splitbrain-pushed-good-start () {
670 dep14tag=refs/tags/test-dummy/${v//\~/_}
672 t-output "" git status --porcelain
674 t-refs-same $dep14tag
675 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
676 git merge-base --is-ancestor $dep14tag $dgittag
679 t-ref-same refs/heads/split.p
680 case "$(t-git-get-ref refs/heads/split.b)" in
682 "$(git rev-parse refs/heads/split.p^0)") ;;
683 "$(git rev-parse refs/heads/split.p^1)") ;;
690 t-splitbrain-pushed-good--unpack
691 t-splitbrain-pushed-good--checkdiff $dgittag
693 t-splitbrain-pushed-good-end-made-dep14 () {
694 t-splitbrain-pushed-good--checkdiff $dep14tag
698 t-splitbrain-rm-gitignore-patch () {
700 next unless $_ eq "auto-gitignore\n";
703 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
705 ' debian/patches/series
708 t-gbp-pushed-good () {
709 local suite=${1:-sid}
710 t-splitbrain-pushed-good-start
712 # Right, now we want to check that the maintainer tree and
713 # the dgit tree differ in exactly the ways we expect. We
714 # achieve this by trying to reconstruct the maintainer tree
715 # from the dgit tree.
717 # So, unpack it withut the patches applied
718 t-splitbrain-pushed-good--unpack --skip-patches
720 # dgit might have added a .gitignore patch, which we need to
722 t-splitbrain-rm-gitignore-patch
724 # Now the result should differ only in non-debian/ .gitignores
725 t-splitbrain-pushed-good--checkprep
726 git diff --cached --name-only $dep14tag >../changed
728 next if !m#^debian/# && m#(^|/)\.gitignore#;
732 # If we actually apply the gitignore patch by hand, it
734 if [ -f ../t-auto-gitignore ]; then
735 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
738 t-splitbrain-pushed-good-end-made-dep14
741 t-unapplied-pushed-good () {
742 t-splitbrain-pushed-good-start
743 t-splitbrain-pushed-good--unpack --skip-patches
744 t-splitbrain-pushed-good-end-made-dep14
747 t-dpm-pushed-good () {
748 t-splitbrain-pushed-good-start
749 t-splitbrain-pushed-good--unpack
750 t-splitbrain-rm-gitignore-patch
751 t-splitbrain-pushed-good-end-made-dep14
754 t-commit-build-push-expect-log () {
760 t-dgit push --new 2>&1 |tee $tmp/push.log
761 t-grep-mpat "$mpat" $tmp/push.log
768 use Dpkg::Control::Hash;
769 my $h = new Dpkg::Control::Hash allow_pgp=>1;
770 $h->parse(\*STDIN,"'"$file"'");
771 my $val = $h->{"'$field'"},"\n";
772 die "'"$file $field"'" unless defined $val;
784 "") '$var'="$tstunt" ;;
785 *) '$var'="$tstunt:$'$var'" ;;
792 local tstunt=$tmp/tstunt
793 t-stunt-envvar PATH $tstunt
794 t-stunt-envvar PERLLIB $tstunt
798 local d="$tstunt/${f%/*}"
800 ln -sf "$troot/tstunt/$f" "$d"/.
804 t-tstunt-parsechangelog () {
805 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
808 t-tstunt-lintian () {
812 t-tstunt-debuild () {
813 : ${DGIT_TEST_REAL_DEBUILD:=$(type -p debuild)}
814 export DGIT_TEST_REAL_DEBUILD
819 local dsc=${p}_${v}.dsc
820 incoming_dsc=$tmp/incoming/$dsc
825 local val=`t-822-field $incoming_dsc Dgit`
826 perl -e '$_=shift @ARGV; die "Dgit $_ ?" unless m/^\w+\b/;' "$val"
827 t-ref-same-val $incoming_dsc "$val"
834 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
838 t-gbp-unapplied-pq2qc () {
839 # does `gbp pq export'
840 # commits the resulting debian/patches on qc/BRANCH
841 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
842 # qc/BRANCH is not fast-forwarding
846 branch=`git symbolic-ref HEAD`
847 branch=${branch#refs/heads/}
850 */*) fail "unexpected branch $branch" ;;
853 git branch -f qc/$branch
854 git checkout qc/$branch
855 git add debian/patches
856 git commit -m 'Commit patch queue'
859 t-git-pseudo-merge () {
860 # like git merge -s ours
861 if [ ! "$git_pseuomerge_opts" ]; then
862 if git merge --help \
863 | grep -q allow-unrelated-histories; then
864 git_pseuomerge_opts='--allow-unrelated-histories'
866 git_pseuomerge_opts+=' -s ours'
868 git merge $git_pseuomerge_opts "$@"
871 t-gbp-example-prep-no-ff () {
872 t-tstunt-parsechangelog
873 t-archive example 1.0-1
881 git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
884 echo '/* some comment */' >>src.c
886 git commit -m 'Add a comment to an upstream file'
888 t-gbp-unapplied-pq2qc
890 t-commit 'some updates' 1.0-2
893 t-gbp-example-prep () {
894 t-gbp-example-prep-no-ff
897 -m 'Pseudo-merge to make descendant of archive' \
898 remotes/dgit/dgit/sid
901 t-make-badcommit () {
903 git cat-file commit HEAD | \
904 perl -pe 's/^committer /commiter /' | \
905 git hash-object -w -t commit --stdin
907 t-expect-fsck-fail $badcommit
912 v=${2:-${majorv:-1}.$revision}
913 dch --force-distribution -v$v --distribution ${3:-unstable} "$1"
914 git add debian/changelog
916 revision=$(( ${revision-0} + 1 ))
920 git config --global "$@"
924 export DGIT_TEST_TROOT=$troot
925 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
926 t-git-config dgit-distro.test-dummy.git-check true
927 t-git-config dgit-distro.test-dummy.git-create true
928 t-git-config dgit-distro.test-dummy.dgit-tag-format new,old,maint
929 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
930 cp $troot/suites $tmp/.
931 cp $troot/suites $tmp/suites-master
933 export t_check_pushed_master=t-check-pushed-master
935 drs_dispatch=$tmp/distro=test-dummy
938 if [ "x$DGIT_TEST_INTREE" != x ]; then
939 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
942 ln -sf $tmp/git $drs_dispatch/repos
943 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
944 mkdir -p $drs_dispatch/keyrings
945 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
946 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
947 ln -sf /bin/true $drs_dispatch/policy-hook
951 export tagpfx=archive/test-dummy
952 t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
955 export tagpfx=test-dummy
956 t-git-config dgit-distro.test-dummy.dgit-tag-format old
961 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
962 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
963 t-git-config dgit-distro.test-dummy.git-create true
964 t-git-config dgit-distro.test-dummy.git-url \
965 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
967 t-git-config dgit-distro.test-dummy.diverts.drs /drs
968 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
969 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
970 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
971 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
973 echo 'no-such-package* drs' >$drs_dispatch/diverts
977 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
980 t-policy-nonexist () {
981 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
984 t-make-hook-link () {
985 local hook=$1 # in infra/
987 hook=${DGIT_INFRA_PFX}$hook
990 *) hook=`type -P $hook` ;;
992 ln -sf "$hook" $linkpath
997 t-make-hook-link $policyhook $drs_dispatch/policy-hook
1002 t-policy dgit-repos-policy-debian
1005 t-policy-admin create-db
1008 t-policy-periodic () {
1009 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
1010 test-dummy $drs_dispatch '' --cron
1014 local restriction=$1
1015 (cd $root; t-restriction-$restriction >&2)
1019 : "Hopefully installed: $*"
1026 export DGIT_TEST_TESTNAME="$testname"
1027 export DGIT_TEST_TMPBASE="$tmpbase"
1035 t-chain-test "${t#*-}"
1040 *) t-setup-import gnupg ;;