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 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
423 diff --exclude=.git --exclude=.pc -ruN $*
426 t-files-notexist () {
435 t-cloned-fetched-good () {
436 t-diff-nogit ../extract/$p-${v%-*} .
437 t-clean-on-branch dgit/sid
440 refs/heads/dgit/sid \
441 refs/remotes/dgit/dgit/sid
442 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
446 printf "%s${1:+\n}" "$1" >$tmp/t.want
449 diff $tmp/t.want $tmp/t.got
452 t-clean-on-branch () {
453 t-output "## $1" git status -b --porcelain
461 local import=IMPORT.${0##*/}
462 exec 4>$tmp/$import.new
465 for vn in $savevars; do
466 perl >&4 -I. -MDebian::Dgit -e '
467 printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
468 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
471 (set -e; cd $tmp; tar cf $import.tar $savedirs)
473 printf >&4 "\n%s\n" "$importeval"
475 mv -f $tmp/$import.new $tmp/$import
483 if [ "x$tmpbase" = x ]; then
484 # ADTTMP was set on entry to tests/lib, so we
485 # are not sharing tmp area between tests
487 lock="$tmp/.dummy.lock"
489 setupsrc="$tmpbase/$setupname"
490 lock="$setupsrc.lock"
493 local simport="$setupsrc/IMPORT.$setupname"
495 if ! [ -e "$simport" ]; then
496 with-lock-ex -w "$lock" \
497 xargs -0 -a $tmp/.save-env \
500 setupname="$1"; shift
502 if [ -e "$simport" ]; then exit 0; fi
504 "tests/setup/$setupname"
505 ' x "$root" "$setupname" "$simport"
508 if [ "x$setupsrc" != "x$tmp" ]; then
509 (set -e; cd $tmp; tar xf "$simport.tar")
515 t-git-get-ref-exact () {
517 # does not dereference, unlike t-git-get-ref
520 *) fail "t-git-get-ref-exact bad $ref" ;;
522 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
529 *) fail "t-git-get-ref bad $ref" ;;
531 (git show-ref -d $1 || test $? = 1) | perl -ne '
532 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
533 END { print "$x\n" if length $x; }
537 t-ref-same-exact () {
539 local val; val=`t-git-get-ref-exact $name`
540 t-ref-same-val "$name" $val
545 local val; val=`t-git-get-ref $name`
546 t-ref-same-val "$name" $val
550 local val; val=`git rev-parse HEAD`
551 t-ref-same-val HEAD $val
557 case "${t_ref_val-unset}" in
560 *) fail "ref varies: ($name)\
561 ${val:-nothing} != ${t_ref_val:-nothing} (${t_ref_names[*]})" ;;
564 t_ref_names+=("$name")
567 t-refs-same-start () {
582 val=`t-git-get-ref $g`
583 if [ "x$val" != x ]; then
584 fail "ref $g unexpectedly exists ($val)"
590 echo refs/tags/$tagpfx/${v//\~/_}
594 git log -n1 --pretty=format:"$1" "$2"
597 t-sametree-parent () {
600 local ctree; ctree=$(t-format-ref '%T' "$ref")
603 for parent in $(t-format-ref '%P' "$ref"); do
604 local ptree; ptree=$(t-format-ref '%T' "$parent")
605 if [ "x$ptree" = "x$ctree" ]; then
609 case "$psame" in ""|" * *") break ;; esac
615 t-check-pushed-master () {
616 local master; master=`t-git-get-ref refs/heads/master`
617 if [ x$master = x$t_ref_val ]; then return; fi
618 if [ x$master = x ]; then fail "failed to push master"; fi
619 # didn't update master, it must be not FF
620 local mbase; mbase=`t-git-merge-base $master $t_ref_val`
621 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
626 local suite=${2:-sid}
632 t-pushed-good-core () {
636 refs/remotes/dgit/dgit/$suite
638 refs/heads/dgit/unstable \
639 refs/remotes/dgit/dgit/unstable
640 (set -e; cd $dgitrepo
644 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
648 git verify-tag `t-v-tag`
651 t-splitbrain-pushed-good--unpack () {
656 ln -s $tmp/mirror/pool/main/*.orig*.tar* .
657 ln -s $tmp/incoming/*.orig*.tar* . ||:
658 ln -s $incoming_dsc .
659 ln -s ${incoming_dsc/.dsc/.debian.tar}* .
660 dpkg-source "$@" -x *.dsc
663 git fetch ../../$p "refs/tags/*:refs/tags/*"
666 t-splitbrain-pushed-good--checkprep () {
668 git rm --cached -r --ignore-unmatch .pc
671 t-splitbrain-pushed-good--checkdiff () {
673 t-splitbrain-pushed-good--checkprep
674 t-output "" git diff --stat --cached $tag
677 t-splitbrain-pushed-good-start () {
678 dep14tag=refs/tags/test-dummy/${v//\~/_}
680 t-output "" git status --porcelain
682 t-refs-same $dep14tag
683 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
684 git merge-base --is-ancestor $dep14tag $dgittag
687 t-ref-same refs/heads/split.p
688 case "$(t-git-get-ref refs/heads/split.b)" in
690 "$(git rev-parse refs/heads/split.p^0)") ;;
691 "$(git rev-parse refs/heads/split.p^1)") ;;
698 t-splitbrain-pushed-good--unpack
699 t-splitbrain-pushed-good--checkdiff $dgittag
701 t-splitbrain-pushed-good-end-made-dep14 () {
702 t-splitbrain-pushed-good--checkdiff $dep14tag
706 t-splitbrain-rm-gitignore-patch () {
708 next unless $_ eq "auto-gitignore\n";
711 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
713 ' debian/patches/series
716 t-gbp-pushed-good () {
717 local suite=${1:-sid}
718 t-splitbrain-pushed-good-start
720 # Right, now we want to check that the maintainer tree and
721 # the dgit tree differ in exactly the ways we expect. We
722 # achieve this by trying to reconstruct the maintainer tree
723 # from the dgit tree.
725 # So, unpack it withut the patches applied
726 t-splitbrain-pushed-good--unpack --skip-patches
728 # dgit might have added a .gitignore patch, which we need to
730 t-splitbrain-rm-gitignore-patch
732 # Now the result should differ only in non-debian/ .gitignores
733 t-splitbrain-pushed-good--checkprep
734 git diff --cached --name-only $dep14tag >../changed
736 next if !m#^debian/# && m#(^|/)\.gitignore#;
740 # If we actually apply the gitignore patch by hand, it
742 if [ -f ../t-auto-gitignore ]; then
743 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
746 t-splitbrain-pushed-good-end-made-dep14
749 t-unapplied-pushed-good () {
750 t-splitbrain-pushed-good-start
751 t-splitbrain-pushed-good--unpack --skip-patches
752 t-splitbrain-pushed-good-end-made-dep14
755 t-dpm-pushed-good () {
756 t-splitbrain-pushed-good-start
757 t-splitbrain-pushed-good--unpack
758 t-splitbrain-rm-gitignore-patch
759 t-splitbrain-pushed-good-end-made-dep14
762 t-commit-build-push-expect-log () {
768 t-dgit push --new 2>&1 |tee $tmp/push.log
769 t-grep-mpat "$mpat" $tmp/push.log
776 use Dpkg::Control::Hash;
777 my $h = new Dpkg::Control::Hash allow_pgp=>1;
778 $h->parse(\*STDIN,"'"$file"'");
779 my $val = $h->{"'$field'"},"\n";
780 die "'"$file $field"'" unless defined $val;
786 export DGIT_TEST_DISTRO=''
788 t-git-config dgit-suite.unstable.distro test-dummy
798 "") '$var'="$tstunt" ;;
799 *) '$var'="$tstunt:$'$var'" ;;
805 t-tstunt--save-real () {
816 p="${p/:"$tmp/tstunt":/:}"
828 *) fail "did not find $f on PATH $PATH" ;;
831 local varname=${f//[^_0-9a-zA-Z]/_}
832 varname=DGIT_TEST_REAL_${varname^^}
835 : \${$varname:=\$real}
841 local tstunt=$tmp/tstunt
842 t-stunt-envvar PATH $tstunt
843 t-stunt-envvar PERLLIB $tstunt
846 t-tstunt--save-real $f
848 local d="$tstunt/${f%/*}"
850 ln -sf "$troot/tstunt/$f" "$d"/.
854 t-tstunt-parsechangelog () {
855 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
858 t-tstunt-lintian () {
862 t-tstunt-debuild () {
867 local dsc=${p}_${v}.dsc
868 incoming_dsc=$tmp/incoming/$dsc
873 local val; val=`t-822-field $incoming_dsc Dgit`
876 die "Dgit $_ ?" unless m/^\w+\b/;
877 print $&,"\n" or die $!;
879 t-ref-same-val $incoming_dsc "$val"
886 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
890 t-gbp-unapplied-pq2qc () {
891 # does `gbp pq export'
892 # commits the resulting debian/patches on qc/BRANCH
893 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
894 # qc/BRANCH is not fast-forwarding
898 branch=`git symbolic-ref HEAD`
899 branch=${branch#refs/heads/}
902 */*) fail "unexpected branch $branch" ;;
905 git branch -f qc/$branch
906 git checkout qc/$branch
907 git add debian/patches
908 git commit -m 'Commit patch queue'
911 t-git-pseudo-merge () {
912 # like git merge -s ours
913 if [ ! "$git_pseuomerge_opts" ]; then
914 if git merge --help \
915 | grep -q allow-unrelated-histories; then
916 git_pseuomerge_opts='--allow-unrelated-histories'
918 git_pseuomerge_opts+=' -s ours'
920 git merge $git_pseuomerge_opts "$@"
923 t-gbp-example-prep-no-ff () {
924 t-tstunt-parsechangelog
925 t-archive example 1.0-1
933 git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
936 echo '/* some comment */' >>src.c
938 git commit -m 'Add a comment to an upstream file'
940 t-gbp-unapplied-pq2qc
942 t-commit 'some updates' 1.0-2
945 t-gbp-example-prep () {
946 t-gbp-example-prep-no-ff
949 -m 'Pseudo-merge to make descendant of archive' \
950 remotes/dgit/dgit/sid
953 t-make-badcommit () {
955 git cat-file commit HEAD | \
956 perl -pe 's/^committer /commiter /' | \
957 git hash-object -w -t commit --stdin
959 t-expect-fsck-fail $badcommit
964 v=${2:-${majorv:-1}.$revision}
965 dch --force-distribution -v$v --distribution ${3:-unstable} "$1"
966 git add debian/changelog
968 revision=$(( ${revision-0} + 1 ))
972 git config --global "$@"
976 export DGIT_TEST_TROOT=$troot
977 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
978 t-git-config dgit-distro.test-dummy.git-check true
979 t-git-config dgit-distro.test-dummy.git-create true
980 t-git-config dgit-distro.test-dummy.dgit-tag-format new,old,maint
981 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
982 cp $troot/suites $tmp/.
983 cp $troot/suites $tmp/suites-master
985 export t_check_pushed_master=t-check-pushed-master
987 drs_dispatch=$tmp/distro=test-dummy
990 if [ "x$DGIT_TEST_INTREE" != x ]; then
991 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
994 ln -sf $tmp/git $drs_dispatch/repos
995 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
996 mkdir -p $drs_dispatch/keyrings
997 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
998 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
999 ln -sf /bin/true $drs_dispatch/policy-hook
1003 export tagpfx=archive/test-dummy
1004 t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
1007 export tagpfx=test-dummy
1008 t-git-config dgit-distro.test-dummy.dgit-tag-format old
1013 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
1014 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
1015 t-git-config dgit-distro.test-dummy.git-create true
1016 t-git-config dgit-distro.test-dummy.git-url \
1017 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
1019 t-git-config dgit-distro.test-dummy.diverts.drs /drs
1020 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
1021 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
1022 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
1023 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
1025 echo 'no-such-package* drs' >$drs_dispatch/diverts
1029 : '(((((((((((((((((((((((((((((((((((((((('
1030 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
1031 : '))))))))))))))))))))))))))))))))))))))))'
1034 t-policy-nonexist () {
1035 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
1038 t-make-hook-link () {
1039 local hook=$1 # in infra/
1041 hook=${DGIT_INFRA_PFX}$hook
1044 *) hook=`type -P $hook` ;;
1046 ln -sf "$hook" $linkpath
1051 t-make-hook-link $policyhook $drs_dispatch/policy-hook
1056 t-policy dgit-repos-policy-debian
1059 t-policy-admin create-db
1062 t-policy-periodic () {
1063 : '(((((((((((((((((((((((((((((((((((((((('
1064 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
1065 test-dummy $drs_dispatch '' --cron
1066 : '))))))))))))))))))))))))))))))))))))))))'
1070 local restriction=$1
1071 (cd $root; t-restriction-$restriction >&2)
1075 : "Hopefully installed: $*"
1082 export DGIT_TEST_TESTNAME="$testname"
1083 export DGIT_TEST_TMPBASE="$tmpbase"
1091 t-chain-test "${t#*-}"
1094 t-git-config dgit.default.old-dsc-distro test-dummy
1098 *) t-setup-import gnupg ;;