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