chiark / gitweb /
changelog: start 7.1~
[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                 t-gdr-made-patches
172                 git diff --quiet HEAD~ -- ':.' ':!debian/patches'
173                 git reset --hard HEAD~
174                 ;;
175         l*)
176                 git diff --quiet HEAD refs/heads/$before -- ':.' ':!debian/patches'
177                 t-gdr-good laundered
178                 ;;
179         A*)
180                 t-refs-notexist \
181                         refs/ffq-prev/heads/$work \
182                         refs/debrebase-last/heads/$work
183                 ;;
184         t*)
185                 git diff --quiet HEAD refs/heads/$before
186                 ;;
187         f*)
188                 t-has-ancestor HEAD refs/heads/$before
189                 ;;
190         Z*)
191                 t-refs-same-start
192                 t-refs-same refs/heads/$peel
193                 t-refs-same refs/heads/before-unstitch/$startbranch
194                 t-ref-head
195                 ;;
196         *)
197                 fail "$1"
198                 ;;
199         esac
200 }
201
202 Ec="F:No ongoing git-debrebase session"
203 Ep="F:Patch export produced patch amendments"
204
205 # input state:
206 #  stitched?            st'd    st'd    unst'd  unst'd  convert
207 #  laundered?           laund'd mixed   laund'd mixed   -from-gbp
208 #
209 # "mixed" means an out of order branch
210 # containing mixed commits and patch additions,
211 # but which needs even more patches
212 #
213 subcmd  ''              Ult     Ull     Vlt     Vl      nU
214 subcmd  stitch          Ns      Nu      Sltf    Stf     Ns
215 subcmd  prepush         ns      nu      Sltf    Stf     ns
216 subcmd  quick           ns      Sl      Sltf    Sl      n
217 subcmd  conclude        "$Ec"   "$Ec"   Sltf    Sl      N
218 subcmd  scrap           Ns      Ns      Z       Z       N
219 subcmd  make-patches    sPft    "$Ep"   uPft    "$Ep"   Pn
220 subcmd  forget-was-ever-debrebase nA nA nA      nA      nA
221 #
222 # result codes, each one is a check:
223 #   E:$pat      } this is an error (must come first)
224 #   F:$pat      } arg is passed to expect-fail
225 #
226 #   X           should fail due to snags, but succeed when forced
227 #   XX          crash out of script for manual debugging
228 #
229 #   N           this is a noop, error unless --noop-ok
230 #   n           this is a silent noop
231 # both of these imply tf; but, specify also one of   u s
232 #
233 # should normally specify one of these:
234 #   U           just unstiched: ffq-prev is exactly previous HEAD; implies u
235 #   u           result is unstitched
236 #   V           ffq-prev remains unchanged; implies also u
237 #   s           result is stitched, debrebase-last exists and is unchanged
238 #   S           result is stitch just made, remaining letters apply to result~
239 #   Z           result is rewind to before changes made
240 #   A           no ffq-prev or debrebase-last refs ("Amnesia")
241 #
242 #   P           result is add-patches, remaining letters apply to result~
243 #
244 # should normally specify one or both of these:
245 #   l           result is laundered, tree is same as before minus d/patches
246 #   t           tree is exactly same as before
247 #
248 #   f           result is ff from previous HEAD
249
250 t-ok