chiark / gitweb /
changelog: start 9.10
[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         t-non-dgit-upload
264         git checkout master
265 }
266
267 t-nmu-commit-an-upstream-change () {
268         echo >>newsrc.c "// more upstream"
269         git add newsrc.c
270         git commit -m 'UPSTREAM NMU'
271 }
272
273 t-maintainer-commit-some-changes () {
274         t-dch-commit -v$v -m "start $v"
275
276         t-some-changes "maintainer $v"
277         t-git-debrebase
278         t-git-debrebase stitch
279
280         git branch did.maintainer
281
282         t-git-next-date
283 }
284
285 t-nmu-causes-ff-fail () {
286         t-dgit fetch
287
288         t-expect-fail E:'Not.*fast-forward' \
289         git merge --ff-only dgit/dgit/sid
290
291         t-expect-fail E:'-fdiverged.*refs/remotes/dgit/dgit/sid' \
292         t-git-debrebase
293 }
294
295 t-nmu-reconciled-good () {
296         local nmutree=$1
297
298         : 'check that what we have is what is expected'
299
300         git checkout -b compare.nmu origin/master~0
301         git checkout $nmutree .
302         git rm -rf debian/patches
303         git commit -m 'rm patches nmu'
304
305         git checkout -b compare.maintainer origin/master~0
306         git checkout did.maintainer .
307         git rm -rf --ignore-unmatch debian/patches
308         git commit --allow-empty -m 'rm patches maintainer'
309
310         git merge compare.nmu
311         git diff --quiet master
312
313         : 'check that dgit still likes it'
314
315         git checkout master
316         t-dgit -wgf quilt-fixup
317 }
318
319 t-gdr-prep-new-upstream () {
320         uv=$1
321         t-git-next-date
322         git checkout make-upstream
323         git reset --hard upstream
324         t-make-new-upstream-tarball $uv
325         git push . make-upstream:upstream
326         git checkout master
327         t-git-next-date
328 }
329
330 t-gdr-gbp-import-core () {
331         p=example
332         t-worktree 1.1
333
334         cd example
335
336         : 'fake up some kind of upstream'
337         git checkout -b upstream quilt-tip
338         rm -rf debian
339         mkdir debian
340         echo junk >debian/rules
341         git add debian
342         git commit -m "an upstream retcon ($0)"
343         git tag v1.0
344 }
345
346 t-gdr-gbp-import-core-with-queue () {
347         t-gdr-gbp-import-core
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 }
363
364 t-gdr-made-patches () {
365         git log -n1 --'pretty=format:%B' \
366         | egrep '^\[git-debrebase'
367 }