chiark / gitweb /
test suite: baredebian-multitar: New test
[dgit.git] / tests / lib-gdr
1 #
2
3 : ${GDR_TEST_DEBUG=-D}
4 export GDR_TEST_DEBUG
5
6 t-tstunt debchange
7
8 t-git-debrebase () {
9         local gdr=${DGIT_GITDEBREBASE_TEST-git-debrebase}
10         : '
11 {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{'
12         $gdr "--dgit=${DGIT_TEST-dgit}" $GDR_TEST_OPTS \
13                 $GDR_TEST_DEBUG $t_gdr_xopts "$@"
14         : '}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
15 '
16 }
17
18 t-gdr-good () {
19         local state=$1
20         local beforetag=$2 # say HEAD to skip this check
21         # state should be one of
22         #   laundered
23         #   stitched
24         #   pushed
25
26         case $state in
27         pushed*)
28                 t-gdr-made-patches
29                 ;;
30         esac
31
32         git diff --quiet ${beforetag-t.before} -- ':.' ':!debian/patches'
33
34         LC_MESSAGES=C t-git-debrebase status >../status.check
35         case $state in
36         laundered*)
37                 egrep '^  *branch is laundered' ../status.check
38                 ;;
39         stitched*|pushed*)
40                 egrep \
41  '^  *branch contains furniture|^  *branch is unlaundered|^  *branch needs laundering' ../status.check
42                 egrep '^  stitched$' ../status.check
43                 ;;
44         esac
45
46         t-gdr-good-analyse HEAD $state
47 }
48
49 t-gdr-good-analyse () {
50         local head=$1
51         local state=$2
52         local wsfx=$3
53         local etypes bwtip
54
55         # etypes is either a type,
56         # or   PseudoMerge-<more etypes>
57         # or   AddPatches-<more etypes>
58
59         case $state in
60         laundered)
61                         etypes=Upstream
62                         bwtip=Y:`t-git-debrebase breakwater`
63                 ;;
64         stitched)       etypes=Pseudomerge-Upstream ;;
65         pushed)         etypes=AddPatches-Pseudomerge-Upstream ;;
66         pushed-interop) etypes=Pseudomerge-AddPatchesInterop-Upstream ;;
67         breakwater)     etypes=Packaging ;;
68         *)              fail-unknown-state-$state ;;
69         esac
70
71         anal=../anal$wsfx
72         t-git-debrebase analyse $head >$anal.check
73         expect=`git rev-parse $head`
74         exec <$anal.check
75         local cid ctype info nparents
76         while read cid ctype info; do
77                 : ===== $cid $ctype $info =====
78                 test $cid = $expect
79                 local cetype=${etypes%%-*}
80                 if [ "x$ctype" = "x$cetype" ]; then cetype=SAME; fi
81                 local parents="`git log -n1 --pretty=format:%P $cid`"
82                 expect="$parents"
83                 enparents=1
84                 : "$ctype/$cetype" "$parents"
85
86                 case "$ctype/$cetype" in
87                 Pseudomerge/SAME)                       ;;
88                 Packaging/SAME)                         ;;
89                 Packaging/Upstream)                     ;;
90                 MergedBreakwaters/Packaging)            ;;
91                 MergedBreakwaters/Upstream)             ;;
92                 AddPatches/SAME)                        ;;
93                 AddPatches/AddPatchesInterop)           ;;
94                 Changelog/Packaging)                    ;;
95                 Changelog/Upstream)                     ;;
96                 Upstream/SAME)                          ;;
97                 Anchor/Upstream)                        ;;
98                 Anchor/Packaging)                       ;;
99                 *)
100                         fail "etypes=$etypes ctype=$ctype cetype=$cetype $cid"
101                         ;;
102                 esac
103
104                 case "$ctype/$etypes" in
105                 Packaging/Upstream|\
106                 Changelog/Upstream)
107                         if [ "x$bwtip" != x ]; then
108                                 test "$bwtip" = "Y:$cid"
109                                 bwtip=''
110                         fi
111                 esac
112
113                 case "$cetype" in
114                 AddPatchesInterop)
115                         git log -n1 --pretty=format:%B \
116                         | grep '^\[git-debrebase[ :]'
117                         ;;
118                 esac
119
120                 case "$ctype" in
121                 Pseudomerge)
122                         expect=${info#Contributor=}
123                         expect=${expect%% *}
124                         enparents=2
125                         git diff --quiet $expect..$cid
126                         etypes=${etypes#*-}
127
128                         : 'reject pointless pseudomerges'
129                         local overwritten=${parents/$expect/}
130                         overwritten=${overwritten// /}
131                         t-git-debrebase analyse $overwritten >$anal.overwr
132                         local ocid otype oinfo
133                         read <$anal.overwr ocid otype oinfo
134                         case "$otype" in
135                         Pseudomerge) test "x$info" != "x$oinfo" ;;
136                         esac
137                         ;;
138                 Packaging)
139                         git diff --quiet $expect..$cid -- ':.' ':!debian' 
140                         git diff --quiet $expect..$cid -- ':debian/patches'
141                         etypes=Packaging
142                         ;;
143                 AddPatches)
144                         git diff --quiet $expect..$cid -- \
145                                 ':.' ':!debian/patches'
146                         etypes=${etypes#*-}
147                         ;;
148                 Changelog)
149                         git diff --quiet $expect..$cid -- \
150                                 ':.' ':!debian/changelog'
151                         etypes=Packaging
152                         ;;
153                 Upstream/SAME)
154                         git diff --quiet $expect..$cid -- ':debian'
155                         ;;
156                 MergedBreakwaters)
157                         enparents=2
158                         ;;
159                 Anchor)
160                         break
161                         ;;
162                 esac
163
164                 local cnparents=`printf "%s" "$parents" | wc -w`
165                 test $cnparents = $enparents
166
167                 local cndparents=`
168         for f in $parents; do echo $f; done | t-sort -u | wc -w
169                                 `
170                 test $cndparents = $cnparents
171
172                 case "$parents" in
173                 *"$expect"*)    ;;
174                 *)              fail 'unexpected parent' ;;
175                 esac
176
177                 case "$ctype" in
178                 MergedBreakwaters)
179                         local f
180                         local parent_ix=0
181                         for f in $parents; do
182                                 t-gdr-good-analyse $f breakwater \
183                                         $wsfx-mp$parent_ix
184                                 parent_ix=$(( $parent_ix + 1 ))
185                         done
186                         return
187                         ;;
188                 esac            
189
190         done
191 }
192
193 t-some-changes () {
194         local token=$1
195         local which=${2:-dum}
196         local fsuffix=$3
197
198         t-git-next-date
199
200         case "$which" in
201         *d*)
202                 echo >>debian/zorkmid$fsuffix "// debian $token"
203                 git add debian/zorkmid$fsuffix
204                 git commit -m "DEBIAN add zorkmid$fsuffix ($token)"
205                 ;;
206         esac
207
208         case "$which" in
209         *u*)
210                 echo >>src$fsuffix.c "// upstream $token"
211                 git add src$fsuffix.c
212                 git commit -m "UPSTREAM edit src$fsuffix.c ($token)"
213                 ;;
214         esac
215
216         case "$which" in
217         *m*)
218                 for f in debian/zorkmid$fsuffix src$fsuffix.c; do
219                         echo "// both! $token" >>$f
220                         git add $f
221                 done
222                 git commit -m "MIXED add both($fsuffix) ($token)"
223                 ;;
224         esac
225
226         t-git-next-date
227 }
228
229 t-make-new-upstream-tarball () {
230         local uv=$1
231         git checkout make-upstream
232         echo "upstream $uv" >>docs/README
233         git commit -a -m "upstream $uv tarball"
234         t-make-orig example $uv make-upstream
235 }
236
237 t-nmu-upload-1 () {
238         # usage:
239         #  v=<full version>
240         #  nmu-upload-1 <nmubranch>
241         #  gbp pq import or perhaps other similar things
242         #  nmu-upload-2
243         #  maybe make some dgit-covertible commits
244         #  nmu-upload-3
245
246         t-git-next-date
247         nmubranch=$1
248         git checkout -f -b $nmubranch
249         t-git-debrebase
250         t-git-debrebase convert-to-gbp
251         t-git-next-date
252         # now we are on a gbp patched-unapplied branch
253 }
254
255
256 t-nmu-upload-2 () {
257         t-git-next-date
258         t-dch-commit -v $v -m "nmu $nmubranch $v"
259 }
260
261 t-nmu-upload-3 () {
262         t-dch-commit-r
263
264         t-dgit -wgf build-source
265
266         cd ..
267         c=${p}_${v}_source.changes
268         debsign -kBCD22CD83243B79D3DFAC33EA3DBCBC039B13D8A $c
269         dput -c $tmp/dput.cf test-dummy $c
270
271         t-archive-process-incoming sid
272         t-git-next-date
273         cd $p
274         git checkout master
275 }
276
277 t-nmu-commit-an-upstream-change () {
278         echo >>newsrc.c "// more upstream"
279         git add newsrc.c
280         git commit -m 'UPSTREAM NMU'
281 }
282
283 t-maintainer-commit-some-changes () {
284         t-dch-commit -v$v -m "start $v"
285
286         t-some-changes "maintainer $v"
287         t-git-debrebase
288         t-git-debrebase stitch
289
290         git branch did.maintainer
291
292         t-git-next-date
293 }
294
295 t-nmu-causes-ff-fail () {
296         t-dgit fetch
297
298         t-expect-fail E:'Not.*fast-forward' \
299         git merge --ff-only dgit/dgit/sid
300
301         t-expect-fail E:'-fdiverged.*refs/remotes/dgit/dgit/sid' \
302         t-git-debrebase
303 }
304
305 t-nmu-reconciled-good () {
306         local nmutree=$1
307
308         : 'check that what we have is what is expected'
309
310         git checkout -b compare.nmu origin/master~0
311         git checkout $nmutree .
312         git rm -rf debian/patches
313         git commit -m 'rm patches nmu'
314
315         git checkout -b compare.maintainer origin/master~0
316         git checkout did.maintainer .
317         git rm -rf --ignore-unmatch debian/patches
318         git commit --allow-empty -m 'rm patches maintainer'
319
320         git merge compare.nmu
321         git diff --quiet master
322
323         : 'check that dgit still likes it'
324
325         git checkout master
326         t-dgit -wgf quilt-fixup
327 }
328
329 t-gdr-prep-new-upstream () {
330         uv=$1
331         t-git-next-date
332         git checkout make-upstream
333         git reset --hard upstream
334         t-make-new-upstream-tarball $uv
335         git push . make-upstream:upstream
336         git checkout master
337         t-git-next-date
338 }
339
340 t-gdr-gbp-import-core () {
341         p=example
342         t-worktree 1.1
343
344         cd example
345
346         : 'fake up some kind of upstream'
347         git checkout -b upstream quilt-tip
348         rm -rf debian
349         mkdir debian
350         echo junk >debian/rules
351         git add debian
352         git commit -m "an upstream retcon ($0)"
353         git tag v1.0
354 }
355
356 t-gdr-gbp-import-core-with-queue () {
357         t-gdr-gbp-import-core
358
359         : 'fake up that our quilt-tip was descended from upstream'
360         git checkout quilt-tip
361         git merge --no-edit -s ours upstream
362
363         : 'fake up that our quilt-tip had the patch queue in it'
364         git checkout patch-queue/quilt-tip
365         gbp pq export
366         git add debian/patches
367         git commit -m "patch queue update ($0)"
368
369         : 'make branch names more conventional'
370         git branch -D master
371         git branch -m quilt-tip master
372 }
373
374 t-gdr-made-patches () {
375         git log -n1 --'pretty=format:%B' \
376         | egrep '^\[git-debrebase'
377 }