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 env -0 >$tmp/.save-env
60 export DEBCHANGE_VENDOR=dpkg
62 mkdir -p $tmp/incoming
63 cat <<END >$tmp/dput.cf
66 incoming = $tmp/incoming
70 : ${t_archive_method:=aq}
71 : ${tagpfx:=archive/test-dummy}
72 : ${suitespecs:=sid:unstable}
75 GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
76 GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
80 local mpat="$1"; shift
83 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
84 local ps="${PIPESTATUS[*]}"
88 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
90 *) fail "tee failed" ;;
93 t-grep-mpat "$mpat" $tmp/t.output
104 E:*) grepper=egrep ;;
105 F:*) grepper=fgrep ;;
106 *) fail "bad mpat prefix in $mpat";;
112 $grepper -e "$mpat" "$file" ||
113 fail "message not found"
116 t-expect-push-fail () {
117 local mpat="$1"; shift
119 local triedpush; triedpush=`git rev-parse HEAD`
122 t-expect-fail "$mpat" "$@"
124 diff $tmp/show-refs.{pre,post}-push
126 t-git-objects-not-present '' $triedpush
128 eval "$t_expect_push_fail_hook"
131 t-git-objects-not-present () {
132 # t-git-objects-not-present GITDIR|'' OBJID [...]
133 # specifying '' means the repo for package $p
134 local gitdir="${1-$dgitrepo}"
136 if ! [ -e "$gitdir" ]; then return; fi
139 t-expect-fail 'unable to find' \
145 local whichoutput=$1; shift
146 local whichrepo=${1-$dgitrepo}
147 local outputfile="$tmp/show-refs.$whichoutput"
150 if test -d $whichrepo; then
158 local edittree=$1.edit
159 if test -d "$edittree"; then
160 cp -a "$edittree"/* .
168 t-untar $troot/worktrees/${p}_$1
171 t-select-package () {
173 dgitrepo=$tmp/git/$p.git
180 local gs=$troot/git-srcs/${p}_$v.git
181 (set -e; cd $tmp/git; t-untar $gs)
186 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
189 t-git-merge-base () {
190 git merge-base $1 $2 || test $? = 1
194 # t-has-ancestor ANCESTOR
195 # (CHILD is implicit, HEAD)
196 local now; now=`git rev-parse HEAD`
197 local ancestor; ancestor=`git rev-parse $1^{}`
198 local mbase; mbase=`t-git-merge-base $ancestor $now`
199 if [ x$mbase != x$ancestor ]; then
200 fail "not ff $ancestor..$now, $mbase != $ancestor"
204 t-has-parent-or-is () {
205 # t-has-parent-or-is CHILD PARENT
209 parents=$(git show --pretty=format:' %P %H ' "$child")
210 parent=$(git rev-parse "$parent~0")
213 *) fail "child $child lacks parent $parent" ;;
217 t-prep-newpackage () {
224 if ! git show-ref --verify --quiet refs/heads/master; then
225 git branch -m dgit/sid master
233 t-archive-none-$t_archive_method
235 t-archive-none-aq () {
236 mkdir -p $tmp/aq/dsc_in_suite $tmp/mirror/pool/main
242 for suitespec in $suitespecs; do
243 local suite=${suitespec%%:*}
244 local sname=${suitespec#*:}
246 >$tmp/aq/package.$suite.$p
247 t-aq-archive-updated $suite $p
249 >$tmp/aq/package.new.$p
250 t-aq-archive-updated new $p
252 ln -sf $suite $tmp/aq/dsc_in_suite/$sname
254 cat <<END >>$tmp/aq/suites
257 "archive" : "ftp-master",
258 "codename" : "$suite",
271 cat <<END >>$tmp/aq/suites
277 t-aq-archive-updated () {
280 local suitedir=$tmp/aq/dsc_in_suite/$suite
282 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
286 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
294 my $json = JSON->new->canonical();
295 print $json->encode(\@v) or die $!;
300 t-archive-process-incoming () {
302 mv $tmp/incoming/${p}_* $tmp/mirror/pool/main/
303 t-archive-query "$suite"
308 local dscf=main/${p}_${v}.dsc
309 t-archive-query-$t_archive_method "$suite" "$p" "$v" "$dscf"
311 t-archive-query-aq () {
316 local sha; sha=`sha256sum <$tmp/mirror/pool/$dscf`
317 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
318 t-aq-archive-updated $suite $p
324 local dscf=${p}_$2.dsc
325 rm -f $tmp/mirror/pool/main/${p}_*
326 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
327 t-archive-query $suite
330 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
333 t-git-dir-time-passes () {
334 touch -d 'last year' $dgitrepo
338 local gitdir=$dgitrepo
341 if test -e "$gitdir"; then fail "$gitdir exists"; fi
344 public) wantstat='7[75]5' ;;
345 secret) wantstat='7[70]0' ;;
346 *) fail "$1 t-git-dir-check ?" ;;
348 gotstat=`stat -c%a $gitdir`
350 *$wantstat) return ;;
351 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
355 t-expect-fsck-fail () {
356 echo >>$tmp/fsck.expected-errors "$1"
361 LC_MESSAGES=C git fsck --no-dangling --strict 2>&1 \
362 | tee dgit-test-fsck.errs
363 ps="${PIPESTATUS[*]}"
367 if [ -f $tmp/fsck.expected-errors ]; then
368 pats=(-w -f $tmp/fsck.expected-errors)
372 pats+=(-e 'notice: HEAD points to an unborn branch')
373 pats+=(-e 'notice: No default references')
376 grep -v "${pats[@]}" dgit-test-fsck.errs
380 1) ;; # no unexpected errors
381 0) fail "unexpected messages from git-fsck" ;;
382 *) fail "grep of git-fsck failed" ;;
389 for d in $tmp/*/.git $tmp/git/*.git; do
397 : '========================================'
402 t-rm-dput-dropping () {
403 rm -f $tmp/${p}_${v}_*.upload
407 local dgit=${DGIT_TEST-dgit}
410 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
411 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
412 ${dgit_config_debian_alias-"--config-lookup-explode=dgit-distro.debian.alias-canon"} \
413 ${distro--dtest-dummy} ${distro+${distro:+-d}${distro}} \
414 $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
415 -k39B13D8A $t_dgit_xopts "$@"
416 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
421 diff --exclude=.git --exclude=.pc -ruN $*
424 t-files-notexist () {
433 t-cloned-fetched-good () {
434 t-diff-nogit ../extract/$p-${v%-*} .
435 t-clean-on-branch dgit/sid
438 refs/heads/dgit/sid \
439 refs/remotes/dgit/dgit/sid
440 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
444 printf "%s${1:+\n}" "$1" >$tmp/t.want
447 diff $tmp/t.want $tmp/t.got
450 t-clean-on-branch () {
451 t-output "## $1" git status -b --porcelain
459 local import=IMPORT.${0##*/}
460 exec 4>$tmp/$import.new
463 for vn in $savevars; do
464 perl >&4 -I. -MDebian::Dgit -e '
465 printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
466 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
469 (set -e; cd $tmp; tar cf $import.tar $savedirs)
471 printf >&4 "\n%s\n" "$importeval"
473 mv -f $tmp/$import.new $tmp/$import
481 if [ "x$tmpbase" = x ]; then
482 # ADTTMP was set on entry to tests/lib, so we
483 # are not sharing tmp area between tests
485 lock="$tmp/.dummy.lock"
487 setupsrc="$tmpbase/$setupname"
488 lock="$setupsrc.lock"
491 local simport="$setupsrc/IMPORT.$setupname"
493 if ! [ -e "$simport" ]; then
494 with-lock-ex -w "$lock" \
495 xargs -0 -a $tmp/.save-env \
498 setupname="$1"; shift
500 if [ -e "$simport" ]; then exit 0; fi
502 "tests/setup/$setupname"
503 ' x "$root" "$setupname" "$simport"
506 if [ "x$setupsrc" != "x$tmp" ]; then
507 (set -e; cd $tmp; tar xf "$simport.tar")
513 t-git-get-ref-exact () {
515 # does not dereference, unlike t-git-get-ref
518 *) fail "t-git-get-ref-exact bad $ref" ;;
520 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
527 *) fail "t-git-get-ref bad $ref" ;;
529 (git show-ref -d $1 || test $? = 1) | perl -ne '
530 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
531 END { print "$x\n" if length $x; }
535 t-ref-same-exact () {
537 local val; val=`t-git-get-ref-exact $name`
538 t-ref-same-val "$name" $val
543 local val; val=`t-git-get-ref $name`
544 t-ref-same-val "$name" $val
548 local val; val=`git rev-parse HEAD`
549 t-ref-same-val HEAD $val
555 case "${t_ref_val-unset}" in
558 *) fail "ref varies: ($name)\
559 ${val:-nothing} != ${t_ref_val:-nothing} (${t_ref_names[*]})" ;;
562 t_ref_names+=("$name")
565 t-refs-same-start () {
580 val=`t-git-get-ref $g`
581 if [ "x$val" != x ]; then
582 fail "ref $g unexpectedly exists ($val)"
588 echo refs/tags/$tagpfx/${v//\~/_}
592 git log -n1 --pretty=format:"$1" "$2"
595 t-sametree-parent () {
598 local ctree; ctree=$(t-format-ref '%T' "$ref")
601 for parent in $(t-format-ref '%P' "$ref"); do
602 local ptree; ptree=$(t-format-ref '%T' "$parent")
603 if [ "x$ptree" = "x$ctree" ]; then
607 case "$psame" in ""|" * *") break ;; esac
613 t-check-pushed-master () {
614 local master; master=`t-git-get-ref refs/heads/master`
615 if [ x$master = x$t_ref_val ]; then return; fi
616 if [ x$master = x ]; then fail "failed to push master"; fi
617 # didn't update master, it must be not FF
618 local mbase; mbase=`t-git-merge-base $master $t_ref_val`
619 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
624 local suite=${2:-sid}
630 t-pushed-good-core () {
634 refs/remotes/dgit/dgit/$suite
636 refs/heads/dgit/unstable \
637 refs/remotes/dgit/dgit/unstable
638 (set -e; cd $dgitrepo
642 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
646 git verify-tag `t-v-tag`
649 t-splitbrain-pushed-good--unpack () {
654 ln -s $tmp/mirror/pool/main/*.orig*.tar* .
655 ln -s $tmp/incoming/*.orig*.tar* . ||:
656 ln -s $incoming_dsc .
657 ln -s ${incoming_dsc/.dsc/.debian.tar}* .
658 dpkg-source "$@" -x *.dsc
661 git fetch ../../$p "refs/tags/*:refs/tags/*"
664 t-splitbrain-pushed-good--checkprep () {
666 git rm --cached -r --ignore-unmatch .pc
669 t-splitbrain-pushed-good--checkdiff () {
671 t-splitbrain-pushed-good--checkprep
672 t-output "" git diff --stat --cached $tag
675 t-splitbrain-pushed-good-start () {
676 dep14tag=refs/tags/test-dummy/${v//\~/_}
678 t-output "" git status --porcelain
680 t-refs-same $dep14tag
681 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
682 git merge-base --is-ancestor $dep14tag $dgittag
685 t-ref-same refs/heads/split.p
686 case "$(t-git-get-ref refs/heads/split.b)" in
688 "$(git rev-parse refs/heads/split.p^0)") ;;
689 "$(git rev-parse refs/heads/split.p^1)") ;;
696 t-splitbrain-pushed-good--unpack
697 t-splitbrain-pushed-good--checkdiff $dgittag
699 t-splitbrain-pushed-good-end-made-dep14 () {
700 t-splitbrain-pushed-good--checkdiff $dep14tag
704 t-splitbrain-rm-gitignore-patch () {
706 next unless $_ eq "auto-gitignore\n";
709 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
711 ' debian/patches/series
714 t-gbp-pushed-good () {
715 local suite=${1:-sid}
716 t-splitbrain-pushed-good-start
718 # Right, now we want to check that the maintainer tree and
719 # the dgit tree differ in exactly the ways we expect. We
720 # achieve this by trying to reconstruct the maintainer tree
721 # from the dgit tree.
723 # So, unpack it withut the patches applied
724 t-splitbrain-pushed-good--unpack --skip-patches
726 # dgit might have added a .gitignore patch, which we need to
728 t-splitbrain-rm-gitignore-patch
730 # Now the result should differ only in non-debian/ .gitignores
731 t-splitbrain-pushed-good--checkprep
732 git diff --cached --name-only $dep14tag >../changed
734 next if !m#^debian/# && m#(^|/)\.gitignore#;
738 # If we actually apply the gitignore patch by hand, it
740 if [ -f ../t-auto-gitignore ]; then
741 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
744 t-splitbrain-pushed-good-end-made-dep14
747 t-unapplied-pushed-good () {
748 t-splitbrain-pushed-good-start
749 t-splitbrain-pushed-good--unpack --skip-patches
750 t-splitbrain-pushed-good-end-made-dep14
753 t-dpm-pushed-good () {
754 t-splitbrain-pushed-good-start
755 t-splitbrain-pushed-good--unpack
756 t-splitbrain-rm-gitignore-patch
757 t-splitbrain-pushed-good-end-made-dep14
760 t-commit-build-push-expect-log () {
766 t-dgit push --new 2>&1 |tee $tmp/push.log
767 t-grep-mpat "$mpat" $tmp/push.log
774 use Dpkg::Control::Hash;
775 my $h = new Dpkg::Control::Hash allow_pgp=>1;
776 $h->parse(\*STDIN,"'"$file"'");
777 my $val = $h->{"'$field'"},"\n";
778 die "'"$file $field"'" unless defined $val;
784 export DGIT_TEST_DISTRO=''
785 t-git-config dgit-suite.unstable.distro test-dummy
795 "") '$var'="$tstunt" ;;
796 *) '$var'="$tstunt:$'$var'" ;;
802 t-tstunt--save-real () {
813 p="${p/:"$tmp/tstunt":/:}"
825 *) fail "did not find $f on PATH $PATH" ;;
828 local varname=${f//[^_0-9a-zA-Z]/_}
829 varname=DGIT_TEST_REAL_${varname^^}
832 : \${$varname:=\$real}
838 local tstunt=$tmp/tstunt
839 t-stunt-envvar PATH $tstunt
840 t-stunt-envvar PERLLIB $tstunt
843 t-tstunt--save-real $f
845 local d="$tstunt/${f%/*}"
847 ln -sf "$troot/tstunt/$f" "$d"/.
851 t-tstunt-parsechangelog () {
852 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
855 t-tstunt-lintian () {
859 t-tstunt-debuild () {
864 local dsc=${p}_${v}.dsc
865 incoming_dsc=$tmp/incoming/$dsc
870 local val; val=`t-822-field $incoming_dsc Dgit`
873 die "Dgit $_ ?" unless m/^\w+\b/;
874 print $&,"\n" or die $!;
876 t-ref-same-val $incoming_dsc "$val"
883 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
887 t-gbp-unapplied-pq2qc () {
888 # does `gbp pq export'
889 # commits the resulting debian/patches on qc/BRANCH
890 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
891 # qc/BRANCH is not fast-forwarding
895 branch=`git symbolic-ref HEAD`
896 branch=${branch#refs/heads/}
899 */*) fail "unexpected branch $branch" ;;
902 git branch -f qc/$branch
903 git checkout qc/$branch
904 git add debian/patches
905 git commit -m 'Commit patch queue'
908 t-git-pseudo-merge () {
909 # like git merge -s ours
910 if [ ! "$git_pseuomerge_opts" ]; then
911 if git merge --help \
912 | grep -q allow-unrelated-histories; then
913 git_pseuomerge_opts='--allow-unrelated-histories'
915 git_pseuomerge_opts+=' -s ours'
917 git merge $git_pseuomerge_opts "$@"
920 t-gbp-example-prep-no-ff () {
921 t-tstunt-parsechangelog
922 t-archive example 1.0-1
930 git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
933 echo '/* some comment */' >>src.c
935 git commit -m 'Add a comment to an upstream file'
937 t-gbp-unapplied-pq2qc
939 t-commit 'some updates' 1.0-2
942 t-gbp-example-prep () {
943 t-gbp-example-prep-no-ff
946 -m 'Pseudo-merge to make descendant of archive' \
947 remotes/dgit/dgit/sid
950 t-make-badcommit () {
952 git cat-file commit HEAD | \
953 perl -pe 's/^committer /commiter /' | \
954 git hash-object -w -t commit --stdin
956 t-expect-fsck-fail $badcommit
961 v=${2:-${majorv:-1}.$revision}
962 dch --force-distribution -v$v --distribution ${3:-unstable} "$1"
963 git add debian/changelog
965 revision=$(( ${revision-0} + 1 ))
969 git config --global "$@"
973 export DGIT_TEST_TROOT=$troot
974 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
975 t-git-config dgit-distro.test-dummy.git-check true
976 t-git-config dgit-distro.test-dummy.git-create true
977 t-git-config dgit-distro.test-dummy.dgit-tag-format new,old,maint
978 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
979 cp $troot/suites $tmp/.
980 cp $troot/suites $tmp/suites-master
982 export t_check_pushed_master=t-check-pushed-master
984 drs_dispatch=$tmp/distro=test-dummy
987 if [ "x$DGIT_TEST_INTREE" != x ]; then
988 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
991 ln -sf $tmp/git $drs_dispatch/repos
992 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
993 mkdir -p $drs_dispatch/keyrings
994 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
995 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
996 ln -sf /bin/true $drs_dispatch/policy-hook
1000 export tagpfx=archive/test-dummy
1001 t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
1004 export tagpfx=test-dummy
1005 t-git-config dgit-distro.test-dummy.dgit-tag-format old
1010 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
1011 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
1012 t-git-config dgit-distro.test-dummy.git-create true
1013 t-git-config dgit-distro.test-dummy.git-url \
1014 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
1016 t-git-config dgit-distro.test-dummy.diverts.drs /drs
1017 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
1018 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
1019 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
1020 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
1022 echo 'no-such-package* drs' >$drs_dispatch/diverts
1026 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
1029 t-policy-nonexist () {
1030 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
1033 t-make-hook-link () {
1034 local hook=$1 # in infra/
1036 hook=${DGIT_INFRA_PFX}$hook
1039 *) hook=`type -P $hook` ;;
1041 ln -sf "$hook" $linkpath
1046 t-make-hook-link $policyhook $drs_dispatch/policy-hook
1051 t-policy dgit-repos-policy-debian
1054 t-policy-admin create-db
1057 t-policy-periodic () {
1058 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
1059 test-dummy $drs_dispatch '' --cron
1063 local restriction=$1
1064 (cd $root; t-restriction-$restriction >&2)
1068 : "Hopefully installed: $*"
1075 export DGIT_TEST_TESTNAME="$testname"
1076 export DGIT_TEST_TMPBASE="$tmpbase"
1084 t-chain-test "${t#*-}"
1089 *) t-setup-import gnupg ;;