chiark / gitweb /
git-debrebase: merge: Comment about laundry of merge of unstitched
[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         local fsuffix=$3
161
162         t-git-next-date
163
164         case "$which" in
165         *d*)
166                 echo >>debian/zorkmid$fsuffix "// debian $token"
167                 git add debian/zorkmid$fsuffix
168                 git commit -m "DEBIAN add zorkmid$fsuffix ($token)"
169                 ;;
170         esac
171
172         case "$which" in
173         *u*)
174                 echo >>src$fsuffix.c "// upstream $token"
175                 git add src$fsuffix.c
176                 git commit -m "UPSTREAM edit src$fsuffix.c ($token)"
177                 ;;
178         esac
179
180         case "$which" in
181         *m*)
182                 for f in debian/zorkmid$fsuffix src$fsuffix.c; do
183                         echo "// both! $token" >>$f
184                         git add $f
185                 done
186                 git commit -m "MIXED add both($fsuffix) ($token)"
187                 ;;
188         esac
189
190         t-git-next-date
191 }
192
193 t-make-new-upstream-tarball () {
194         local uv=$1
195         git checkout make-upstream
196         # leaves ust set to filename of orig tarball
197         echo "upstream $uv" >>docs/README
198         git commit -a -m "upstream $uv tarball"
199         ust=example_$uv.orig.tar.gz
200         git archive -o ../$ust --prefix=example-2.0/ make-upstream
201 }
202
203 t-nmu-upload-1 () {
204         # usage:
205         #  v=<full version>
206         #  nmu-upload-1 <nmubranch>
207         #  gbp pq import or perhaps other similar things
208         #  nmu-upload-2
209         #  maybe make some dgit-covertible commits
210         #  nmu-upload-3
211
212         t-git-next-date
213         nmubranch=$1
214         git checkout -f -b $nmubranch
215         t-git-debrebase
216         t-git-debrebase convert-to-gbp
217         t-git-next-date
218         # now we are on a gbp patched-unapplied branch
219 }
220
221
222 t-nmu-upload-2 () {
223         t-git-next-date
224         t-dch-commit -v $v -m "nmu $nmubranch $v"
225 }
226
227 t-nmu-upload-3 () {
228         t-dch-commit-r
229
230         t-dgit -wgf build-source
231
232         cd ..
233         c=${p}_${v}_source.changes
234         debsign -kBCD22CD83243B79D3DFAC33EA3DBCBC039B13D8A $c
235         dput -c $tmp/dput.cf test-dummy $c
236
237         t-archive-process-incoming sid
238         t-git-next-date
239         cd $p
240         git checkout master
241 }
242
243 t-nmu-commit-an-upstream-change () {
244         echo >>newsrc.c "// more upstream"
245         git add newsrc.c
246         git commit -m 'UPSTREAM NMU'
247 }
248
249 t-maintainer-commit-some-changes () {
250         t-dch-commit -v$v -m "start $v"
251
252         t-some-changes "maintainer $v"
253         t-git-debrebase
254         t-git-debrebase stitch
255
256         git branch did.maintainer
257
258         t-git-next-date
259 }
260
261 t-nmu-causes-ff-fail () {
262         t-dgit fetch
263
264         t-expect-fail E:'Not.*fast-forward' \
265         git merge --ff-only dgit/dgit/sid
266
267         t-expect-fail E:'-fdiverged.*refs/remotes/dgit/dgit/sid' \
268         t-git-debrebase
269 }
270
271 t-nmu-reconciled-good () {
272         local nmutree=$1
273
274         : 'check that what we have is what is expected'
275
276         git checkout -b compare.nmu origin/master~0
277         git checkout $nmutree .
278         git rm -rf debian/patches
279         git commit -m 'rm patches nmu'
280
281         git checkout -b compare.maintainer origin/master~0
282         git checkout did.maintainer .
283         git rm -rf --ignore-unmatch debian/patches
284         git commit --allow-empty -m 'rm patches maintainer'
285
286         git merge compare.nmu
287         git diff --quiet master
288
289         : 'check that dgit still likes it'
290
291         git checkout master
292         t-dgit -wgf quilt-fixup
293 }
294
295 t-gdr-prep-new-upstream () {
296         uv=$1
297         t-git-next-date
298         git checkout make-upstream
299         git reset --hard upstream
300         t-make-new-upstream-tarball $uv
301         git push . make-upstream:upstream
302         git checkout master
303         t-git-next-date
304 }