chiark / gitweb /
test suite: Add t-tstunt-parsechangelog to many gdr tests.
[dgit.git] / tests / tests / gdr-subcommands
1 #!/bin/bash
2 set -e
3 . tests/lib
4
5 t-dependencies GDR
6
7 t-tstunt-parsechangelog
8 t-setup-import gdr-convert-gbp
9
10 cd $p
11
12 t-dgit setup-mergechangelogs
13
14 mix-it () {
15         t-git-next-date
16
17         local m=$(git symbolic-ref HEAD)
18         t-some-changes "subcommands $m 1"
19
20         # we want patches mde by dgit, not gdr, for our test cases
21         t-dgit --git-debrebase=true -wgf quilt-fixup
22         t-git-next-date
23
24         t-some-changes "subcommands $m 2"
25         t-git-next-date
26 }
27
28 git checkout -b stitched-laundered master
29 mix-it
30 t-git-debrebase quick
31 t-gdr-good stitched HEAD
32
33 git checkout -b stitched-mixed master
34 mix-it
35
36 git checkout -b unstitched-laundered master
37 mix-it
38 t-git-debrebase
39 t-gdr-good laundered
40
41 git checkout -b unstitched-mixed master
42 t-git-debrebase
43 mix-it
44
45 t-git-next-date
46
47 git show-ref 
48
49 subcmd () {
50         local subcmd=$1
51         shift
52         for startbranch in {stitched,unstitched}-{laundered,mixed}; do
53                 work="work-$subcmd-$startbranch"
54
55                 : "---------- $subcmd $startbranch ----------"
56
57                 git for-each-ref "**/$startbranch"{,/**} \
58                         --format='create %(refname) %(objectname)' \
59                 | sed "s/$startbranch/$work/" \
60                 | git update-ref --stdin
61
62                 git checkout $work
63                 checkletters=$1; shift
64
65                 before=before-$work
66                 git branch $before
67
68                 local xopts=''
69
70                 case "$checkletters" in
71                 XX*)
72                         fail "$checkletters" # for debugging
73                         ;;
74                 esac
75
76                 case "$checkletters" in
77                 X*)
78                         t-expect-fail E:'snags: [0-9]* blockers' \
79                         t-git-debrebase $xopts $subcmd
80                         xopts+=' --force'
81                         next_checkletter
82                         ;;
83                 esac
84
85                 case "$checkletters" in
86                 N*)
87                         t-expect-fail E:. \
88                         t-git-debrebase $xopts $subcmd
89                         xopts+=' --noop-ok'
90                         next_checkletter
91                         ;;
92                 esac
93
94                 case "$checkletters" in
95                 [EF]:*)
96                         t-expect-fail "$checkletters" \
97                         t-git-debrebase $xopts $subcmd
98                         continue
99                         ;;
100                 *)
101                         t-git-debrebase $xopts $subcmd
102                         ;;
103                 esac
104
105                 peel=peel-$subcmd-$startbranch
106                 git checkout -b $peel
107                 t-clean-on-branch $peel
108
109                 : "---------- $subcmd $startbranch $checkletters ----------"
110
111                 while [ "x$checkletters" != x ]; do
112                         : "---- $subcmd $startbranch ...$checkletters ----"
113                         make_check "$checkletters"
114                         checkletters="${checkletters#?}"
115                 done
116         done
117
118 }
119
120 next_checkletter () {
121         checkletters="${checkletters#?}"
122 }
123
124 make_check () {
125         case "$1" in
126         [Nn]*)
127                 t-refs-same-start
128                 t-refs-same refs/heads/$before refs/heads/$work
129                 ;;
130         U*)
131                 t-refs-same-start
132                 t-refs-same refs/heads/$before refs/ffq-prev/heads/$work
133                 make_check u
134                 ;;
135         u*)
136                 t-git-get-ref refs/ffq-prev/heads/$work
137                 t-refs-notexist refs/debrebase-last/heads/$work
138                 ;;
139         V*)
140                 t-refs-same-start
141                 t-refs-same refs/ffq-prev/heads/$work \
142                         refs/ffq-prev/heads/$startbranch
143                 t-refs-notexist refs/debrebase-last/heads/$work
144                 ;;
145         s*)
146                 t-refs-notexist refs/ffq-prev/heads/$work
147                 t-refs-same-start
148                 t-refs-same refs/debrebase-last/heads/$work \
149                         refs/debrebase-last/heads/$startbranch
150                 t-has-ancestor HEAD refs/debrebase-last/heads/$work
151                 ;;
152         S*)
153                 t-refs-notexist refs/ffq-prev/heads/$work
154                 t-refs-same-start refs/debrebase-last/heads/$work
155                 t-ref-head
156                 git diff --quiet HEAD^1
157                 git diff HEAD^2 | grep $startbranch
158                 git reset --hard HEAD^1
159                 ;;
160         P*)
161                 t-dgit -wgf --quilt=nofix quilt-fixup
162                 git diff HEAD~ debian/patches | egrep .
163                 git diff --quiet HEAD~ -- ':.' ':!debian/patches'
164                 git reset --hard HEAD~
165                 ;;
166         l*)
167                 git diff --quiet HEAD refs/heads/$before -- ':.' ':!debian/patches'
168                 t-gdr-good laundered
169                 ;;
170         t*)
171                 git diff --quiet HEAD refs/heads/$before
172                 ;;
173         f*)
174                 t-has-ancestor HEAD refs/heads/$before
175                 ;;
176         *)
177                 fail "$1"
178                 ;;
179         esac
180 }
181
182 Ec="F:No ongoing git-debrebase session"
183 Ep="F:Patch export produced patch amendments"
184
185 # input state:
186 #  stitched?            st'd    st'd    unst'd  unst'd
187 #  laundered?           laund'd mixed   laund'd mixed
188 #
189 # "mixed" means an out of order branch
190 # containing mixed commits and patch additions,
191 # but which needs even more patches
192 #
193 subcmd  ''              Ult     Ull     Vlt     Vl
194 subcmd  stitch          Ns      Nu      Sltf    Stf
195 subcmd  prepush         Ns      Nu      Sltf    Stf
196 subcmd  quick           ns      Sl      Sltf    Sl
197 subcmd  conclude        "$Ec"   "$Ec"   Sltf    Sl
198 subcmd  make-patches    sPft    "$Ep"   uPft    "$Ep"
199 #subcmd dgit-upload-hook Psft   "$Ep"   SPft    "$Ep"
200 #
201 # result codes, each one is a check:
202 #   E:$pat      } this is an error (must come first)
203 #   F:$pat      } arg is passed to expect-fail
204 #
205 #   X           should fail due to snags, but succeed when forced
206 #   XX          crash out of script for manual debugging
207 #
208 #   N           this is a noop, error unless --noop-ok
209 #   n           this is a silent noop
210 # both of these imply tf; but, specify also one of   u s
211 #
212 # should normally specify one of these:
213 #   U           just unstiched: ffq-prev is exactly previous HEAD; implies u
214 #   u           result is unstitched
215 #   V           ffq-prev remains unchanged; implies also u
216 #   s           result is stitched, debrebase-last exists and is unchanged
217 #   S           result is stitch just made, remaining letters apply to result~
218 #
219 #   P           result is add-patches, remaining letters apply to result~
220 #
221 # should normally specify one or both of these:
222 #   l           result is laundered, tree is same as before minus d/patches
223 #   t           tree is exactly same as before
224 #
225 #   f           result is ff from previous HEAD
226
227 t-ok