chiark / gitweb /
test suite: git-debrebase: Use gdr-convert-gbp-noarchive
[dgit.git] / tests / lib
1 #
2
3 exec 2>&1
4 set -x
5 set -o pipefail
6
7 . tests/lib-core
8 . tests/lib-restricts
9
10 t-report-failure () {
11         set +x
12         rc=$1
13         cat <<END >&2
14 TEST FAILED
15 cwd: $PWD
16 funcs: ${FUNCNAME[*]}
17 lines: ${BASH_LINENO[*]}
18 files: ${BASH_SOURCE[*]}
19 END
20         exit 16
21 }
22
23 trap 'test $? = 0 || t-report-failure' EXIT
24
25 t-filter-out-git-hyphen-dir
26
27 t-set-intree
28
29 : ${DGIT_TEST_DEBUG=-D}
30 export DGIT_TEST_DEBUG
31
32 : ${DGIT_TEST_DISTRO+ ${distro=${DGIT_TEST_DISTRO}}}
33
34 export GIT_COMMITTER_DATE='1515000000 +0100'
35 export GIT_AUTHOR_DATE='1515000000 +0100'
36
37 root=`pwd`
38 troot=$root/tests
39 testname="${DGIT_TEST_TESTNAME-${0##*/}}"
40 export DGIT_TEST_TROOT=$troot
41
42 tmp=$ADTTMP
43 if [ x"$tmp" = x ]; then
44         mkdir -p tests/tmp
45         tmpbase=$troot/tmp
46         tmp=tests/tmp/$testname
47         rm -rf $tmp
48         mkdir $tmp
49 elif [ "x$DGIT_TEST_TMPBASE" != x ]; then
50         tmpbase="$DGIT_TEST_TMPBASE"
51 fi
52 cd $tmp
53
54 tmp=`pwd`
55
56 t-set-using-tmp
57
58 test -f $tmp/.save-env || \
59 env -0 >$tmp/.save-env
60
61 ln -f $troot/ssh ssh
62
63 export DEBCHANGE_VENDOR=dpkg
64
65 mkdir -p $tmp/incoming
66 cat <<END >$tmp/dput.cf
67 [test-dummy]
68 method                  = local
69 incoming                = $tmp/incoming
70 run_dinstall            = 0
71 END
72
73 : ${t_archive_method:=aq}
74 : ${tagpfx:=archive/test-dummy}
75 : ${suitespecs:=sid:unstable}
76
77 t-git-next-date () {
78         GIT_COMMITTER_DATE="$(( ${GIT_COMMITTER_DATE%% *} + 1 )) ${GIT_COMMITTER_DATE#* }"
79         GIT_AUTHOR_DATE="$GIT_COMMITTER_DATE"
80 }
81
82 t-expect-fail () {
83         local mpat="$1"; shift
84
85         set +o pipefail
86         LC_MESSAGES=C "$@" 2>&1 | tee $tmp/t.output
87         local ps="${PIPESTATUS[*]}"
88         set -o pipefail
89
90         case $ps in
91         "0 0")  fail "command unexpectedly succeeded (instead of: $mpat)" ;;
92         *" 0")  ;;
93         *)      fail "tee failed"  ;;
94         esac
95
96         t-grep-mpat "$mpat" $tmp/t.output
97 }
98
99 t-grep-mpat () {
100         local mpat="$1"
101         local file="$2"
102
103         local grepper=fgrep
104         case "$mpat" in
105         [A-Z]:*)
106                 case "$mpat" in
107                 E:*)    grepper=egrep   ;;
108                 F:*)    grepper=fgrep   ;;
109                 *)      fail "bad mpat prefix in $mpat";;
110                 esac
111                 mpat=${mpat#[A-Z]:}
112                 ;;
113         esac
114
115         $grepper -e "$mpat" "$file" ||
116                 fail "message not found"
117 }
118
119 t-expect-push-fail () {
120         local mpat="$1"; shift
121
122         local triedpush; triedpush=`git rev-parse HEAD`
123
124         t-reporefs pre-push
125         t-expect-fail "$mpat"  "$@"
126         t-reporefs post-push
127         diff $tmp/show-refs.{pre,post}-push
128
129         t-git-objects-not-present '' $triedpush
130
131         eval "$t_expect_push_fail_hook"
132 }
133
134 t-git-objects-not-present () {
135         # t-git-objects-not-present GITDIR|'' OBJID [...]
136         # specifying '' means the repo for package $p
137         local gitdir="${1-$dgitrepo}"
138         local obj
139         if ! [ -e "$gitdir" ]; then return; fi
140         for obj in "$@"; do
141                 GIT_DIR=$gitdir \
142                 t-expect-fail 'unable to find' \
143                 git cat-file -t $obj
144         done
145 }
146
147 t-reporefs () {
148         local whichoutput=$1; shift
149         local whichrepo=${1-$dgitrepo}
150         local outputfile="$tmp/show-refs.$whichoutput"
151         (set -e
152          exec >"$outputfile"
153          if test -d $whichrepo; then
154                 cd $whichrepo
155                 git show-ref |sort
156         fi)
157 }
158
159 t-untar () {
160         local tarfile=$1.tar
161         local edittree=$1.edit
162         if test -d "$edittree"; then
163                 cp -a "$edittree"/* .
164         else
165                 tar xf "$tarfile"
166         fi
167 }
168
169 t-worktree () {
170         rm -rf $p
171         t-untar $troot/worktrees/${p}_$1
172 }
173
174 t-select-package () {
175         p=$1
176         dgitrepo=$tmp/git/$p.git
177 }
178
179 t-git () {
180         t-select-package $1
181         v=$2
182         mkdir -p $tmp/git
183         local gs=$troot/git-srcs/${p}_$v.git
184         (set -e; cd $tmp/git; t-untar $gs)
185 }
186
187 t-git-none () {
188         mkdir -p $tmp/git
189         (set -e; cd $tmp/git; tar xf $troot/git-template.tar)
190 }
191
192 t-salsa-add-remote () {
193         local d=$tmp/salsa/$p
194         mkdir -p $d
195         (set -e; cd $d; git init --bare)
196         git remote add ${1-origin} $d
197 }
198
199 t-git-merge-base () {
200         git merge-base $1 $2 || test $? = 1
201 }
202
203 t-has-ancestor () {
204         # t-has-ancestor ANCESTOR
205         # (CHILD is implicit, HEAD)
206         local now;      now=`git rev-parse HEAD`
207         local ancestor; ancestor=`git rev-parse $1^{}`
208         local mbase;    mbase=`t-git-merge-base $ancestor $now`
209         if [ x$mbase != x$ancestor ]; then
210                 fail "not ff $ancestor..$now, $mbase != $ancestor"
211         fi
212 }
213
214 t-has-parent-or-is () {
215         # t-has-parent-or-is CHILD PARENT
216         local child=$1
217         local parent=$2
218         local parents
219         parents=$(git show --pretty=format:' %P %H ' "$child")
220         parent=$(git rev-parse "$parent~0")
221         case "$parents" in
222         *" $parent "*)  ;;
223         *)      fail "child $child lacks parent $parent" ;;
224         esac
225 }
226
227 t-prep-newpackage () {
228         t-select-package $1
229         v=$2
230         t-archive-none $p
231         t-git-none
232         t-worktree $v
233         cd $p
234         if ! git show-ref --verify --quiet refs/heads/master; then
235                 git branch -m dgit/sid master
236                 git remote rm dgit
237         fi
238         cd ..
239 }
240
241 t-archive-none () {
242         t-select-package $1
243         t-archive-none-$t_archive_method
244 }
245 t-archive-none-aq () {
246         mkdir -p $tmp/aq/dsc_in_suite $tmp/mirror/pool/main
247
248         : >$tmp/aq/suites
249         local jsondelim="["
250
251         local suitespec
252         for suitespec in $suitespecs; do
253                 local suite=${suitespec%%:*}
254                 local sname=${suitespec#*:}
255
256                 >$tmp/aq/package.$suite.$p
257                 t-aq-archive-updated $suite $p
258
259                 >$tmp/aq/package.new.$p
260                 t-aq-archive-updated new $p
261
262                 ln -sf $suite $tmp/aq/dsc_in_suite/$sname
263
264                 cat <<END >>$tmp/aq/suites
265 $jsondelim
266    {
267       "archive" : "ftp-master",
268       "codename" : "$suite",
269       "components" : [
270          "main",
271          "contrib",
272          "non-free"
273       ],
274       "name" : "$sname",
275       "dakname" : "$sname"
276 END
277
278                 jsondelim="   },"
279
280         done
281         cat <<END >>$tmp/aq/suites
282     }
283 ]
284 END
285 }
286
287 t-aq-archive-updated () {
288         local suite=$1
289         local p=$2
290         local suitedir=$tmp/aq/dsc_in_suite/$suite
291         mkdir -p $suitedir
292         perl <$tmp/aq/package.$suite.$p >$suitedir/$p -wne '
293                 use JSON;
294                 use strict;
295                 our @v;
296                 m{^(\S+) (\w+) ([^ \t/]+)/(\S+)} or die;
297                 push @v, {
298                         "version" => "$1",
299                         "sha256sum" => "$2",
300                         "component" => "$3",
301                         "filename" => "$4",
302                 };
303                 END {
304                         my $json = JSON->new->canonical();
305                         print $json->encode(\@v) or die $!;
306                 }
307         '
308 }
309
310 t-archive-process-incoming () {
311         local suite=$1
312         mv $tmp/incoming/${p}_* $tmp/mirror/pool/main/
313         t-archive-query "$suite"
314 }
315
316 t-archive-query () {
317         local suite=${1-sid}
318         local dscf=main/${p}_${v}.dsc
319         t-archive-query-$t_archive_method "$suite" "$p" "$v" "$dscf"
320 }
321 t-archive-query-aq () {
322         local suite=$1
323         local p=$2
324         local v=$3
325         local dscf=$4
326         local sha; sha=`sha256sum <$tmp/mirror/pool/$dscf`
327         echo "${v} ${sha%  -} $dscf" >>$tmp/aq/package.$suite.${p}
328         t-aq-archive-updated $suite $p
329 }
330
331 t-archive () {
332         t-archive-none $1
333         v=$2
334         local dscf=${p}_$2.dsc
335         rm -f $tmp/mirror/pool/main/${p}_*
336         ln $troot/pkg-srcs/${p}_${2%-*}* $tmp/mirror/pool/main/
337         t-archive-query $suite
338         rm -rf $tmp/extract
339         mkdir $tmp/extract
340         (set -e; cd $tmp/extract; dpkg-source -x ../mirror/pool/main/$dscf)
341 }
342
343 t-git-dir-time-passes () {
344         touch -d 'last year' $dgitrepo
345 }
346
347 t-git-dir-check () {
348         local gitdir=$dgitrepo
349         case "$1" in
350         enoent)
351                 if test -e "$gitdir"; then fail "$gitdir exists"; fi
352                 return
353                 ;;
354         public) wantstat='7[75]5' ;;
355         secret) wantstat='7[70]0' ;;
356         *)      fail "$1 t-git-dir-check ?" ;;
357         esac
358         gotstat=`stat -c%a $gitdir`
359         case "$gotstat" in
360         *$wantstat) return ;;
361         *)      fail "$gitdir has mode $gotstat, expected $wantstat" ;;
362         esac
363 }
364
365 t-expect-fsck-fail () {
366         echo >>$tmp/fsck.expected-errors "$1"
367 }
368
369 t-git-fsck () {
370         local fsckerrs=$(git rev-parse --git-dir)/dgit-test-fsck.errs
371
372         set +e
373         LC_MESSAGES=C git fsck --no-dangling --strict 2>&1 \
374                 | tee $fsckerrs
375         ps="${PIPESTATUS[*]}"
376         set -e
377
378         local pats
379         if [ -f $tmp/fsck.expected-errors ]; then
380                 pats=(-w -f $tmp/fsck.expected-errors)
381         else
382                 test "$ps" = "0 0"
383         fi
384         pats+=(-e 'notice: HEAD points to an unborn branch')
385         pats+=(-e 'notice: No default references')
386
387         set +e
388         grep -v "${pats[@]}" $fsckerrs
389         rc=$?
390         set -e
391         case $rc in
392         1) ;; # no unexpected errors
393         0) fail "unexpected messages from git-fsck" ;;
394         *) fail "grep of git-fsck failed" ;;
395         esac
396 }
397
398 t-fscks () {
399         (
400         shopt -s nullglob
401         for d in $tmp/*/.git $tmp/git/*.git; do
402                 cd "${d%/.git}"
403                 t-git-fsck
404         done
405         )
406 }
407
408 t-ok () {
409         : '========================================'
410         t-fscks
411         echo ok.
412 }
413
414 t-rm-dput-dropping () {
415         rm -f $tmp/${p}_${v}_*.upload
416 }
417
418 t-dgit () {
419         local dgit=${DGIT_TEST-dgit}
420         pwd >&2
421         : '
422 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
423         $dgit --dgit=$dgit --dget:-u --dput:--config=$tmp/dput.cf \
424  ${dgit_config_debian_alias-"--config-lookup-explode=dgit-distro.debian.alias-canon"} \
425  ${DGIT_GITDEBREBASE_TEST+--git-debrebase=}${DGIT_GITDEBREBASE_TEST} \
426                 ${distro+${distro:+-d}}${distro--dtest-dummy} \
427                 $DGIT_TEST_OPTS $DGIT_TEST_DEBUG \
428                 -kBCD22CD83243B79D3DFAC33EA3DBCBC039B13D8A $t_dgit_xopts "$@"
429         : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
430 '
431 }
432
433 t-dgit-manpage () {
434         local section=$1
435         local page=$2
436         (export LC_ALL=C.UTF-8
437          if [ "$DGIT_TEST_INTREE" ]; then
438                 make -C $DGIT_TEST_INTREE $page.$section.view
439          else
440                 man $section $page
441          fi)
442 }
443
444 t-diff-nogit () {
445         diff --exclude=.git --exclude=.pc -ruN $*
446 }
447
448 t-files-notexist () {
449         local f
450         for f in "$@"; do
451                 if [ -e $f ]; then
452                         fail "$f exists!"
453                 fi
454         done
455 }
456
457 t-cloned-fetched-good () {
458         t-diff-nogit ../extract/$p-${v%-*} .
459         t-clean-on-branch dgit/sid
460         t-refs-same-start
461         t-refs-same \
462                 refs/heads/dgit/sid \
463                 refs/remotes/dgit/dgit/sid
464         t-refs-notexist refs/dgit/unstable refs/remotes/dgit/dgit/unstable
465 }
466
467 t-output () {
468         printf "%s${1:+\n}" "$1" >$tmp/t.want
469         shift
470         "$@" >$tmp/t.got
471         diff $tmp/t.want $tmp/t.got
472 }
473
474 t-clean-on-branch () {
475         t-output "## $1" git status -b --porcelain
476 }
477
478 t-setup-done () {
479         local savevars=$1
480         local savedirs=$2
481         local importeval=$3
482
483         local import=IMPORT.${DGIT_TEST_TESTNAME-${0##*/}}
484         exec 4>$tmp/$import.new
485
486         local vn
487         for vn in $savevars; do
488                 perl >&4 -"I$root" -MDebian::Dgit -e '
489                         printf "%s=%s\n", $ARGV[0], shellquote $ARGV[1]
490                 ' $vn "$(eval "printf '%s\n' \"\$$vn\"")"
491         done
492
493         (set -e; cd $tmp; tar cf $import.tar $savedirs)
494
495         printf >&4 "\n%s\n" "$importeval"
496
497         mv -f $tmp/$import.new $tmp/$import
498 }
499
500 t-setup-import () {
501         local setupname=$1
502
503         local setupsrc
504         local lock
505         if [ "x$tmpbase" = x ]; then
506                 # ADTTMP was set on entry to tests/lib, so we
507                 # are not sharing tmp area between tests
508                 setupsrc="$tmp"
509                 lock="$tmp/.dummy.lock"
510         else
511                 setupsrc="$tmpbase/$setupname"
512                 lock="$setupsrc.lock"
513         fi
514
515         local simport="$setupsrc/IMPORT.$setupname"
516
517         if ! [ -e "$simport" ]; then
518                 with-lock-ex -w "$lock" \
519                 xargs -0 -a $tmp/.save-env \
520                 bash -xec '
521                         cd "$1"; shift
522                         setupname="$1"; shift
523                         simport="$1"; shift
524                         if [ -e "$simport" ]; then exit 0; fi
525                         env - "$@" \
526                         "tests/setup/$setupname"
527                 ' x "$root" "$setupname" "$simport"
528         fi
529
530         if [ "x$setupsrc" != "x$tmp" ]; then
531                 (set -e; cd $tmp; tar xf "$simport.tar")
532         fi
533
534         . "$simport"
535 }
536
537 t-git-get-ref-exact () {
538         local ref=$1
539         # does not dereference, unlike t-git-get-ref
540         case "$ref" in
541         refs/*) ;;
542         *) fail "t-git-get-ref-exact bad $ref" ;;
543         esac
544         git for-each-ref --format='%(objectname)' "[r]efs/${ref#refs/}"
545 }
546
547 t-git-get-ref () {
548         local ref=$1
549         case "$ref" in
550         refs/*) ;;
551         *) fail "t-git-get-ref bad $ref" ;;
552         esac
553         (git show-ref -d $1 || test $? = 1) | perl -ne '
554                 $x = $1 if m#^(\w+) \Q'$1'\E(?:\^\{\})?$#;
555                 END { print "$x\n" if length $x; }
556         '
557 }
558
559 t-ref-same-exact () {
560         local name="$1"
561         local val; val=`t-git-get-ref-exact $name`
562         t-ref-same-val "$name" $val
563 }
564
565 t-ref-same () {
566         local name="$1"
567         local val; val=`t-git-get-ref $name`
568         t-ref-same-val "$name" $val
569 }
570
571 t-ref-head () {
572         local val; val=`git rev-parse HEAD`
573         t-ref-same-val HEAD $val
574 }
575
576 t-ref-same-val () {
577         local name="$1"
578         local val=$2
579         case "${t_ref_val-unset}" in
580         unset)          ;;
581         "$val")         ;;
582         *)              fail "ref varies: ($name)\
583  ${val:-nothing} != ${t_ref_val:-nothing} (${t_ref_names[*]})" ;;
584         esac
585         t_ref_val="$val"
586         t_ref_names+=("$name")
587 }
588
589 t-refs-same-start () {
590         unset t_ref_val
591         t_ref_names=()
592 }
593
594 t-refs-same () {
595         local g
596         for g in $*; do
597                 t-ref-same $g
598         done
599 }
600
601 t-refs-notexist () {
602         local val
603         for g in $*; do
604                 val=`t-git-get-ref $g`
605                 if [ "x$val" != x ]; then
606                         fail "ref $g unexpectedly exists ($val)"
607                 fi
608         done
609 }
610
611 t-v-tag () {
612         echo refs/tags/$tagpfx/${v//\~/_}
613 }
614
615 t-format-ref () {
616         git log -n1 --pretty=format:"$1" "$2"
617 }
618
619 t-sametree-parent () {
620         local ref=$1
621         local parent
622         local ctree; ctree=$(t-format-ref '%T' "$ref")
623         while :; do
624                 local psame=''
625                 for parent in $(t-format-ref '%P' "$ref"); do
626                         local ptree; ptree=$(t-format-ref '%T' "$parent")
627                         if [ "x$ptree" = "x$ctree" ]; then
628                                 psame+=" $parent"
629                         fi
630                 done
631                 case "$psame" in ""|" * *") break ;; esac
632                 ref="${psame# }"
633         done
634         echo "$ref"
635 }
636
637 t-check-pushed-master () {
638         local master; master=`t-git-get-ref refs/heads/master`
639         if [ x$master = x$t_ref_val ]; then return; fi
640         if [ x$master = x ]; then fail "failed to push master"; fi
641         # didn't update master, it must be not FF
642         local mbase; mbase=`t-git-merge-base $master $t_ref_val`
643         if [ x$mbase = x$master ]; then fail "failed to ff master"; fi
644 }
645
646 t-push-was-source-only () {
647         local f
648         t-files-notexist $tmp/incoming/${p}_${v}_*.deb \
649                          $tmp/incoming/${p}_${v}_*.udeb
650         # we permit _source.buildinfo files; see test_changes_source_only()
651         for f in $tmp/incoming/${p}_${v}_*.buildinfo; do
652             if [ -e $f ]; then
653                 case "$f" in
654                     *_source.buildinfo) ;;
655                     *) fail "non-source-only file $f exists!" ;;
656                 esac
657             fi
658         done
659 }
660
661 t-pushed-good () {
662         local branch=$1
663         local suite=${2:-sid}
664         t-refs-same \
665                 refs/heads/$branch
666         t-pushed-good-core
667 }
668         
669 t-pushed-good-core () {
670         t-ref-dsc-dgit
671         t-refs-same \
672                 `t-v-tag` \
673                 refs/remotes/dgit/dgit/$suite
674         t-refs-notexist \
675                 refs/heads/dgit/unstable \
676                 refs/remotes/dgit/dgit/unstable
677         (set -e; cd $dgitrepo
678          t-refs-same \
679                 refs/dgit/$suite \
680                 `t-v-tag`
681          ${t_check_pushed_master:- : NOT-DRS-NO-CHECK-PUSHED-MASTER}
682          t-refs-notexist \
683                 refs/dgit/unstable
684         )
685         git verify-tag `t-v-tag`
686 }
687
688 t-splitbrain-pushed-good--unpack () {
689         cd $tmp
690         rm -rf t-unpack
691         mkdir t-unpack
692         cd t-unpack
693         ln -s $tmp/mirror/pool/main/*.orig*.tar* .
694         ln -s $tmp/incoming/*.orig*.tar* . ||:
695         ln -s $incoming_dsc .
696         ln -s ${incoming_dsc/.dsc/.debian.tar}* .
697         dpkg-source "$@" -x *.dsc
698         cd */.
699         git init
700         git fetch ../../$p "refs/tags/*:refs/tags/*"
701 }
702
703 t-splitbrain-pushed-good--checkprep () {
704         git add -Af .
705         git rm --cached -r --ignore-unmatch .pc
706 }
707
708 t-splitbrain-pushed-good--checkdiff () {
709         local tag=$1
710         t-splitbrain-pushed-good--checkprep
711         t-output "" git diff --stat --cached $tag
712 }
713
714 t-splitbrain-pushed-good-start () {
715         dep14tag=refs/tags/test-dummy/${v//\~/_}
716         dgittag=$(t-v-tag)
717         t-output "" git status --porcelain
718         t-ref-head
719         t-refs-same $dep14tag
720         (set -e; cd $dgitrepo; t-refs-same $dep14tag)
721         git merge-base --is-ancestor $dep14tag $dgittag
722
723         t-refs-same-start
724         t-ref-same refs/heads/split.p
725         case "$(t-git-get-ref refs/heads/split.b)" in
726         "$t_ref_val") ;;
727         "$(git rev-parse refs/heads/split.p^0)") ;;
728         "$(git rev-parse refs/heads/split.p^1)") ;;
729         *) fail 'bad b/p' ;;
730         esac
731         t-pushed-good-core
732
733         t-incoming-dsc
734
735         t-splitbrain-pushed-good--unpack
736         t-splitbrain-pushed-good--checkdiff $dgittag
737 }
738 t-splitbrain-pushed-good-end-made-dep14 () {
739         t-splitbrain-pushed-good--checkdiff $dep14tag
740         cd $tmp/$p
741 }
742
743 t-splitbrain-rm-gitignore-patch () {
744         perl -i -pe '
745                 next unless $_ eq "auto-gitignore\n";
746                 die if $counter++;
747                 chomp;
748                 rename "debian/patches/$_", "../t-auto-gitignore" or die $!;
749                 $_ = "";
750         ' debian/patches/series
751 }
752
753 t-gbp-pushed-good () {
754         local suite=${1:-sid}
755         t-splitbrain-pushed-good-start
756
757         # Right, now we want to check that the maintainer tree and
758         # the dgit tree differ in exactly the ways we expect.  We
759         # achieve this by trying to reconstruct the maintainer tree
760         # from the dgit tree.
761
762         # So, unpack it withut the patches applied
763         t-splitbrain-pushed-good--unpack --skip-patches
764
765         # dgit might have added a .gitignore patch, which we need to
766         # drop and remove
767         t-splitbrain-rm-gitignore-patch
768
769         # Now the result should differ only in non-debian/ .gitignores
770         t-splitbrain-pushed-good--checkprep
771         git diff --cached --name-only $dep14tag >../changed
772         perl -ne '
773                 next if !m#^debian/# && m#(^|/)\.gitignore#;
774                 die "$_ mismatch";
775         ' <../changed
776
777         # If we actually apply the gitignore patch by hand, it
778         # should be perfect:
779         if [ -f ../t-auto-gitignore ]; then
780                 patch --backup-if-mismatch -p1 -u <../t-auto-gitignore
781         fi
782
783         t-splitbrain-pushed-good-end-made-dep14
784 }
785
786 t-unapplied-pushed-good () {
787         t-splitbrain-pushed-good-start
788         t-splitbrain-pushed-good--unpack --skip-patches
789         t-splitbrain-pushed-good-end-made-dep14
790 }
791
792 t-dpm-pushed-good () {
793         t-splitbrain-pushed-good-start
794         t-splitbrain-pushed-good--unpack
795         t-splitbrain-rm-gitignore-patch
796         t-splitbrain-pushed-good-end-made-dep14
797 }
798
799 t-commit-build-push-expect-log () {
800         local msg=$1
801         local mpat=$2
802         t-commit "$msg"
803         t-dgit build
804         LC_MESSAGES=C \
805         t-dgit push --new 2>&1 |tee $tmp/push.log
806         t-grep-mpat "$mpat" $tmp/push.log
807 }
808
809 t-822-field () {
810         local file=$1
811         local field=$2
812         perl -e '
813                 use Dpkg::Control::Hash;
814                 my $h = new Dpkg::Control::Hash allow_pgp=>1;
815                 $h->parse(\*STDIN,"'"$file"'");
816                 my $val = $h->{"'$field'"},"\n";
817                 die "'"$file $field"'" unless defined $val;
818                 print $val,"\n";
819         ' <$file
820 }
821
822 t-defdistro () {
823         export DGIT_TEST_DISTRO=''
824         distro=''
825         t-git-config dgit-suite.unstable.distro test-dummy
826 }
827
828 t-stunt-envvar () {
829         local var=$1
830         local tstunt=$2
831         eval '
832                 case "$'$var'" in
833                 "$tstunt:"*)    ;;
834                 *":$tstunt:"*)  ;;
835                 "")             '$var'="$tstunt" ;;
836                 *)              '$var'="$tstunt:$'$var'" ;;
837                 esac
838                 export '$var'
839         '
840 }
841
842 t-tstunt--save-real () {
843         local f="$1"
844         case "$f" in
845         */*) return ;;
846         esac
847
848         local rc
849         local real
850         set +e
851         real=$(
852                 p=":$PATH:"
853                 p="${p/:"$tmp/tstunt":/:}"
854                 p="${p%:}"
855                 p="${p#:}"
856                 PATH="$p"
857                 type -p "$f"
858         )
859         rc=$?
860         set -e
861
862         case $rc in
863         1)      return ;;
864         0)      ;;
865         *)      fail "did not find $f on PATH $PATH" ;;
866         esac
867
868         local varname=${f//[^_0-9a-zA-Z]/_}
869         varname=DGIT_TEST_REAL_${varname^^}
870
871         eval "
872                 : \${$varname:=\$real}
873                 export $varname
874         "
875 }
876
877 t-tstunt () {
878         local tstunt=$tmp/tstunt
879         t-stunt-envvar PATH $tstunt
880         t-stunt-envvar PERLLIB $tstunt
881         local f
882         for f in "$@"; do
883                 t-tstunt--save-real $f
884                 f="./$f"
885                 local d="$tstunt/${f%/*}"
886                 mkdir -p $d
887                 ln -sf "$troot/tstunt/$f" "$d"/.
888         done
889 }
890
891 t-tstunt-parsechangelog () {
892         t-tstunt dpkg-parsechangelog Dpkg/Changelog/Parse.pm
893 }
894
895 t-tstunt-lintian () {
896         t-tstunt lintian
897 }
898
899 t-tstunt-debuild () {
900         t-tstunt debuild
901 }
902
903 t-incoming-dsc () {
904         local dsc=${p}_${v}.dsc
905         incoming_dsc=$tmp/incoming/$dsc
906 }
907
908 t-ref-dsc-dgit () {
909         t-incoming-dsc
910         local val; val=`t-822-field $incoming_dsc Dgit`
911         val=$( perl -e '
912                 $_=shift @ARGV;
913                 die "Dgit $_ ?" unless m/^\w+\b/;
914                 print $&,"\n" or die $!;
915         ' "$val")
916         t-ref-same-val $incoming_dsc "$val"
917 }
918
919 t-apply-diff () {
920         local v1=$1
921         local v2=$2
922         (cd $troot/pkg-srcs;
923          debdiff ${p}_${v1}.dsc ${p}_${v2}.dsc || test $? = 1) \
924          | patch -p1 -u
925 }
926
927 t-gbp-unapplied-pq2qc () {
928         # does `gbp pq export'
929         # commits the resulting debian/patches on  qc/BRANCH
930         # leaves us on qc/BRANCH (eg "qc/quilt-tip"))
931         # qc/BRANCH is not fast-forwarding
932
933         gbp pq export
934
935         branch=`git symbolic-ref HEAD`
936         branch=${branch#refs/heads/}
937
938         case "$branch" in
939         */*) fail "unexpected branch $branch" ;;
940         esac
941
942         git branch -f qc/$branch
943         git checkout qc/$branch
944         git add debian/patches
945         git commit -m 'Commit patch queue'
946 }
947
948 t-git-pseudo-merge () {
949         # like   git merge -s ours
950         if [ ! "$git_pseuomerge_opts" ]; then
951                 if git merge --help \
952                  | grep -q allow-unrelated-histories; then
953                         git_pseuomerge_opts='--allow-unrelated-histories'
954                 fi
955                 git_pseuomerge_opts+=' -s ours'
956         fi
957         git merge $git_pseuomerge_opts "$@"
958 }
959
960 t-gbp-example-prep-no-ff () {
961         t-tstunt-parsechangelog
962         t-archive example 1.0-1
963         t-git-none
964         t-worktree 1.0
965
966         cd example
967
968         t-dgit fetch
969
970         git checkout -b patch-queue/quilt-tip-2 patch-queue/quilt-tip
971         gbp pq rebase
972
973         echo '/* some comment */' >>src.c
974         git add src.c
975         git commit -m 'Add a comment to an upstream file'
976
977         t-gbp-unapplied-pq2qc
978
979         t-commit 'some updates' 1.0-2
980 }
981
982 t-gbp-example-prep () {
983         t-gbp-example-prep-no-ff
984
985         t-git-pseudo-merge \
986                 -m 'Pseudo-merge to make descendant of archive' \
987                 remotes/dgit/dgit/sid
988 }
989
990 t-make-badcommit () {
991         badcommit=$(
992                 git cat-file commit HEAD | \
993                 perl -pe 's/^committer /commiter /' | \
994                 git hash-object -w -t commit --stdin
995         )
996         t-expect-fsck-fail $badcommit
997 }
998
999 t-commit () {
1000         local msg=$1
1001         v=${2:-${majorv:-1}.$revision}
1002         dch --force-distribution -v$v --distribution ${3:-unstable} "$1"
1003         git add debian/changelog
1004         debcommit
1005         revision=$(( ${revision-0} + 1 ))
1006 }
1007
1008 t-dch-commit () {
1009         faketime @"${GIT_AUTHOR_DATE% *}" dch "$@"
1010         git commit -m "dch $*" debian/changelog
1011 }
1012
1013 t-git-config () {
1014         git config --global "$@"
1015 }
1016
1017 t-drs () {
1018  t-git-config dgit-distro.test-dummy.git-url "ext::$troot/drs-git-ext %S "
1019  t-git-config dgit-distro.test-dummy.git-check true
1020  t-git-config dgit-distro.test-dummy.git-create true
1021  t-git-config dgit-distro.test-dummy.dgit-tag-format new,old,maint
1022         cp $troot/gnupg/{dd.gpg,dm.gpg,dm.txt} $tmp/.
1023         cp $troot/suites $tmp/.
1024         cp $troot/suites $tmp/suites-master
1025
1026         export t_check_pushed_master=t-check-pushed-master
1027
1028         drs_dispatch=$tmp/distro=test-dummy
1029         mkdir $drs_dispatch
1030
1031         if [ "x$DGIT_TEST_INTREE" != x ]; then
1032                 ln -sf "$DGIT_TEST_INTREE" $drs_dispatch/dgit-live
1033         fi
1034
1035         ln -sf $tmp/git $drs_dispatch/repos
1036         ln -sf $tmp/suites $tmp/suites-master $tmp/dm.txt $drs_dispatch/
1037         mkdir -p $drs_dispatch/keyrings
1038         ln -sf $tmp/dd.gpg $drs_dispatch/keyrings/debian-keyring.gpg
1039         ln -sf $tmp/dm.gpg $drs_dispatch/keyrings/debian-maintainers.gpg
1040         ln -sf /bin/true $drs_dispatch/policy-hook
1041 }
1042
1043 t-newtag () {
1044  export tagpfx=archive/test-dummy
1045  t-git-config dgit-distro.test-dummy.dgit-tag-format new,maint
1046 }
1047 t-oldtag () {
1048  export tagpfx=test-dummy
1049  t-git-config dgit-distro.test-dummy.dgit-tag-format old
1050 }
1051
1052 t-dsd () {
1053         t-drs
1054  t-git-config dgit-distro.test-dummy.ssh "$troot/dsd-ssh"
1055  t-git-config dgit-distro.test-dummy.git-check ssh-cmd
1056  t-git-config dgit-distro.test-dummy.git-create true
1057  t-git-config dgit-distro.test-dummy.git-url \
1058                 "ext::$troot/dsd-ssh X %S /dgit/test-dummy/repos"
1059
1060  t-git-config dgit-distro.test-dummy.diverts.drs /drs
1061  t-git-config dgit-distro.test-dummy/drs.ssh "$troot/ssh"
1062  t-git-config dgit-distro.test-dummy/drs.git-url $tmp/git
1063  t-git-config dgit-distro.test-dummy/drs.git-check ssh-cmd
1064  t-git-config dgit-distro.test-dummy/drs.git-create ssh-cmd
1065
1066         echo 'no-such-package* drs' >$drs_dispatch/diverts
1067 }
1068
1069 t-policy-admin () {
1070         : '(((((((((((((((((((((((((((((((((((((((('
1071         ${DGIT_INFRA_PFX}dgit-repos-admin-debian --repos $tmp/git "$@"
1072         : '))))))))))))))))))))))))))))))))))))))))'
1073 }
1074
1075 t-policy-nonexist () {
1076         ln -sf no-such-file-or-directory $drs_dispatch/policy-hook
1077 }
1078
1079 t-make-hook-link () {
1080         local hook=$1 # in infra/
1081         local linkpath=$2
1082         hook=${DGIT_INFRA_PFX}$hook
1083         case $hook in
1084         */*)    ;;
1085         *)      hook=`type -P $hook` ;;
1086         esac
1087         ln -sf "$hook" $linkpath
1088 }
1089
1090 t-policy () {
1091         local policyhook=$1
1092         t-make-hook-link $policyhook $drs_dispatch/policy-hook
1093 }
1094
1095 t-debpolicy () {
1096         t-dsd
1097         t-policy dgit-repos-policy-debian
1098
1099         mkdir $tmp/git
1100         t-policy-admin create-db
1101 }
1102
1103 t-policy-periodic () {
1104         : '(((((((((((((((((((((((((((((((((((((((('
1105         ${DGIT_REPOS_SERVER_TEST-dgit-repos-server} \
1106                 test-dummy $drs_dispatch '' --cron
1107         : '))))))))))))))))))))))))))))))))))))))))'
1108 }
1109
1110 t-restrict () {
1111         local restriction=$1
1112         (cd $root; t-restriction-$restriction >&2)
1113 }
1114
1115 t-dependencies () {
1116         : "Hopefully installed: $*"
1117 }
1118
1119 t-chain-test () {
1120         local ct=$1
1121         local d=${0%/*}
1122         cd $root
1123         export DGIT_TEST_TESTNAME="$testname"
1124         export DGIT_TEST_TMPBASE="$tmpbase"
1125         export ADTTMP=$tmp
1126         exec "$d/$ct"
1127 }       
1128
1129 t-alt-test () {
1130         local t=${0##*/}
1131         t-${t%%-*}
1132         t-chain-test "${t#*-}"
1133 }
1134
1135 t-git-config dgit.default.old-dsc-distro test-dummy
1136
1137 case "$0" in
1138 */gnupg) ;;
1139 *)      t-setup-import gnupg    ;;
1140 esac