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