chiark / gitweb /
test suite: gdr-diverge-nmu-dgit: Insist on gdr-generated patches
[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         case $state in
25         pushed*)
26                 t-gdr-made-patches
27                 ;;
28         esac
29
30         git diff --quiet ${beforetag-t.before} -- ':.' ':!debian/patches'
31
32         LC_MESSAGES=C t-git-debrebase status >../status.check
33         case $state in
34         laundered*)
35                 egrep '^  *branch is laundered' ../status.check
36                 ;;
37         stitched*|pushed*)
38                 egrep \
39  '^  *branch contains furniture|^  *branch is unlaundered|^  *branch needs laundering' ../status.check
40                 egrep '^  stitched$' ../status.check
41                 ;;
42         esac
43
44         t-gdr-good-analyse HEAD $state
45 }
46
47 t-gdr-good-analyse () {
48         local head=$1
49         local state=$2
50         local wsfx=$3
51         local etypes bwtip
52
53         # etypes is either a type,
54         # or   PseudoMerge-<more etypes>
55         # or   AddPatches-<more etypes>
56
57         case $state in
58         laundered)
59                         etypes=Upstream
60                         bwtip=Y:`t-git-debrebase breakwater`
61                 ;;
62         stitched)       etypes=Pseudomerge-Upstream ;;
63         pushed)         etypes=AddPatches-Pseudomerge-Upstream ;;
64         pushed-interop) etypes=Pseudomerge-AddPatchesInterop-Upstream ;;
65         breakwater)     etypes=Packaging ;;
66         *)              fail-unknown-state-$state ;;
67         esac
68
69         anal=../anal$wsfx
70         t-git-debrebase analyse $head >$anal.check
71         expect=`git rev-parse $head`
72         exec <$anal.check
73         local cid ctype info nparents
74         while read cid ctype info; do
75                 : ===== $cid $ctype $info =====
76                 test $cid = $expect
77                 local cetype=${etypes%%-*}
78                 if [ "x$ctype" = "x$cetype" ]; then cetype=SAME; fi
79                 local parents="`git log -n1 --pretty=format:%P $cid`"
80                 expect="$parents"
81                 enparents=1
82                 : "$ctype/$cetype" "$parents"
83
84                 case "$ctype/$cetype" in
85                 Pseudomerge/SAME)                       ;;
86                 Packaging/SAME)                         ;;
87                 Packaging/Upstream)                     ;;
88                 MergedBreakwaters/Packaging)            ;;
89                 MergedBreakwaters/Upstream)             ;;
90                 AddPatches/SAME)                        ;;
91                 AddPatches/AddPatchesInterop)           ;;
92                 Changelog/Packaging)                    ;;
93                 Changelog/Upstream)                     ;;
94                 Upstream/SAME)                          ;;
95                 Anchor/Upstream)                        ;;
96                 Anchor/Packaging)                       ;;
97                 *)
98                         fail "etypes=$etypes ctype=$ctype cetype=$cetype $cid"
99                         ;;
100                 esac
101
102                 case "$ctype/$etypes" in
103                 Packaging/Upstream|\
104                 Changelog/Upstream)
105                         if [ "x$bwtip" != x ]; then
106                                 test "$bwtip" = "Y:$cid"
107                                 bwtip=''
108                         fi
109                 esac
110
111                 case "$cetype" in
112                 AddPatchesInterop)
113                         git log -n1 --pretty=format:%B \
114                         | grep '^\[git-debrebase[ :]'
115                         ;;
116                 esac
117
118                 case "$ctype" in
119                 Pseudomerge)
120                         expect=${info#Contributor=}
121                         expect=${expect%% *}
122                         enparents=2
123                         git diff --quiet $expect..$cid
124                         etypes=${etypes#*-}
125
126                         : 'reject pointless pseudomerges'
127                         local overwritten=${parents/$expect/}
128                         overwritten=${overwritten// /}
129                         t-git-debrebase analyse $overwritten >$anal.overwr
130                         local ocid otype oinfo
131                         read <$anal.overwr ocid otype oinfo
132                         case "$otype" in
133                         Pseudomerge) test "x$info" != "x$oinfo" ;;
134                         esac
135                         ;;
136                 Packaging)
137                         git diff --quiet $expect..$cid -- ':.' ':!debian' 
138                         git diff --quiet $expect..$cid -- ':debian/patches'
139                         etypes=Packaging
140                         ;;
141                 AddPatches)
142                         git diff --quiet $expect..$cid -- \
143                                 ':.' ':!debian/patches'
144                         etypes=${etypes#*-}
145                         ;;
146                 Changelog)
147                         git diff --quiet $expect..$cid -- \
148                                 ':.' ':!debian/changelog'
149                         etypes=Packaging
150                         ;;
151                 Upstream/SAME)
152                         git diff --quiet $expect..$cid -- ':debian'
153                         ;;
154                 MergedBreakwaters)
155                         enparents=2
156                         ;;
157                 Anchor)
158                         break
159                         ;;
160                 esac
161
162                 local cnparents=`printf "%s" "$parents" | wc -w`
163                 test $cnparents = $enparents
164
165                 local cndparents=`
166         for f in $parents; do echo $f; done | t-sort -u | wc -w
167                                 `
168                 test $cndparents = $cnparents
169
170                 case "$parents" in
171                 *"$expect"*)    ;;
172                 *)              fail 'unexpected parent' ;;
173                 esac
174
175                 case "$ctype" in
176                 MergedBreakwaters)
177                         local f
178                         local parent_ix=0
179                         for f in $parents; do
180                                 t-gdr-good-analyse $f breakwater \
181                                         $wsfx-mp$parent_ix
182                                 parent_ix=$(( $parent_ix + 1 ))
183                         done
184                         return
185                         ;;
186                 esac            
187
188         done
189 }
190
191 t-some-changes () {
192         local token=$1
193         local which=${2:-dum}
194         local fsuffix=$3
195
196         t-git-next-date
197
198         case "$which" in
199         *d*)
200                 echo >>debian/zorkmid$fsuffix "// debian $token"
201                 git add debian/zorkmid$fsuffix
202                 git commit -m "DEBIAN add zorkmid$fsuffix ($token)"
203                 ;;
204         esac
205
206         case "$which" in
207         *u*)
208                 echo >>src$fsuffix.c "// upstream $token"
209                 git add src$fsuffix.c
210                 git commit -m "UPSTREAM edit src$fsuffix.c ($token)"
211                 ;;
212         esac
213
214         case "$which" in
215         *m*)
216                 for f in debian/zorkmid$fsuffix src$fsuffix.c; do
217                         echo "// both! $token" >>$f
218                         git add $f
219                 done
220                 git commit -m "MIXED add both($fsuffix) ($token)"
221                 ;;
222         esac
223
224         t-git-next-date
225 }
226
227 t-make-new-upstream-tarball () {
228         local uv=$1
229         git checkout make-upstream
230         # leaves ust set to filename of orig tarball
231         echo "upstream $uv" >>docs/README
232         git commit -a -m "upstream $uv tarball"
233         ust=example_$uv.orig.tar.gz
234         git archive -o ../$ust --prefix=example-2.0/ 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         : 'fake up that our quilt-tip was descended from upstream'
356         git checkout quilt-tip
357         git merge --no-edit -s ours upstream
358
359         : 'fake up that our quilt-tip had the patch queue in it'
360         git checkout patch-queue/quilt-tip
361         gbp pq export
362         git add debian/patches
363         git commit -m "patch queue update ($0)"
364
365         : 'make branch names more conventional'
366         git branch -D master
367         git branch -m quilt-tip master
368 }
369
370 t-gdr-made-patches () {
371         git log -n1 --'pretty=format:%B' \
372         | egrep '^\[git-debrebase'
373 }