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