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 : ${DGIT_TEST_DISTRO+ ${distro=${DGIT_TEST_DISTRO}}}
33 export GIT_COMMITTER_DATE='1440253867 +0100'
34 export GIT_AUTHOR_DATE='1440253867 +0100'
38 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
41 if [ x"$tmp" = x ]; then
44 tmp=tests/tmp/$testname
47 elif [ "x$DGIT_TEST_TMPBASE" != x ]; then
48 tmpbase="$DGIT_TEST_TMPBASE"
56 test -f $tmp/.save-env || \
57 env -0 >$tmp/.save-env
61 export DEBCHANGE_VENDOR=dpkg
63 mkdir -p $tmp/incoming
64 cat <<END >$tmp/dput.cf
67 incoming = $tmp/incoming
71 : ${t_archive_method:=aq}
72 : ${tagpfx:=archive/test-dummy}
73 : ${suitespecs:=sid:unstable}
76 GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
77 GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
81 local mpat="$1"; shift
84 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
85 local ps="${PIPESTATUS[*]}"
89 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
91 *) fail "tee failed" ;;
94 t-grep-mpat "$mpat" $tmp/t.output
105 E:*) grepper=egrep ;;
106 F:*) grepper=fgrep ;;
107 *) fail "bad mpat prefix in $mpat";;
113 $grepper -e "$mpat" "$file" ||
114 fail "message not found"
117 t-expect-push-fail () {
118 local mpat="$1"; shift
120 local triedpush; triedpush=`git rev-parse HEAD`
123 t-expect-fail "$mpat" "$@"
125 diff $tmp/show-refs.{pre,post}-push
127 t-git-objects-not-present '' $triedpush
129 eval "$t_expect_push_fail_hook"
132 t-git-objects-not-present () {
133 # t-git-objects-not-present GITDIR|'' OBJID [...]
134 # specifying '' means the repo for package $p
135 local gitdir="${1-$dgitrepo}"
137 if ! [ -e "$gitdir" ]; then return; fi
140 t-expect-fail 'unable to find' \
146 local whichoutput=$1; shift
147 local whichrepo=${1-$dgitrepo}
148 local outputfile="$tmp/show-refs.$whichoutput"
151 if test -d $whichrepo; then
159 local edittree=$1.edit
160 if test -d "$edittree"; then
161 cp -a "$edittree"/* .
169 t-untar $troot/worktrees/${p}_$1
172 t-select-package () {
174 dgitrepo=$tmp/git/$p.git
181 local gs=$troot/git-srcs/${p}_$v.git
182 (set -e; cd $tmp/git; t-untar $gs)
187 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
190 t-git-merge-base () {
191 git merge-base $1 $2 || test $? = 1
195 # t-has-ancestor ANCESTOR
196 # (CHILD is implicit, HEAD)
197 local now; now=`git rev-parse HEAD`
198 local ancestor; ancestor=`git rev-parse $1^{}`
199 local mbase; mbase=`t-git-merge-base $ancestor $now`
200 if [ x$mbase != x$ancestor ]; then
201 fail "not ff $ancestor..$now, $mbase != $ancestor"
205 t-has-parent-or-is () {
206 # t-has-parent-or-is CHILD PARENT
210 parents=$(git show --pretty=format:' %P %H ' "$child")
211 parent=$(git rev-parse "$parent~0")
214 *) fail "child $child lacks parent $parent" ;;
218 t-prep-newpackage () {
225 if ! git show-ref --verify --quiet refs/heads/master; then
226 git branch -m dgit/sid master
234 t-archive-none-$t_archive_method
236 t-archive-none-aq () {
237 mkdir -p $tmp/aq/dsc_in_suite $tmp/mirror/pool/main
243 for suitespec in $suitespecs; do
244 local suite=${suitespec%%:*}
245 local sname=${suitespec#*:}
247 >$tmp/aq/package.$suite.$p
248 t-aq-archive-updated $suite $p
250 >$tmp/aq/package.new.$p
251 t-aq-archive-updated new $p
253 ln -sf $suite $tmp/aq/dsc_in_suite/$sname
255 cat <<END >>$tmp/aq/suites
258 "archive" : "ftp-master",
259 "codename" : "$suite",
272 cat <<END >>$tmp/aq/suites
278 t-aq-archive-updated () {
281 local suitedir=$tmp/aq/dsc_in_suite/$suite
283 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
287 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
295 my $json = JSON->new->canonical();
296 print $json->encode(\@v) or die $!;
301 t-archive-process-incoming () {
303 mv $tmp/incoming/${p}_* $tmp/mirror/pool/main/
304 t-archive-query "$suite"
309 local dscf=main/${p}_${v}.dsc
310 t-archive-query-$t_archive_method "$suite" "$p" "$v" "$dscf"
312 t-archive-query-aq () {
317 local sha; sha=`sha256sum <$tmp/mirror/pool/$dscf`
318 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
319 t-aq-archive-updated $suite $p
325 local dscf=${p}_$2.dsc
326 rm -f $tmp/mirror/pool/main/${p}_*
327 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
328 t-archive-query $suite
331 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
334 t-git-dir-time-passes () {
335 touch -d 'last year' $dgitrepo
339 local gitdir=$dgitrepo
342 if test -e "$gitdir"; then fail "$gitdir exists"; fi
345 public) wantstat='7[75]5' ;;
346 secret) wantstat='7[70]0' ;;
347 *) fail "$1 t-git-dir-check ?" ;;
349 gotstat=`stat -c%a $gitdir`
351 *$wantstat) return ;;
352 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
356 t-expect-fsck-fail () {
357 echo >>$tmp/fsck.expected-errors "$1"
362 LC_MESSAGES=C git fsck --no-dangling --strict 2>&1 \
363 | tee dgit-test-fsck.errs
364 ps="${PIPESTATUS[*]}"
368 if [ -f $tmp/fsck.expected-errors ]; then
369 pats=(-w -f $tmp/fsck.expected-errors)
373 pats+=(-e 'notice: HEAD points to an unborn branch')
374 pats+=(-e 'notice: No default references')
377 grep -v "${pats[@]}" dgit-test-fsck.errs
381 1) ;; # no unexpected errors
382 0) fail "unexpected messages from git-fsck" ;;
383 *) fail "grep of git-fsck failed" ;;
390 for d in $tmp/*/.git $tmp/git/*.git; do
398 : '========================================'
403 t-rm-dput-dropping () {
404 rm -f $tmp/${p}_${v}_*.upload
408 local dgit=${DGIT_TEST-dgit}
411 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
412 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
413 ${dgit_config_debian_alias-"--config-lookup-explode=dgit-distro.debian.alias-canon"} \
414 ${distro+${distro:+-d}}${distro--dtest-dummy} \
415 $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
416 -k39B13D8A $t_dgit_xopts "$@"
417 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
422 diff --exclude=.git --exclude=.pc -ruN $*
425 t-files-notexist () {
434 t-cloned-fetched-good () {
435 t-diff-nogit ../extract/$p-${v%-*} .
436 t-clean-on-branch dgit/sid
439 refs/heads/dgit/sid \
440 refs/remotes/dgit/dgit/sid
441 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
445 printf "%s${1:+\n}" "$1" >$tmp/t.want
448 diff $tmp/t.want $tmp/t.got
451 t-clean-on-branch () {
452 t-output "## $1" git status -b --porcelain
460 local import=IMPORT.${0##*/}
461 exec 4>$tmp/$import.new
464 for vn in $savevars; do
465 perl >&4 -I. -MDebian::Dgit -e '
466 printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
467 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
470 (set -e; cd $tmp; tar cf $import.tar $savedirs)
472 printf >&4 "\n%s\n" "$importeval"
474 mv -f $tmp/$import.new $tmp/$import
482 if [ "x$tmpbase" = x ]; then
483 # ADTTMP was set on entry to tests/lib, so we
484 # are not sharing tmp area between tests
486 lock="$tmp/.dummy.lock"
488 setupsrc="$tmpbase/$setupname"
489 lock="$setupsrc.lock"
492 local simport="$setupsrc/IMPORT.$setupname"
494 if ! [ -e "$simport" ]; then
495 with-lock-ex -w "$lock" \
496 xargs -0 -a $tmp/.save-env \
499 setupname="$1"; shift
501 if [ -e "$simport" ]; then exit 0; fi
503 "tests/setup/$setupname"
504 ' x "$root" "$setupname" "$simport"
507 if [ "x$setupsrc" != "x$tmp" ]; then
508 (set -e; cd $tmp; tar xf "$simport.tar")
514 t-git-get-ref-exact () {
516 # does not dereference, unlike t-git-get-ref
519 *) fail "t-git-get-ref-exact bad $ref" ;;
521 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
528 *) fail "t-git-get-ref bad $ref" ;;
530 (git show-ref -d $1 || test $? = 1) | perl -ne '
531 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
532 END { print "$x\n" if length $x; }
536 t-ref-same-exact () {
538 local val; val=`t-git-get-ref-exact $name`
539 t-ref-same-val "$name" $val
544 local val; val=`t-git-get-ref $name`
545 t-ref-same-val "$name" $val
549 local val; val=`git rev-parse HEAD`
550 t-ref-same-val HEAD $val
556 case "${t_ref_val-unset}" in
559 *) fail "ref varies: ($name)\
560 ${val:-nothing} != ${t_ref_val:-nothing} (${t_ref_names[*]})" ;;
563 t_ref_names+=("$name")
566 t-refs-same-start () {
581 val=`t-git-get-ref $g`
582 if [ "x$val" != x ]; then
583 fail "ref $g unexpectedly exists ($val)"
589 echo refs/tags/$tagpfx/${v//\~/_}
593 git log -n1 --pretty=format:"$1" "$2"
596 t-sametree-parent () {
599 local ctree; ctree=$(t-format-ref '%T' "$ref")
602 for parent in $(t-format-ref '%P' "$ref"); do
603 local ptree; ptree=$(t-format-ref '%T' "$parent")
604 if [ "x$ptree" = "x$ctree" ]; then
608 case "$psame" in ""|" * *") break ;; esac
614 t-check-pushed-master () {
615 local master; master=`t-git-get-ref refs/heads/master`
616 if [ x$master = x$t_ref_val ]; then return; fi
617 if [ x$master = x ]; then fail "failed to push master"; fi
618 # didn't update master, it must be not FF
619 local mbase; mbase=`t-git-merge-base $master $t_ref_val`
620 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
625 local suite=${2:-sid}
631 t-pushed-good-core () {
635 refs/remotes/dgit/dgit/$suite
637 refs/heads/dgit/unstable \
638 refs/remotes/dgit/dgit/unstable
639 (set -e; cd $dgitrepo
643 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
647 git verify-tag `t-v-tag`
650 t-splitbrain-pushed-good--unpack () {
655 ln -s $tmp/mirror/pool/main/*.orig*.tar* .
656 ln -s $tmp/incoming/*.orig*.tar* . ||:
657 ln -s $incoming_dsc .
658 ln -s ${incoming_dsc/.dsc/.debian.tar}* .
659 dpkg-source "$@" -x *.dsc
662 git fetch ../../$p "refs/tags/*:refs/tags/*"
665 t-splitbrain-pushed-good--checkprep () {
667 git rm --cached -r --ignore-unmatch .pc
670 t-splitbrain-pushed-good--checkdiff () {
672 t-splitbrain-pushed-good--checkprep
673 t-output "" git diff --stat --cached $tag
676 t-splitbrain-pushed-good-start () {
677 dep14tag=refs/tags/test-dummy/${v//\~/_}
679 t-output "" git status --porcelain
681 t-refs-same $dep14tag
682 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
683 git merge-base --is-ancestor $dep14tag $dgittag
686 t-ref-same refs/heads/split.p
687 case "$(t-git-get-ref refs/heads/split.b)" in
689 "$(git rev-parse refs/heads/split.p^0)") ;;
690 "$(git rev-parse refs/heads/split.p^1)") ;;
697 t-splitbrain-pushed-good--unpack
698 t-splitbrain-pushed-good--checkdiff $dgittag
700 t-splitbrain-pushed-good-end-made-dep14 () {
701 t-splitbrain-pushed-good--checkdiff $dep14tag
705 t-splitbrain-rm-gitignore-patch () {
707 next unless $_ eq "auto-gitignore\n";
710 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
712 ' debian/patches/series
715 t-gbp-pushed-good () {
716 local suite=${1:-sid}
717 t-splitbrain-pushed-good-start
719 # Right, now we want to check that the maintainer tree and
720 # the dgit tree differ in exactly the ways we expect. We
721 # achieve this by trying to reconstruct the maintainer tree
722 # from the dgit tree.
724 # So, unpack it withut the patches applied
725 t-splitbrain-pushed-good--unpack --skip-patches
727 # dgit might have added a .gitignore patch, which we need to
729 t-splitbrain-rm-gitignore-patch
731 # Now the result should differ only in non-debian/ .gitignores
732 t-splitbrain-pushed-good--checkprep
733 git diff --cached --name-only $dep14tag >../changed
735 next if !m#^debian/# && m#(^|/)\.gitignore#;
739 # If we actually apply the gitignore patch by hand, it
741 if [ -f ../t-auto-gitignore ]; then
742 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
745 t-splitbrain-pushed-good-end-made-dep14
748 t-unapplied-pushed-good () {
749 t-splitbrain-pushed-good-start
750 t-splitbrain-pushed-good--unpack --skip-patches
751 t-splitbrain-pushed-good-end-made-dep14
754 t-dpm-pushed-good () {
755 t-splitbrain-pushed-good-start
756 t-splitbrain-pushed-good--unpack
757 t-splitbrain-rm-gitignore-patch
758 t-splitbrain-pushed-good-end-made-dep14
761 t-commit-build-push-expect-log () {
767 t-dgit push --new 2>&1 |tee $tmp/push.log
768 t-grep-mpat "$mpat" $tmp/push.log
775 use Dpkg::Control::Hash;
776 my $h = new Dpkg::Control::Hash allow_pgp=>1;
777 $h->parse(\*STDIN,"'"$file"'");
778 my $val = $h->{"'$field'"},"\n";
779 die "'"$file $field"'" unless defined $val;
785 export DGIT_TEST_DISTRO=''
786 t-git-config dgit-suite.unstable.distro test-dummy
796 "") '$var'="$tstunt" ;;
797 *) '$var'="$tstunt:$'$var'" ;;
803 t-tstunt--save-real () {
814 p="${p/:"$tmp/tstunt":/:}"
826 *) fail "did not find $f on PATH $PATH" ;;
829 local varname=${f//[^_0-9a-zA-Z]/_}
830 varname=DGIT_TEST_REAL_${varname^^}
833 : \${$varname:=\$real}
839 local tstunt=$tmp/tstunt
840 t-stunt-envvar PATH $tstunt
841 t-stunt-envvar PERLLIB $tstunt
844 t-tstunt--save-real $f
846 local d="$tstunt/${f%/*}"
848 ln -sf "$troot/tstunt/$f" "$d"/.
852 t-tstunt-parsechangelog () {
853 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
856 t-tstunt-lintian () {
860 t-tstunt-debuild () {
865 local dsc=${p}_${v}.dsc
866 incoming_dsc=$tmp/incoming/$dsc
871 local val; val=`t-822-field $incoming_dsc Dgit`
874 die "Dgit $_ ?" unless m/^\w+\b/;
875 print $&,"\n" or die $!;
877 t-ref-same-val $incoming_dsc "$val"
884 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
888 t-gbp-unapplied-pq2qc () {
889 # does `gbp pq export'
890 # commits the resulting debian/patches on qc/BRANCH
891 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
892 # qc/BRANCH is not fast-forwarding
896 branch=`git symbolic-ref HEAD`
897 branch=${branch#refs/heads/}
900 */*) fail "unexpected branch $branch" ;;
903 git branch -f qc/$branch
904 git checkout qc/$branch
905 git add debian/patches
906 git commit -m 'Commit patch queue'
909 t-git-pseudo-merge () {
910 # like git merge -s ours
911 if [ ! "$git_pseuomerge_opts" ]; then
912 if git merge --help \
913 | grep -q allow-unrelated-histories; then
914 git_pseuomerge_opts='--allow-unrelated-histories'
916 git_pseuomerge_opts+=' -s ours'
918 git merge $git_pseuomerge_opts "$@"
921 t-gbp-example-prep-no-ff () {
922 t-tstunt-parsechangelog
923 t-archive example 1.0-1
931 git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
934 echo '/* some comment */' >>src.c
936 git commit -m 'Add a comment to an upstream file'
938 t-gbp-unapplied-pq2qc
940 t-commit 'some updates' 1.0-2
943 t-gbp-example-prep () {
944 t-gbp-example-prep-no-ff
947 -m 'Pseudo-merge to make descendant of archive' \
948 remotes/dgit/dgit/sid
951 t-make-badcommit () {
953 git cat-file commit HEAD | \
954 perl -pe 's/^committer /commiter /' | \
955 git hash-object -w -t commit --stdin
957 t-expect-fsck-fail $badcommit
962 v=${2:-${majorv:-1}.$revision}
963 dch --force-distribution -v$v --distribution ${3:-unstable} "$1"
964 git add debian/changelog
966 revision=$(( ${revision-0} + 1 ))
970 git config --global "$@"
974 export DGIT_TEST_TROOT=$troot
975 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
976 t-git-config dgit-distro.test-dummy.git-check true
977 t-git-config dgit-distro.test-dummy.git-create true
978 t-git-config dgit-distro.test-dummy.dgit-tag-format new,old,maint
979 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
980 cp $troot/suites $tmp/.
981 cp $troot/suites $tmp/suites-master
983 export t_check_pushed_master=t-check-pushed-master
985 drs_dispatch=$tmp/distro=test-dummy
988 if [ "x$DGIT_TEST_INTREE" != x ]; then
989 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
992 ln -sf $tmp/git $drs_dispatch/repos
993 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
994 mkdir -p $drs_dispatch/keyrings
995 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
996 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
997 ln -sf /bin/true $drs_dispatch/policy-hook
1001 export tagpfx=archive/test-dummy
1002 t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
1005 export tagpfx=test-dummy
1006 t-git-config dgit-distro.test-dummy.dgit-tag-format old
1011 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
1012 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
1013 t-git-config dgit-distro.test-dummy.git-create true
1014 t-git-config dgit-distro.test-dummy.git-url \
1015 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
1017 t-git-config dgit-distro.test-dummy.diverts.drs /drs
1018 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
1019 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
1020 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
1021 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
1023 echo 'no-such-package* drs' >$drs_dispatch/diverts
1027 : '(((((((((((((((((((((((((((((((((((((((('
1028 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
1029 : '))))))))))))))))))))))))))))))))))))))))'
1032 t-policy-nonexist () {
1033 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
1036 t-make-hook-link () {
1037 local hook=$1 # in infra/
1039 hook=${DGIT_INFRA_PFX}$hook
1042 *) hook=`type -P $hook` ;;
1044 ln -sf "$hook" $linkpath
1049 t-make-hook-link $policyhook $drs_dispatch/policy-hook
1054 t-policy dgit-repos-policy-debian
1057 t-policy-admin create-db
1060 t-policy-periodic () {
1061 : '(((((((((((((((((((((((((((((((((((((((('
1062 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
1063 test-dummy $drs_dispatch '' --cron
1064 : '))))))))))))))))))))))))))))))))))))))))'
1068 local restriction=$1
1069 (cd $root; t-restriction-$restriction >&2)
1073 : "Hopefully installed: $*"
1080 export DGIT_TEST_TESTNAME="$testname"
1081 export DGIT_TEST_TMPBASE="$tmpbase"
1089 t-chain-test "${t#*-}"
1092 t-git-config dgit.default.old-dsc-distro test-dummy
1096 *) t-setup-import gnupg ;;