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"
363 LC_MESSAGES=C git fsck --no-dangling --strict 2>&1 \
364 | tee dgit-test-fsck.errs
365 ps="${PIPESTATUS[*]}"
369 if [ -f $tmp/fsck.expected-errors ]; then
370 pats=(-w -f $tmp/fsck.expected-errors)
374 pats+=(-e 'notice: HEAD points to an unborn branch')
375 pats+=(-e 'notice: No default references')
378 grep -v "${pats[@]}" dgit-test-fsck.errs
382 1) ;; # no unexpected errors
383 0) fail "unexpected messages from git-fsck" ;;
384 *) fail "grep of git-fsck failed" ;;
391 for d in $tmp/*/.git $tmp/git/*.git; do
399 : '========================================'
404 t-rm-dput-dropping () {
405 rm -f $tmp/${p}_${v}_*.upload
409 local dgit=${DGIT_TEST-dgit}
412 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
413 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
414 ${dgit_config_debian_alias-"--config-lookup-explode=dgit-distro.debian.alias-canon"} \
415 ${distro+${distro:+-d}}${distro--dtest-dummy} \
416 $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
417 -k39B13D8A $t_dgit_xopts "$@"
418 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
425 (export LC_ALL=C.UTF-8
426 if [ "$DGIT_TEST_INTREE" ]; then
427 make -C $DGIT_TEST_INTREE $page.$section.view
434 diff --exclude=.git --exclude=.pc -ruN $*
437 t-files-notexist () {
446 t-cloned-fetched-good () {
447 t-diff-nogit ../extract/$p-${v%-*} .
448 t-clean-on-branch dgit/sid
451 refs/heads/dgit/sid \
452 refs/remotes/dgit/dgit/sid
453 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
457 printf "%s${1:+\n}" "$1" >$tmp/t.want
460 diff $tmp/t.want $tmp/t.got
463 t-clean-on-branch () {
464 t-output "## $1" git status -b --porcelain
472 local import=IMPORT.${0##*/}
473 exec 4>$tmp/$import.new
476 for vn in $savevars; do
477 perl >&4 -I. -MDebian::Dgit -e '
478 printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
479 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
482 (set -e; cd $tmp; tar cf $import.tar $savedirs)
484 printf >&4 "\n%s\n" "$importeval"
486 mv -f $tmp/$import.new $tmp/$import
494 if [ "x$tmpbase" = x ]; then
495 # ADTTMP was set on entry to tests/lib, so we
496 # are not sharing tmp area between tests
498 lock="$tmp/.dummy.lock"
500 setupsrc="$tmpbase/$setupname"
501 lock="$setupsrc.lock"
504 local simport="$setupsrc/IMPORT.$setupname"
506 if ! [ -e "$simport" ]; then
507 with-lock-ex -w "$lock" \
508 xargs -0 -a $tmp/.save-env \
511 setupname="$1"; shift
513 if [ -e "$simport" ]; then exit 0; fi
515 "tests/setup/$setupname"
516 ' x "$root" "$setupname" "$simport"
519 if [ "x$setupsrc" != "x$tmp" ]; then
520 (set -e; cd $tmp; tar xf "$simport.tar")
526 t-git-get-ref-exact () {
528 # does not dereference, unlike t-git-get-ref
531 *) fail "t-git-get-ref-exact bad $ref" ;;
533 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
540 *) fail "t-git-get-ref bad $ref" ;;
542 (git show-ref -d $1 || test $? = 1) | perl -ne '
543 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
544 END { print "$x\n" if length $x; }
548 t-ref-same-exact () {
550 local val; val=`t-git-get-ref-exact $name`
551 t-ref-same-val "$name" $val
556 local val; val=`t-git-get-ref $name`
557 t-ref-same-val "$name" $val
561 local val; val=`git rev-parse HEAD`
562 t-ref-same-val HEAD $val
568 case "${t_ref_val-unset}" in
571 *) fail "ref varies: ($name)\
572 ${val:-nothing} != ${t_ref_val:-nothing} (${t_ref_names[*]})" ;;
575 t_ref_names+=("$name")
578 t-refs-same-start () {
593 val=`t-git-get-ref $g`
594 if [ "x$val" != x ]; then
595 fail "ref $g unexpectedly exists ($val)"
601 echo refs/tags/$tagpfx/${v//\~/_}
605 git log -n1 --pretty=format:"$1" "$2"
608 t-sametree-parent () {
611 local ctree; ctree=$(t-format-ref '%T' "$ref")
614 for parent in $(t-format-ref '%P' "$ref"); do
615 local ptree; ptree=$(t-format-ref '%T' "$parent")
616 if [ "x$ptree" = "x$ctree" ]; then
620 case "$psame" in ""|" * *") break ;; esac
626 t-check-pushed-master () {
627 local master; master=`t-git-get-ref refs/heads/master`
628 if [ x$master = x$t_ref_val ]; then return; fi
629 if [ x$master = x ]; then fail "failed to push master"; fi
630 # didn't update master, it must be not FF
631 local mbase; mbase=`t-git-merge-base $master $t_ref_val`
632 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
637 local suite=${2:-sid}
643 t-pushed-good-core () {
647 refs/remotes/dgit/dgit/$suite
649 refs/heads/dgit/unstable \
650 refs/remotes/dgit/dgit/unstable
651 (set -e; cd $dgitrepo
655 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
659 git verify-tag `t-v-tag`
662 t-splitbrain-pushed-good--unpack () {
667 ln -s $tmp/mirror/pool/main/*.orig*.tar* .
668 ln -s $tmp/incoming/*.orig*.tar* . ||:
669 ln -s $incoming_dsc .
670 ln -s ${incoming_dsc/.dsc/.debian.tar}* .
671 dpkg-source "$@" -x *.dsc
674 git fetch ../../$p "refs/tags/*:refs/tags/*"
677 t-splitbrain-pushed-good--checkprep () {
679 git rm --cached -r --ignore-unmatch .pc
682 t-splitbrain-pushed-good--checkdiff () {
684 t-splitbrain-pushed-good--checkprep
685 t-output "" git diff --stat --cached $tag
688 t-splitbrain-pushed-good-start () {
689 dep14tag=refs/tags/test-dummy/${v//\~/_}
691 t-output "" git status --porcelain
693 t-refs-same $dep14tag
694 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
695 git merge-base --is-ancestor $dep14tag $dgittag
698 t-ref-same refs/heads/split.p
699 case "$(t-git-get-ref refs/heads/split.b)" in
701 "$(git rev-parse refs/heads/split.p^0)") ;;
702 "$(git rev-parse refs/heads/split.p^1)") ;;
709 t-splitbrain-pushed-good--unpack
710 t-splitbrain-pushed-good--checkdiff $dgittag
712 t-splitbrain-pushed-good-end-made-dep14 () {
713 t-splitbrain-pushed-good--checkdiff $dep14tag
717 t-splitbrain-rm-gitignore-patch () {
719 next unless $_ eq "auto-gitignore\n";
722 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
724 ' debian/patches/series
727 t-gbp-pushed-good () {
728 local suite=${1:-sid}
729 t-splitbrain-pushed-good-start
731 # Right, now we want to check that the maintainer tree and
732 # the dgit tree differ in exactly the ways we expect. We
733 # achieve this by trying to reconstruct the maintainer tree
734 # from the dgit tree.
736 # So, unpack it withut the patches applied
737 t-splitbrain-pushed-good--unpack --skip-patches
739 # dgit might have added a .gitignore patch, which we need to
741 t-splitbrain-rm-gitignore-patch
743 # Now the result should differ only in non-debian/ .gitignores
744 t-splitbrain-pushed-good--checkprep
745 git diff --cached --name-only $dep14tag >../changed
747 next if !m#^debian/# && m#(^|/)\.gitignore#;
751 # If we actually apply the gitignore patch by hand, it
753 if [ -f ../t-auto-gitignore ]; then
754 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
757 t-splitbrain-pushed-good-end-made-dep14
760 t-unapplied-pushed-good () {
761 t-splitbrain-pushed-good-start
762 t-splitbrain-pushed-good--unpack --skip-patches
763 t-splitbrain-pushed-good-end-made-dep14
766 t-dpm-pushed-good () {
767 t-splitbrain-pushed-good-start
768 t-splitbrain-pushed-good--unpack
769 t-splitbrain-rm-gitignore-patch
770 t-splitbrain-pushed-good-end-made-dep14
773 t-commit-build-push-expect-log () {
779 t-dgit push --new 2>&1 |tee $tmp/push.log
780 t-grep-mpat "$mpat" $tmp/push.log
787 use Dpkg::Control::Hash;
788 my $h = new Dpkg::Control::Hash allow_pgp=>1;
789 $h->parse(\*STDIN,"'"$file"'");
790 my $val = $h->{"'$field'"},"\n";
791 die "'"$file $field"'" unless defined $val;
797 export DGIT_TEST_DISTRO=''
799 t-git-config dgit-suite.unstable.distro test-dummy
809 "") '$var'="$tstunt" ;;
810 *) '$var'="$tstunt:$'$var'" ;;
816 t-tstunt--save-real () {
827 p="${p/:"$tmp/tstunt":/:}"
839 *) fail "did not find $f on PATH $PATH" ;;
842 local varname=${f//[^_0-9a-zA-Z]/_}
843 varname=DGIT_TEST_REAL_${varname^^}
846 : \${$varname:=\$real}
852 local tstunt=$tmp/tstunt
853 t-stunt-envvar PATH $tstunt
854 t-stunt-envvar PERLLIB $tstunt
857 t-tstunt--save-real $f
859 local d="$tstunt/${f%/*}"
861 ln -sf "$troot/tstunt/$f" "$d"/.
865 t-tstunt-parsechangelog () {
866 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
869 t-tstunt-lintian () {
873 t-tstunt-debuild () {
878 local dsc=${p}_${v}.dsc
879 incoming_dsc=$tmp/incoming/$dsc
884 local val; val=`t-822-field $incoming_dsc Dgit`
887 die "Dgit $_ ?" unless m/^\w+\b/;
888 print $&,"\n" or die $!;
890 t-ref-same-val $incoming_dsc "$val"
897 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
901 t-gbp-unapplied-pq2qc () {
902 # does `gbp pq export'
903 # commits the resulting debian/patches on qc/BRANCH
904 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
905 # qc/BRANCH is not fast-forwarding
909 branch=`git symbolic-ref HEAD`
910 branch=${branch#refs/heads/}
913 */*) fail "unexpected branch $branch" ;;
916 git branch -f qc/$branch
917 git checkout qc/$branch
918 git add debian/patches
919 git commit -m 'Commit patch queue'
922 t-git-pseudo-merge () {
923 # like git merge -s ours
924 if [ ! "$git_pseuomerge_opts" ]; then
925 if git merge --help \
926 | grep -q allow-unrelated-histories; then
927 git_pseuomerge_opts='--allow-unrelated-histories'
929 git_pseuomerge_opts+=' -s ours'
931 git merge $git_pseuomerge_opts "$@"
934 t-gbp-example-prep-no-ff () {
935 t-tstunt-parsechangelog
936 t-archive example 1.0-1
944 git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
947 echo '/* some comment */' >>src.c
949 git commit -m 'Add a comment to an upstream file'
951 t-gbp-unapplied-pq2qc
953 t-commit 'some updates' 1.0-2
956 t-gbp-example-prep () {
957 t-gbp-example-prep-no-ff
960 -m 'Pseudo-merge to make descendant of archive' \
961 remotes/dgit/dgit/sid
964 t-make-badcommit () {
966 git cat-file commit HEAD | \
967 perl -pe 's/^committer /commiter /' | \
968 git hash-object -w -t commit --stdin
970 t-expect-fsck-fail $badcommit
975 v=${2:-${majorv:-1}.$revision}
976 dch --force-distribution -v$v --distribution ${3:-unstable} "$1"
977 git add debian/changelog
979 revision=$(( ${revision-0} + 1 ))
983 git config --global "$@"
987 export DGIT_TEST_TROOT=$troot
988 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
989 t-git-config dgit-distro.test-dummy.git-check true
990 t-git-config dgit-distro.test-dummy.git-create true
991 t-git-config dgit-distro.test-dummy.dgit-tag-format new,old,maint
992 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
993 cp $troot/suites $tmp/.
994 cp $troot/suites $tmp/suites-master
996 export t_check_pushed_master=t-check-pushed-master
998 drs_dispatch=$tmp/distro=test-dummy
1001 if [ "x$DGIT_TEST_INTREE" != x ]; then
1002 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
1005 ln -sf $tmp/git $drs_dispatch/repos
1006 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
1007 mkdir -p $drs_dispatch/keyrings
1008 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
1009 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
1010 ln -sf /bin/true $drs_dispatch/policy-hook
1014 export tagpfx=archive/test-dummy
1015 t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
1018 export tagpfx=test-dummy
1019 t-git-config dgit-distro.test-dummy.dgit-tag-format old
1024 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
1025 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
1026 t-git-config dgit-distro.test-dummy.git-create true
1027 t-git-config dgit-distro.test-dummy.git-url \
1028 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
1030 t-git-config dgit-distro.test-dummy.diverts.drs /drs
1031 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
1032 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
1033 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
1034 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
1036 echo 'no-such-package* drs' >$drs_dispatch/diverts
1040 : '(((((((((((((((((((((((((((((((((((((((('
1041 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
1042 : '))))))))))))))))))))))))))))))))))))))))'
1045 t-policy-nonexist () {
1046 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
1049 t-make-hook-link () {
1050 local hook=$1 # in infra/
1052 hook=${DGIT_INFRA_PFX}$hook
1055 *) hook=`type -P $hook` ;;
1057 ln -sf "$hook" $linkpath
1062 t-make-hook-link $policyhook $drs_dispatch/policy-hook
1067 t-policy dgit-repos-policy-debian
1070 t-policy-admin create-db
1073 t-policy-periodic () {
1074 : '(((((((((((((((((((((((((((((((((((((((('
1075 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
1076 test-dummy $drs_dispatch '' --cron
1077 : '))))))))))))))))))))))))))))))))))))))))'
1081 local restriction=$1
1082 (cd $root; t-restriction-$restriction >&2)
1086 : "Hopefully installed: $*"
1093 export DGIT_TEST_TESTNAME="$testname"
1094 export DGIT_TEST_TMPBASE="$tmpbase"
1102 t-chain-test "${t#*-}"
1105 t-git-config dgit.default.old-dsc-distro test-dummy
1109 *) t-setup-import gnupg ;;