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