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