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 export GIT_COMMITTER_DATE='1440253867 +0100'
32 export GIT_AUTHOR_DATE='1440253867 +0100'
36 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
39 if [ x"$tmp" = x ]; then
42 tmp=tests/tmp/$testname
45 elif [ "x$DGIT_TEST_TMPBASE" != x ]; then
46 tmpbase="$DGIT_TEST_TMPBASE"
54 env -0 >$tmp/.save-env
58 export DEBCHANGE_VENDOR=dpkg
60 mkdir -p $tmp/incoming
61 cat <<END >$tmp/dput.cf
64 incoming = $tmp/incoming
68 : ${t_archive_method:=aq}
69 : ${tagpfx:=archive/test-dummy}
70 : ${suitespecs:=sid:unstable}
73 GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
74 GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
78 local mpat="$1"; shift
81 LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
82 local ps="${PIPESTATUS[*]}"
86 "0 0") fail "command unexpectedly succeeded (instead of: $mpat)" ;;
88 *) fail "tee failed" ;;
91 t-grep-mpat "$mpat" $tmp/t.output
102 E:*) grepper=egrep ;;
103 F:*) grepper=fgrep ;;
104 *) fail "bad mpat prefix in $mpat";;
110 $grepper -e "$mpat" "$file" ||
111 fail "message not found"
114 t-expect-push-fail () {
115 local mpat="$1"; shift
117 local triedpush; triedpush=`git rev-parse HEAD`
120 t-expect-fail "$mpat" "$@"
122 diff $tmp/show-refs.{pre,post}-push
124 t-git-objects-not-present '' $triedpush
126 eval "$t_expect_push_fail_hook"
129 t-git-objects-not-present () {
130 # t-git-objects-not-present GITDIR|'' OBJID [...]
131 # specifying '' means the repo for package $p
132 local gitdir="${1-$dgitrepo}"
134 if ! [ -e "$gitdir" ]; then return; fi
137 t-expect-fail 'unable to find' \
143 local whichoutput=$1; shift
144 local whichrepo=${1-$dgitrepo}
145 local outputfile="$tmp/show-refs.$whichoutput"
148 if test -d $whichrepo; then
156 local edittree=$1.edit
157 if test -d "$edittree"; then
158 cp -a "$edittree"/* .
166 t-untar $troot/worktrees/${p}_$1
169 t-select-package () {
171 dgitrepo=$tmp/git/$p.git
178 local gs=$troot/git-srcs/${p}_$v.git
179 (set -e; cd $tmp/git; t-untar $gs)
184 (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
187 t-git-merge-base () {
188 git merge-base $1 $2 || test $? = 1
192 # t-has-ancestor ANCESTOR
193 # (CHILD is implicit, HEAD)
194 local now; now=`git rev-parse HEAD`
195 local ancestor; ancestor=`git rev-parse $1^{}`
196 local mbase; mbase=`t-git-merge-base $ancestor $now`
197 if [ x$mbase != x$ancestor ]; then
198 fail "not ff $ancestor..$now, $mbase != $ancestor"
202 t-has-parent-or-is () {
203 # t-has-parent-or-is CHILD PARENT
207 parents=$(git show --pretty=format:' %P %H ' "$child")
208 parent=$(git rev-parse "$parent~0")
211 *) fail "child $child lacks parent $parent" ;;
215 t-prep-newpackage () {
222 if ! git show-ref --verify --quiet refs/heads/master; then
223 git branch -m dgit/sid master
231 t-archive-none-$t_archive_method
233 t-archive-none-aq () {
234 mkdir -p $tmp/aq/dsc_in_suite $tmp/mirror/pool/main
240 for suitespec in $suitespecs; do
241 local suite=${suitespec%%:*}
242 local sname=${suitespec#*:}
244 >$tmp/aq/package.$suite.$p
245 t-aq-archive-updated $suite $p
247 >$tmp/aq/package.new.$p
248 t-aq-archive-updated new $p
250 ln -sf $suite $tmp/aq/dsc_in_suite/$sname
252 cat <<END >>$tmp/aq/suites
255 "archive" : "ftp-master",
256 "codename" : "$suite",
269 cat <<END >>$tmp/aq/suites
275 t-aq-archive-updated () {
278 local suitedir=$tmp/aq/dsc_in_suite/$suite
280 perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
284 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
292 my $json = JSON->new->canonical();
293 print $json->encode(\@v) or die $!;
298 t-archive-process-incoming () {
300 mv $tmp/incoming/${p}_* $tmp/mirror/pool/main/
301 t-archive-query "$suite"
306 local dscf=main/${p}_${v}.dsc
307 t-archive-query-$t_archive_method "$suite" "$p" "$v" "$dscf"
309 t-archive-query-aq () {
314 local sha; sha=`sha256sum <$tmp/mirror/pool/$dscf`
315 echo "${v} ${sha% -} $dscf" >>$tmp/aq/package.$suite.${p}
316 t-aq-archive-updated $suite $p
322 local dscf=${p}_$2.dsc
323 rm -f $tmp/mirror/pool/main/${p}_*
324 ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
325 t-archive-query $suite
328 (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
331 t-git-dir-time-passes () {
332 touch -d 'last year' $dgitrepo
336 local gitdir=$dgitrepo
339 if test -e "$gitdir"; then fail "$gitdir exists"; fi
342 public) wantstat='7[75]5' ;;
343 secret) wantstat='7[70]0' ;;
344 *) fail "$1 t-git-dir-check ?" ;;
346 gotstat=`stat -c%a $gitdir`
348 *$wantstat) return ;;
349 *) fail "$gitdir has mode $gotstat, expected $wantstat" ;;
353 t-expect-fsck-fail () {
354 echo >>$tmp/fsck.expected-errors "$1"
359 LC_MESSAGES=C git fsck --no-dangling --strict 2>&1 \
360 | tee dgit-test-fsck.errs
361 ps="${PIPESTATUS[*]}"
365 if [ -f $tmp/fsck.expected-errors ]; then
366 pats=(-w -f $tmp/fsck.expected-errors)
370 pats+=(-e 'notice: HEAD points to an unborn branch')
371 pats+=(-e 'notice: No default references')
374 grep -v "${pats[@]}" dgit-test-fsck.errs
378 1) ;; # no unexpected errors
379 0) fail "unexpected messages from git-fsck" ;;
380 *) fail "grep of git-fsck failed" ;;
387 for d in $tmp/*/.git $tmp/git/*.git; do
395 : '========================================'
400 t-rm-dput-dropping () {
401 rm -f $tmp/${p}_${v}_*.upload
405 local dgit=${DGIT_TEST-dgit}
408 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
409 $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
410 ${dgit_config_debian_alias-"--config-lookup-explode=dgit-distro.debian.alias-canon"} \
411 ${distro--dtest-dummy} ${distro+${distro:+-d}${distro}} \
412 $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
413 -k39B13D8A $t_dgit_xopts "$@"
414 : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
419 diff --exclude=.git --exclude=.pc -ruN $*
422 t-files-notexist () {
431 t-cloned-fetched-good () {
432 t-diff-nogit ../extract/$p-${v%-*} .
433 t-clean-on-branch dgit/sid
436 refs/heads/dgit/sid \
437 refs/remotes/dgit/dgit/sid
438 t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
442 printf "%s${1:+\n}" "$1" >$tmp/t.want
445 diff $tmp/t.want $tmp/t.got
448 t-clean-on-branch () {
449 t-output "## $1" git status -b --porcelain
457 local import=IMPORT.${0##*/}
458 exec 4>$tmp/$import.new
461 for vn in $savevars; do
462 perl >&4 -I. -MDebian::Dgit -e '
463 printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
464 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
467 (set -e; cd $tmp; tar cf $import.tar $savedirs)
469 printf >&4 "\n%s\n" "$importeval"
471 mv -f $tmp/$import.new $tmp/$import
479 if [ "x$tmpbase" = x ]; then
480 # ADTTMP was set on entry to tests/lib, so we
481 # are not sharing tmp area between tests
483 lock="$tmp/.dummy.lock"
485 setupsrc="$tmpbase/$setupname"
486 lock="$setupsrc.lock"
489 local simport="$setupsrc/IMPORT.$setupname"
491 if ! [ -e "$simport" ]; then
492 with-lock-ex -w "$lock" \
493 xargs -0 -a $tmp/.save-env \
496 setupname="$1"; shift
498 if [ -e "$simport" ]; then exit 0; fi
500 "tests/setup/$setupname"
501 ' x "$root" "$setupname" "$simport"
504 if [ "x$setupsrc" != "x$tmp" ]; then
505 (set -e; cd $tmp; tar xf "$simport.tar")
511 t-git-get-ref-exact () {
513 # does not dereference, unlike t-git-get-ref
516 *) fail "t-git-get-ref-exact bad $ref" ;;
518 git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
525 *) fail "t-git-get-ref bad $ref" ;;
527 (git show-ref -d $1 || test $? = 1) | perl -ne '
528 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
529 END { print "$x\n" if length $x; }
533 t-ref-same-exact () {
535 local val; val=`t-git-get-ref-exact $name`
536 t-ref-same-val "$name" $val
541 local val; val=`t-git-get-ref $name`
542 t-ref-same-val "$name" $val
546 local val; val=`git rev-parse HEAD`
547 t-ref-same-val HEAD $val
553 case "${t_ref_val-unset}" in
556 *) fail "ref varies: ($name)\
557 ${val:-nothing} != ${t_ref_val:-nothing} (${t_ref_names[*]})" ;;
560 t_ref_names+=("$name")
563 t-refs-same-start () {
578 val=`t-git-get-ref $g`
579 if [ "x$val" != x ]; then
580 fail "ref $g unexpectedly exists ($val)"
586 echo refs/tags/$tagpfx/${v//\~/_}
590 git log -n1 --pretty=format:"$1" "$2"
593 t-sametree-parent () {
596 local ctree; ctree=$(t-format-ref '%T' "$ref")
599 for parent in $(t-format-ref '%P' "$ref"); do
600 local ptree; ptree=$(t-format-ref '%T' "$parent")
601 if [ "x$ptree" = "x$ctree" ]; then
605 case "$psame" in ""|" * *") break ;; esac
611 t-check-pushed-master () {
612 local master; master=`t-git-get-ref refs/heads/master`
613 if [ x$master = x$t_ref_val ]; then return; fi
614 if [ x$master = x ]; then fail "failed to push master"; fi
615 # didn't update master, it must be not FF
616 local mbase; mbase=`t-git-merge-base $master $t_ref_val`
617 if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
622 local suite=${2:-sid}
628 t-pushed-good-core () {
632 refs/remotes/dgit/dgit/$suite
634 refs/heads/dgit/unstable \
635 refs/remotes/dgit/dgit/unstable
636 (set -e; cd $dgitrepo
640 ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
644 git verify-tag `t-v-tag`
647 t-splitbrain-pushed-good--unpack () {
652 ln -s $tmp/mirror/pool/main/*.orig*.tar* .
653 ln -s $tmp/incoming/*.orig*.tar* . ||:
654 ln -s $incoming_dsc .
655 ln -s ${incoming_dsc/.dsc/.debian.tar}* .
656 dpkg-source "$@" -x *.dsc
659 git fetch ../../$p "refs/tags/*:refs/tags/*"
662 t-splitbrain-pushed-good--checkprep () {
664 git rm --cached -r --ignore-unmatch .pc
667 t-splitbrain-pushed-good--checkdiff () {
669 t-splitbrain-pushed-good--checkprep
670 t-output "" git diff --stat --cached $tag
673 t-splitbrain-pushed-good-start () {
674 dep14tag=refs/tags/test-dummy/${v//\~/_}
676 t-output "" git status --porcelain
678 t-refs-same $dep14tag
679 (set -e; cd $dgitrepo; t-refs-same $dep14tag)
680 git merge-base --is-ancestor $dep14tag $dgittag
683 t-ref-same refs/heads/split.p
684 case "$(t-git-get-ref refs/heads/split.b)" in
686 "$(git rev-parse refs/heads/split.p^0)") ;;
687 "$(git rev-parse refs/heads/split.p^1)") ;;
694 t-splitbrain-pushed-good--unpack
695 t-splitbrain-pushed-good--checkdiff $dgittag
697 t-splitbrain-pushed-good-end-made-dep14 () {
698 t-splitbrain-pushed-good--checkdiff $dep14tag
702 t-splitbrain-rm-gitignore-patch () {
704 next unless $_ eq "auto-gitignore\n";
707 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
709 ' debian/patches/series
712 t-gbp-pushed-good () {
713 local suite=${1:-sid}
714 t-splitbrain-pushed-good-start
716 # Right, now we want to check that the maintainer tree and
717 # the dgit tree differ in exactly the ways we expect. We
718 # achieve this by trying to reconstruct the maintainer tree
719 # from the dgit tree.
721 # So, unpack it withut the patches applied
722 t-splitbrain-pushed-good--unpack --skip-patches
724 # dgit might have added a .gitignore patch, which we need to
726 t-splitbrain-rm-gitignore-patch
728 # Now the result should differ only in non-debian/ .gitignores
729 t-splitbrain-pushed-good--checkprep
730 git diff --cached --name-only $dep14tag >../changed
732 next if !m#^debian/# && m#(^|/)\.gitignore#;
736 # If we actually apply the gitignore patch by hand, it
738 if [ -f ../t-auto-gitignore ]; then
739 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
742 t-splitbrain-pushed-good-end-made-dep14
745 t-unapplied-pushed-good () {
746 t-splitbrain-pushed-good-start
747 t-splitbrain-pushed-good--unpack --skip-patches
748 t-splitbrain-pushed-good-end-made-dep14
751 t-dpm-pushed-good () {
752 t-splitbrain-pushed-good-start
753 t-splitbrain-pushed-good--unpack
754 t-splitbrain-rm-gitignore-patch
755 t-splitbrain-pushed-good-end-made-dep14
758 t-commit-build-push-expect-log () {
764 t-dgit push --new 2>&1 |tee $tmp/push.log
765 t-grep-mpat "$mpat" $tmp/push.log
772 use Dpkg::Control::Hash;
773 my $h = new Dpkg::Control::Hash allow_pgp=>1;
774 $h->parse(\*STDIN,"'"$file"'");
775 my $val = $h->{"'$field'"},"\n";
776 die "'"$file $field"'" unless defined $val;
788 "") '$var'="$tstunt" ;;
789 *) '$var'="$tstunt:$'$var'" ;;
795 t-tstunt--save-real () {
811 *) fail "did not find $f on PATH $PATH" ;;
814 local varname=${f//[^_0-9a-zA-Z]/_}
815 varname=DGIT_TEST_REAL_${varname^^}
818 : \${$varname:=\$real}
824 local tstunt=$tmp/tstunt
825 t-stunt-envvar PATH $tstunt
826 t-stunt-envvar PERLLIB $tstunt
829 t-tstunt--save-real $f
831 local d="$tstunt/${f%/*}"
833 ln -sf "$troot/tstunt/$f" "$d"/.
837 t-tstunt-parsechangelog () {
838 t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
841 t-tstunt-lintian () {
845 t-tstunt-debuild () {
850 local dsc=${p}_${v}.dsc
851 incoming_dsc=$tmp/incoming/$dsc
856 local val; val=`t-822-field $incoming_dsc Dgit`
859 die "Dgit $_ ?" unless m/^\w+\b/;
860 print $&,"\n" or die $!;
862 t-ref-same-val $incoming_dsc "$val"
869 debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
873 t-gbp-unapplied-pq2qc () {
874 # does `gbp pq export'
875 # commits the resulting debian/patches on qc/BRANCH
876 # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
877 # qc/BRANCH is not fast-forwarding
881 branch=`git symbolic-ref HEAD`
882 branch=${branch#refs/heads/}
885 */*) fail "unexpected branch $branch" ;;
888 git branch -f qc/$branch
889 git checkout qc/$branch
890 git add debian/patches
891 git commit -m 'Commit patch queue'
894 t-git-pseudo-merge () {
895 # like git merge -s ours
896 if [ ! "$git_pseuomerge_opts" ]; then
897 if git merge --help \
898 | grep -q allow-unrelated-histories; then
899 git_pseuomerge_opts='--allow-unrelated-histories'
901 git_pseuomerge_opts+=' -s ours'
903 git merge $git_pseuomerge_opts "$@"
906 t-gbp-example-prep-no-ff () {
907 t-tstunt-parsechangelog
908 t-archive example 1.0-1
916 git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
919 echo '/* some comment */' >>src.c
921 git commit -m 'Add a comment to an upstream file'
923 t-gbp-unapplied-pq2qc
925 t-commit 'some updates' 1.0-2
928 t-gbp-example-prep () {
929 t-gbp-example-prep-no-ff
932 -m 'Pseudo-merge to make descendant of archive' \
933 remotes/dgit/dgit/sid
936 t-make-badcommit () {
938 git cat-file commit HEAD | \
939 perl -pe 's/^committer /commiter /' | \
940 git hash-object -w -t commit --stdin
942 t-expect-fsck-fail $badcommit
947 v=${2:-${majorv:-1}.$revision}
948 dch --force-distribution -v$v --distribution ${3:-unstable} "$1"
949 git add debian/changelog
951 revision=$(( ${revision-0} + 1 ))
955 git config --global "$@"
959 export DGIT_TEST_TROOT=$troot
960 t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
961 t-git-config dgit-distro.test-dummy.git-check true
962 t-git-config dgit-distro.test-dummy.git-create true
963 t-git-config dgit-distro.test-dummy.dgit-tag-format new,old,maint
964 cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
965 cp $troot/suites $tmp/.
966 cp $troot/suites $tmp/suites-master
968 export t_check_pushed_master=t-check-pushed-master
970 drs_dispatch=$tmp/distro=test-dummy
973 if [ "x$DGIT_TEST_INTREE" != x ]; then
974 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
977 ln -sf $tmp/git $drs_dispatch/repos
978 ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
979 mkdir -p $drs_dispatch/keyrings
980 ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
981 ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
982 ln -sf /bin/true $drs_dispatch/policy-hook
986 export tagpfx=archive/test-dummy
987 t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
990 export tagpfx=test-dummy
991 t-git-config dgit-distro.test-dummy.dgit-tag-format old
996 t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
997 t-git-config dgit-distro.test-dummy.git-check ssh-cmd
998 t-git-config dgit-distro.test-dummy.git-create true
999 t-git-config dgit-distro.test-dummy.git-url \
1000 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
1002 t-git-config dgit-distro.test-dummy.diverts.drs /drs
1003 t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
1004 t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
1005 t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
1006 t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
1008 echo 'no-such-package* drs' >$drs_dispatch/diverts
1012 ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
1015 t-policy-nonexist () {
1016 ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
1019 t-make-hook-link () {
1020 local hook=$1 # in infra/
1022 hook=${DGIT_INFRA_PFX}$hook
1025 *) hook=`type -P $hook` ;;
1027 ln -sf "$hook" $linkpath
1032 t-make-hook-link $policyhook $drs_dispatch/policy-hook
1037 t-policy dgit-repos-policy-debian
1040 t-policy-admin create-db
1043 t-policy-periodic () {
1044 ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
1045 test-dummy $drs_dispatch '' --cron
1049 local restriction=$1
1050 (cd $root; t-restriction-$restriction >&2)
1054 : "Hopefully installed: $*"
1061 export DGIT_TEST_TESTNAME="$testname"
1062 export DGIT_TEST_TMPBASE="$tmpbase"
1070 t-chain-test "${t#*-}"
1075 *) t-setup-import gnupg ;;