chiark / gitweb /
git-debrebase: merge: test suite: Drop check of no wreckage save
[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         esac
61
62         anal=../anal$wsfx
63         t-git-debrebase analyse $head >$anal.check
64         expect=`git rev-parse $head`
65         exec <$anal.check
66         local cid ctype info nparents
67         while read cid ctype info; do
68                 : ===== $cid $ctype $info =====
69                 test $cid = $expect
70                 local cetype=${etypes%%-*}
71                 if [ "x$ctype" = "x$cetype" ]; then cetype=SAME; fi
72                 local parents="`git log -n1 --pretty=format:%P $cid`"
73                 expect="$parents"
74                 enparents=1
75                 : "$ctype/$cetype" "$parents"
76
77                 case "$ctype/$cetype" in
78                 Pseudomerge/SAME)                       ;;
79                 Packaging/SAME)                         ;;
80                 Packaging/Upstream)                     ;;
81                 MergedBreakwaters/Packaging)            ;;
82                 MergedBreakwaters/Upstream)             ;;
83                 AddPatches/SAME)                        ;;
84                 AddPatches/AddPatchesInterop)           ;;
85                 Changelog/Packaging)                    ;;
86                 Changelog/Upstream)                     ;;
87                 Upstream/SAME)                          ;;
88                 Anchor/Upstream)                        ;;
89                 Anchor/Packaging)                       ;;
90                 *)
91                         fail "etypes=$etypes ctype=$ctype cetype=$cetype $cid"
92                         ;;
93                 esac
94
95                 case "$ctype/$etypes" in
96                 Packaging/Upstream|\
97                 Changelog/Upstream)
98                         if [ "x$bwtip" != x ]; then
99                                 test "$bwtip" = "Y:$cid"
100                                 bwtip=''
101                         fi
102                 esac
103
104                 case "$cetype" in
105                 AddPatchesInterop)
106                         git log -n1 --pretty=format:%B \
107                         | grep '^\[git-debrebase[ :]'
108                         ;;
109                 esac
110
111                 case "$ctype" in
112                 Pseudomerge)
113                         expect=${info#Contributor=}
114                         expect=${expect%% *}
115                         enparents=2
116                         git diff --quiet $expect..$cid
117                         etypes=${etypes#*-}
118
119                         : 'reject pointless pseudomerges'
120                         local overwritten=${parents/$expect/}
121                         overwritten=${overwritten// /}
122                         t-git-debrebase analyse $overwritten >$anal.overwr
123                         local ocid otype oinfo
124                         read <$anal.overwr ocid otype oinfo
125                         case "$otype" in
126                         Pseudomerge) test "x$info" != "x$oinfo" ;;
127                         esac
128                         ;;
129                 Packaging)
130                         git diff --quiet $expect..$cid -- ':.' ':!debian' 
131                         git diff --quiet $expect..$cid -- ':debian/patches'
132                         etypes=Packaging
133                         ;;
134                 AddPatches)
135                         git diff --quiet $expect..$cid -- \
136                                 ':.' ':!debian/patches'
137                         etypes=${etypes#*-}
138                         ;;
139                 Changelog)
140                         git diff --quiet $expect..$cid -- \
141                                 ':.' ':!debian/changelog'
142                         etypes=Packaging
143                         ;;
144                 Upstream/SAME)
145                         git diff --quiet $expect..$cid -- ':debian'
146                         ;;
147                 MergedBreakwaters)
148                         enparents=2
149                         ;;
150                 Anchor)
151                         break
152                         ;;
153                 esac
154
155                 local cnparents=`printf "%s" "$parents" | wc -w`
156                 test $cnparents = $enparents
157
158                 local cndparents=`
159         for f in $parents; do echo $f; done | t-sort -u | wc -w
160                                 `
161                 test $cndparents = $cnparents
162
163                 case "$parents" in
164                 *"$expect"*)    ;;
165                 *)              fail 'unexpected parent' ;;
166                 esac
167
168                 case "$ctype" in
169                 MergedBreakwaters)
170                         local f
171                         local parent_ix=0
172                         for f in $parents; do
173                                 t-gdr-good-analyse $f breakwater \
174                                         $wsfx-mp$parent_ix
175                                 parent_ix=$(( $parent_ix + 1 ))
176                         done
177                         return
178                         ;;
179                 esac            
180
181         done
182 }
183
184 t-some-changes () {
185         local token=$1
186         local which=${2:-dum}
187         local fsuffix=$3
188
189         t-git-next-date
190
191         case "$which" in
192         *d*)
193                 echo >>debian/zorkmid$fsuffix "// debian $token"
194                 git add debian/zorkmid$fsuffix
195                 git commit -m "DEBIAN add zorkmid$fsuffix ($token)"
196                 ;;
197         esac
198
199         case "$which" in
200         *u*)
201                 echo >>src$fsuffix.c "// upstream $token"
202                 git add src$fsuffix.c
203                 git commit -m "UPSTREAM edit src$fsuffix.c ($token)"
204                 ;;
205         esac
206
207         case "$which" in
208         *m*)
209                 for f in debian/zorkmid$fsuffix src$fsuffix.c; do
210                         echo "// both! $token" >>$f
211                         git add $f
212                 done
213                 git commit -m "MIXED add both($fsuffix) ($token)"
214                 ;;
215         esac
216
217         t-git-next-date
218 }
219
220 t-make-new-upstream-tarball () {
221         local uv=$1
222         git checkout make-upstream
223         # leaves ust set to filename of orig tarball
224         echo "upstream $uv" >>docs/README
225         git commit -a -m "upstream $uv tarball"
226         ust=example_$uv.orig.tar.gz
227         git archive -o ../$ust --prefix=example-2.0/ make-upstream
228 }
229
230 t-nmu-upload-1 () {
231         # usage:
232         #  v=<full version>
233         #  nmu-upload-1 <nmubranch>
234         #  gbp pq import or perhaps other similar things
235         #  nmu-upload-2
236         #  maybe make some dgit-covertible commits
237         #  nmu-upload-3
238
239         t-git-next-date
240         nmubranch=$1
241         git checkout -f -b $nmubranch
242         t-git-debrebase
243         t-git-debrebase convert-to-gbp
244         t-git-next-date
245         # now we are on a gbp patched-unapplied branch
246 }
247
248
249 t-nmu-upload-2 () {
250         t-git-next-date
251         t-dch-commit -v $v -m "nmu $nmubranch $v"
252 }
253
254 t-nmu-upload-3 () {
255         t-dch-commit-r
256
257         t-dgit -wgf build-source
258
259         cd ..
260         c=${p}_${v}_source.changes
261         debsign -kBCD22CD83243B79D3DFAC33EA3DBCBC039B13D8A $c
262         dput -c $tmp/dput.cf test-dummy $c
263
264         t-archive-process-incoming sid
265         t-git-next-date
266         cd $p
267         git checkout master
268 }
269
270 t-nmu-commit-an-upstream-change () {
271         echo >>newsrc.c "// more upstream"
272         git add newsrc.c
273         git commit -m 'UPSTREAM NMU'
274 }
275
276 t-maintainer-commit-some-changes () {
277         t-dch-commit -v$v -m "start $v"
278
279         t-some-changes "maintainer $v"
280         t-git-debrebase
281         t-git-debrebase stitch
282
283         git branch did.maintainer
284
285         t-git-next-date
286 }
287
288 t-nmu-causes-ff-fail () {
289         t-dgit fetch
290
291         t-expect-fail E:'Not.*fast-forward' \
292         git merge --ff-only dgit/dgit/sid
293
294         t-expect-fail E:'-fdiverged.*refs/remotes/dgit/dgit/sid' \
295         t-git-debrebase
296 }
297
298 t-nmu-reconciled-good () {
299         local nmutree=$1
300
301         : 'check that what we have is what is expected'
302
303         git checkout -b compare.nmu origin/master~0
304         git checkout $nmutree .
305         git rm -rf debian/patches
306         git commit -m 'rm patches nmu'
307
308         git checkout -b compare.maintainer origin/master~0
309         git checkout did.maintainer .
310         git rm -rf --ignore-unmatch debian/patches
311         git commit --allow-empty -m 'rm patches maintainer'
312
313         git merge compare.nmu
314         git diff --quiet master
315
316         : 'check that dgit still likes it'
317
318         git checkout master
319         t-dgit -wgf quilt-fixup
320 }
321
322 t-gdr-prep-new-upstream () {
323         uv=$1
324         t-git-next-date
325         git checkout make-upstream
326         git reset --hard upstream
327         t-make-new-upstream-tarball $uv
328         git push . make-upstream:upstream
329         git checkout master
330         t-git-next-date
331 }