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