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