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