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