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='1440253867 +0100'
35 export GIT_AUTHOR_DATE='1440253867 +0100'
39 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
42 if [ x"$tmp" = x ]; then
45 tmp=tests/tmp/$testname
48 elif [ "x$DGIT_TEST_TMPBASE" != x ]; then
49 tmpbase="$DGIT_TEST_TMPBASE"
57 test -f $tmp/.save-env || \
58 env -0 >$tmp/.save-env
62 export DEBCHANGE_VENDOR=dpkg
64 mkdir -p $tmp/incoming
65 cat <<END >$tmp/dput.cf
68 incoming = $tmp/incoming
72 : ${t_archive_method:=aq}
73 : ${tagpfx:=archive/test-dummy}
74 : ${suitespecs:=sid:unstable}
77 GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
78 GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
82 local mpat="$1"; shift
85 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
86 local ps="${PIPESTATUS[*]}"
90 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
92 *) fail "tee failed" ;;
95 t-grep-mpat "$mpat" $tmp/t.output
106 E:*) grepper=egrep ;;
107 F:*) grepper=fgrep ;;
108 *) fail "bad mpat prefix in $mpat";;
114 $grepper -e "$mpat" "$file" ||
115 fail "message not found"
118 t-expect-push-fail () {
119 local mpat="$1"; shift
121 local triedpush; triedpush=`git rev-parse HEAD`
124 t-expect-fail "$mpat" "$@"
126 diff $tmp/show-refs.{pre,post}-push
128 t-git-objects-not-present '' $triedpush
130 eval "$t_expect_push_fail_hook"
133 t-git-objects-not-present () {
134 # t-git-objects-not-present GITDIR|'' OBJID [...]
135 # specifying '' means the repo for package $p
136 local gitdir="${1-$dgitrepo}"
138 if ! [ -e "$gitdir" ]; then return; fi
141 t-expect-fail 'unable to find' \
147 local whichoutput=$1; shift
148 local whichrepo=${1-$dgitrepo}
149 local outputfile="$tmp/show-refs.$whichoutput"
152 if test -d $whichrepo; then
160 local edittree=$1.edit
161 if test -d "$edittree"; then
162 cp -a "$edittree"/* .
170 t-untar $troot/worktrees/${p}_$1
173 t-select-package () {
175 dgitrepo=$tmp/git/$p.git
182 local gs=$troot/git-srcs/${p}_$v.git
183 (set -e; cd $tmp/git; t-untar $gs)
188 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
191 t-git-merge-base () {
192 git merge-base $1 $2 || test $? = 1
196 # t-has-ancestor ANCESTOR
197 # (CHILD is implicit, HEAD)
198 local now; now=`git rev-parse HEAD`
199 local ancestor; ancestor=`git rev-parse $1^{}`
200 local mbase; mbase=`t-git-merge-base $ancestor $now`
201 if [ x$mbase != x$ancestor ]; then
202 fail "not ff $ancestor..$now, $mbase != $ancestor"
206 t-has-parent-or-is () {
207 # t-has-parent-or-is CHILD PARENT
211 parents=$(git show --pretty=format:' %P %H ' "$child")
212 parent=$(git rev-parse "$parent~0")
215 *) fail "child $child lacks parent $parent" ;;
219 t-prep-newpackage () {
226 if ! git show-ref --verify --quiet refs/heads/master; then
227 git branch -m dgit/sid master
235 t-archive-none-$t_archive_method
237 t-archive-none-aq () {
238 mkdir -p $tmp/aq/dsc_in_suite $tmp/mirror/pool/main
244 for suitespec in $suitespecs; do
245 local suite=${suitespec%%:*}
246 local sname=${suitespec#*:}
248 >$tmp/aq/package.$suite.$p
249 t-aq-archive-updated $suite $p
251 >$tmp/aq/package.new.$p
252 t-aq-archive-updated new $p
254 ln -sf $suite $tmp/aq/dsc_in_suite/$sname
256 cat <<END >>$tmp/aq/suites
259 "archive" : "ftp-master",
260 "codename" : "$suite",
273 cat <<END >>$tmp/aq/suites
279 t-aq-archive-updated () {
282 local suitedir=$tmp/aq/dsc_in_suite/$suite
284 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
288 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
296 my $json = JSON->new->canonical();
297 print $json->encode(\@v) or die $!;
302 t-archive-process-incoming () {
304 mv $tmp/incoming/${p}_* $tmp/mirror/pool/main/
305 t-archive-query "$suite"
310 local dscf=main/${p}_${v}.dsc
311 t-archive-query-$t_archive_method "$suite" "$p" "$v" "$dscf"
313 t-archive-query-aq () {
318 local sha; sha=`sha256sum <$tmp/mirror/pool/$dscf`
319 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
320 t-aq-archive-updated $suite $p
326 local dscf=${p}_$2.dsc
327 rm -f $tmp/mirror/pool/main/${p}_*
328 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
329 t-archive-query $suite
332 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
335 t-git-dir-time-passes () {
336 touch -d 'last year' $dgitrepo
340 local gitdir=$dgitrepo
343 if test -e "$gitdir"; then fail "$gitdir exists"; fi
346 public) wantstat='7[75]5' ;;
347 secret) wantstat='7[70]0' ;;
348 *) fail "$1 t-git-dir-check ?" ;;
350 gotstat=`stat -c%a $gitdir`
352 *$wantstat) return ;;
353 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
357 t-expect-fsck-fail () {
358 echo >>$tmp/fsck.expected-errors "$1"
362 local fsckerrs=dgit-test-fsck.errs
365 LC_MESSAGES=C git fsck --no-dangling --strict 2>&1 \
367 ps="${PIPESTATUS[*]}"
371 if [ -f $tmp/fsck.expected-errors ]; then
372 pats=(-w -f $tmp/fsck.expected-errors)
376 pats+=(-e 'notice: HEAD points to an unborn branch')
377 pats+=(-e 'notice: No default references')
380 grep -v "${pats[@]}" $fsckerrs
384 1) ;; # no unexpected errors
385 0) fail "unexpected messages from git-fsck" ;;
386 *) fail "grep of git-fsck failed" ;;
393 for d in $tmp/*/.git $tmp/git/*.git; do
401 : '========================================'
406 t-rm-dput-dropping () {
407 rm -f $tmp/${p}_${v}_*.upload
411 local dgit=${DGIT_TEST-dgit}
414 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
415 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
416 ${dgit_config_debian_alias-"--config-lookup-explode=dgit-distro.debian.alias-canon"} \
417 ${distro+${distro:+-d}}${distro--dtest-dummy} \
418 $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
419 -k39B13D8A $t_dgit_xopts "$@"
420 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
425 diff --exclude=.git --exclude=.pc -ruN $*
428 t-files-notexist () {
437 t-cloned-fetched-good () {
438 t-diff-nogit ../extract/$p-${v%-*} .
439 t-clean-on-branch dgit/sid
442 refs/heads/dgit/sid \
443 refs/remotes/dgit/dgit/sid
444 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
448 printf "%s${1:+\n}" "$1" >$tmp/t.want
451 diff $tmp/t.want $tmp/t.got
454 t-clean-on-branch () {
455 t-output "## $1" git status -b --porcelain
463 local import=IMPORT.${0##*/}
464 exec 4>$tmp/$import.new
467 for vn in $savevars; do
468 perl >&4 -I. -MDebian::Dgit -e '
469 printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
470 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
473 (set -e; cd $tmp; tar cf $import.tar $savedirs)
475 printf >&4 "\n%s\n" "$importeval"
477 mv -f $tmp/$import.new $tmp/$import
485 if [ "x$tmpbase" = x ]; then
486 # ADTTMP was set on entry to tests/lib, so we
487 # are not sharing tmp area between tests
489 lock="$tmp/.dummy.lock"
491 setupsrc="$tmpbase/$setupname"
492 lock="$setupsrc.lock"
495 local simport="$setupsrc/IMPORT.$setupname"
497 if ! [ -e "$simport" ]; then
498 with-lock-ex -w "$lock" \
499 xargs -0 -a $tmp/.save-env \
502 setupname="$1"; shift
504 if [ -e "$simport" ]; then exit 0; fi
506 "tests/setup/$setupname"
507 ' x "$root" "$setupname" "$simport"
510 if [ "x$setupsrc" != "x$tmp" ]; then
511 (set -e; cd $tmp; tar xf "$simport.tar")
517 t-git-get-ref-exact () {
519 # does not dereference, unlike t-git-get-ref
522 *) fail "t-git-get-ref-exact bad $ref" ;;
524 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
531 *) fail "t-git-get-ref bad $ref" ;;
533 (git show-ref -d $1 || test $? = 1) | perl -ne '
534 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
535 END { print "$x\n" if length $x; }
539 t-ref-same-exact () {
541 local val; val=`t-git-get-ref-exact $name`
542 t-ref-same-val "$name" $val
547 local val; val=`t-git-get-ref $name`
548 t-ref-same-val "$name" $val
552 local val; val=`git rev-parse HEAD`
553 t-ref-same-val HEAD $val
559 case "${t_ref_val-unset}" in
562 *) fail "ref varies: ($name)\
563 ${val:-nothing} != ${t_ref_val:-nothing} (${t_ref_names[*]})" ;;
566 t_ref_names+=("$name")
569 t-refs-same-start () {
584 val=`t-git-get-ref $g`
585 if [ "x$val" != x ]; then
586 fail "ref $g unexpectedly exists ($val)"
592 echo refs/tags/$tagpfx/${v//\~/_}
596 git log -n1 --pretty=format:"$1" "$2"
599 t-sametree-parent () {
602 local ctree; ctree=$(t-format-ref '%T' "$ref")
605 for parent in $(t-format-ref '%P' "$ref"); do
606 local ptree; ptree=$(t-format-ref '%T' "$parent")
607 if [ "x$ptree" = "x$ctree" ]; then
611 case "$psame" in ""|" * *") break ;; esac
617 t-check-pushed-master () {
618 local master; master=`t-git-get-ref refs/heads/master`
619 if [ x$master = x$t_ref_val ]; then return; fi
620 if [ x$master = x ]; then fail "failed to push master"; fi
621 # didn't update master, it must be not FF
622 local mbase; mbase=`t-git-merge-base $master $t_ref_val`
623 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
628 local suite=${2:-sid}
634 t-pushed-good-core () {
638 refs/remotes/dgit/dgit/$suite
640 refs/heads/dgit/unstable \
641 refs/remotes/dgit/dgit/unstable
642 (set -e; cd $dgitrepo
646 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
650 git verify-tag `t-v-tag`
653 t-splitbrain-pushed-good--unpack () {
658 ln -s $tmp/mirror/pool/main/*.orig*.tar* .
659 ln -s $tmp/incoming/*.orig*.tar* . ||:
660 ln -s $incoming_dsc .
661 ln -s ${incoming_dsc/.dsc/.debian.tar}* .
662 dpkg-source "$@" -x *.dsc
665 git fetch ../../$p "refs/tags/*:refs/tags/*"
668 t-splitbrain-pushed-good--checkprep () {
670 git rm --cached -r --ignore-unmatch .pc
673 t-splitbrain-pushed-good--checkdiff () {
675 t-splitbrain-pushed-good--checkprep
676 t-output "" git diff --stat --cached $tag
679 t-splitbrain-pushed-good-start () {
680 dep14tag=refs/tags/test-dummy/${v//\~/_}
682 t-output "" git status --porcelain
684 t-refs-same $dep14tag
685 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
686 git merge-base --is-ancestor $dep14tag $dgittag
689 t-ref-same refs/heads/split.p
690 case "$(t-git-get-ref refs/heads/split.b)" in
692 "$(git rev-parse refs/heads/split.p^0)") ;;
693 "$(git rev-parse refs/heads/split.p^1)") ;;
700 t-splitbrain-pushed-good--unpack
701 t-splitbrain-pushed-good--checkdiff $dgittag
703 t-splitbrain-pushed-good-end-made-dep14 () {
704 t-splitbrain-pushed-good--checkdiff $dep14tag
708 t-splitbrain-rm-gitignore-patch () {
710 next unless $_ eq "auto-gitignore\n";
713 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
715 ' debian/patches/series
718 t-gbp-pushed-good () {
719 local suite=${1:-sid}
720 t-splitbrain-pushed-good-start
722 # Right, now we want to check that the maintainer tree and
723 # the dgit tree differ in exactly the ways we expect. We
724 # achieve this by trying to reconstruct the maintainer tree
725 # from the dgit tree.
727 # So, unpack it withut the patches applied
728 t-splitbrain-pushed-good--unpack --skip-patches
730 # dgit might have added a .gitignore patch, which we need to
732 t-splitbrain-rm-gitignore-patch
734 # Now the result should differ only in non-debian/ .gitignores
735 t-splitbrain-pushed-good--checkprep
736 git diff --cached --name-only $dep14tag >../changed
738 next if !m#^debian/# && m#(^|/)\.gitignore#;
742 # If we actually apply the gitignore patch by hand, it
744 if [ -f ../t-auto-gitignore ]; then
745 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
748 t-splitbrain-pushed-good-end-made-dep14
751 t-unapplied-pushed-good () {
752 t-splitbrain-pushed-good-start
753 t-splitbrain-pushed-good--unpack --skip-patches
754 t-splitbrain-pushed-good-end-made-dep14
757 t-dpm-pushed-good () {
758 t-splitbrain-pushed-good-start
759 t-splitbrain-pushed-good--unpack
760 t-splitbrain-rm-gitignore-patch
761 t-splitbrain-pushed-good-end-made-dep14
764 t-commit-build-push-expect-log () {
770 t-dgit push --new 2>&1 |tee $tmp/push.log
771 t-grep-mpat "$mpat" $tmp/push.log
778 use Dpkg::Control::Hash;
779 my $h = new Dpkg::Control::Hash allow_pgp=>1;
780 $h->parse(\*STDIN,"'"$file"'");
781 my $val = $h->{"'$field'"},"\n";
782 die "'"$file $field"'" unless defined $val;
788 export DGIT_TEST_DISTRO=''
790 t-git-config dgit-suite.unstable.distro test-dummy
800 "") '$var'="$tstunt" ;;
801 *) '$var'="$tstunt:$'$var'" ;;
807 t-tstunt--save-real () {
818 p="${p/:"$tmp/tstunt":/:}"
830 *) fail "did not find $f on PATH $PATH" ;;
833 local varname=${f//[^_0-9a-zA-Z]/_}
834 varname=DGIT_TEST_REAL_${varname^^}
837 : \${$varname:=\$real}
843 local tstunt=$tmp/tstunt
844 t-stunt-envvar PATH $tstunt
845 t-stunt-envvar PERLLIB $tstunt
848 t-tstunt--save-real $f
850 local d="$tstunt/${f%/*}"
852 ln -sf "$troot/tstunt/$f" "$d"/.
856 t-tstunt-parsechangelog () {
857 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
860 t-tstunt-lintian () {
864 t-tstunt-debuild () {
869 local dsc=${p}_${v}.dsc
870 incoming_dsc=$tmp/incoming/$dsc
875 local val; val=`t-822-field $incoming_dsc Dgit`
878 die "Dgit $_ ?" unless m/^\w+\b/;
879 print $&,"\n" or die $!;
881 t-ref-same-val $incoming_dsc "$val"
888 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
892 t-gbp-unapplied-pq2qc () {
893 # does `gbp pq export'
894 # commits the resulting debian/patches on qc/BRANCH
895 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
896 # qc/BRANCH is not fast-forwarding
900 branch=`git symbolic-ref HEAD`
901 branch=${branch#refs/heads/}
904 */*) fail "unexpected branch $branch" ;;
907 git branch -f qc/$branch
908 git checkout qc/$branch
909 git add debian/patches
910 git commit -m 'Commit patch queue'
913 t-git-pseudo-merge () {
914 # like git merge -s ours
915 if [ ! "$git_pseuomerge_opts" ]; then
916 if git merge --help \
917 | grep -q allow-unrelated-histories; then
918 git_pseuomerge_opts='--allow-unrelated-histories'
920 git_pseuomerge_opts+=' -s ours'
922 git merge $git_pseuomerge_opts "$@"
925 t-gbp-example-prep-no-ff () {
926 t-tstunt-parsechangelog
927 t-archive example 1.0-1
935 git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
938 echo '/* some comment */' >>src.c
940 git commit -m 'Add a comment to an upstream file'
942 t-gbp-unapplied-pq2qc
944 t-commit 'some updates' 1.0-2
947 t-gbp-example-prep () {
948 t-gbp-example-prep-no-ff
951 -m 'Pseudo-merge to make descendant of archive' \
952 remotes/dgit/dgit/sid
955 t-make-badcommit () {
957 git cat-file commit HEAD | \
958 perl -pe 's/^committer /commiter /' | \
959 git hash-object -w -t commit --stdin
961 t-expect-fsck-fail $badcommit
966 v=${2:-${majorv:-1}.$revision}
967 dch --force-distribution -v$v --distribution ${3:-unstable} "$1"
968 git add debian/changelog
970 revision=$(( ${revision-0} + 1 ))
974 git config --global "$@"
978 export DGIT_TEST_TROOT=$troot
979 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
980 t-git-config dgit-distro.test-dummy.git-check true
981 t-git-config dgit-distro.test-dummy.git-create true
982 t-git-config dgit-distro.test-dummy.dgit-tag-format new,old,maint
983 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
984 cp $troot/suites $tmp/.
985 cp $troot/suites $tmp/suites-master
987 export t_check_pushed_master=t-check-pushed-master
989 drs_dispatch=$tmp/distro=test-dummy
992 if [ "x$DGIT_TEST_INTREE" != x ]; then
993 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
996 ln -sf $tmp/git $drs_dispatch/repos
997 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
998 mkdir -p $drs_dispatch/keyrings
999 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
1000 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
1001 ln -sf /bin/true $drs_dispatch/policy-hook
1005 export tagpfx=archive/test-dummy
1006 t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
1009 export tagpfx=test-dummy
1010 t-git-config dgit-distro.test-dummy.dgit-tag-format old
1015 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
1016 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
1017 t-git-config dgit-distro.test-dummy.git-create true
1018 t-git-config dgit-distro.test-dummy.git-url \
1019 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
1021 t-git-config dgit-distro.test-dummy.diverts.drs /drs
1022 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
1023 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
1024 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
1025 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
1027 echo 'no-such-package* drs' >$drs_dispatch/diverts
1031 : '(((((((((((((((((((((((((((((((((((((((('
1032 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
1033 : '))))))))))))))))))))))))))))))))))))))))'
1036 t-policy-nonexist () {
1037 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
1040 t-make-hook-link () {
1041 local hook=$1 # in infra/
1043 hook=${DGIT_INFRA_PFX}$hook
1046 *) hook=`type -P $hook` ;;
1048 ln -sf "$hook" $linkpath
1053 t-make-hook-link $policyhook $drs_dispatch/policy-hook
1058 t-policy dgit-repos-policy-debian
1061 t-policy-admin create-db
1064 t-policy-periodic () {
1065 : '(((((((((((((((((((((((((((((((((((((((('
1066 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
1067 test-dummy $drs_dispatch '' --cron
1068 : '))))))))))))))))))))))))))))))))))))))))'
1072 local restriction=$1
1073 (cd $root; t-restriction-$restriction >&2)
1077 : "Hopefully installed: $*"
1084 export DGIT_TEST_TESTNAME="$testname"
1085 export DGIT_TEST_TMPBASE="$tmpbase"
1093 t-chain-test "${t#*-}"
1096 t-git-config dgit.default.old-dsc-distro test-dummy
1100 *) t-setup-import gnupg ;;