chiark / gitweb /
123a0d9f5f20a997559977a43b5380ed17bd5657
[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                 N*)
73                         t-expect-fail E:. \
74                         t-git-debrebase $xopts $subcmd
75                         t-git-debrebase $xopts --noop-ok $subcmd
76                         ;;
77                 [EF]:*)
78                         t-expect-fail "$checkletters" \
79                         t-git-debrebase $xopts $subcmd
80                         continue
81                         ;;
82                 *)
83                         t-git-debrebase $xopts $subcmd
84                         ;;
85                 esac
86
87                 peel=peel-$subcmd-$startbranch
88                 git checkout -b $peel
89                 t-clean-on-branch $peel
90
91                 : "---------- $subcmd $startbranch $checkletters ----------"
92
93                 while [ "x$checkletters" != x ]; do
94                         : "---- $subcmd $startbranch ...$checkletters ----"
95                         make_check "$checkletters"
96                         checkletters="${checkletters#?}"
97                 done
98         done
99
100 }
101
102 next_checkletter () {
103         checkletters="${checkletters#?}"
104 }
105
106 make_check () {
107         case "$1" in
108         [Nn]*)
109                 t-refs-same-start
110                 t-refs-same refs/heads/$before refs/heads/$work
111                 ;;
112         U*)
113                 t-refs-same-start
114                 t-refs-same refs/heads/$before refs/ffq-prev/heads/$work
115                 make_check u
116                 ;;
117         u*)
118                 t-git-get-ref refs/ffq-prev/heads/$work
119                 t-refs-notexist refs/debrebase-last/heads/$work
120                 ;;
121         V*)
122                 t-refs-same-start
123                 t-refs-same refs/ffq-prev/heads/$work \
124                         refs/ffq-prev/heads/$startbranch
125                 t-refs-notexist refs/debrebase-last/heads/$work
126                 ;;
127         s*)
128                 t-refs-notexist refs/ffq-prev/heads/$work
129                 t-refs-same-start
130                 t-refs-same refs/debrebase-last/heads/$work \
131                         refs/debrebase-last/heads/$startbranch
132                 t-has-ancestor HEAD refs/debrebase-last/heads/$work
133                 ;;
134         S*)
135                 t-refs-notexist refs/ffq-prev/heads/$work
136                 t-refs-same-start refs/debrebase-last/heads/$work
137                 t-ref-head
138                 git diff --quiet HEAD^1
139                 git diff HEAD^2 | grep $startbranch
140                 git reset --hard HEAD^1
141                 ;;
142         P*)
143                 t-dgit -wgf --quilt=nofix quilt-fixup
144                 git diff HEAD~ debian/patches | egrep .
145                 git diff --quiet HEAD~ -- ':.' ':!debian/patches'
146                 git reset --hard HEAD~
147                 ;;
148         l*)
149                 git diff --quiet HEAD refs/heads/$before -- ':.' ':!debian/patches'
150                 t-gdr-good laundered
151                 ;;
152         t*)
153                 git diff --quiet HEAD refs/heads/$before
154                 ;;
155         f*)
156                 t-has-ancestor HEAD refs/heads/$before
157                 ;;
158         *)
159                 fail "$1"
160                 ;;
161         esac
162 }
163
164 Ec="F:No ongoing git-debrebase session"
165 Ep="F:Patch export produced patch amendments"
166
167 # input state:
168 #  stitched?            st'd    st'd    unst'd  unst'd
169 #  laundered?           laund'd mixed   laund'd mixed
170 #
171 # "mixed" means an out of order branch
172 # containing mixed commits and patch additions,
173 # but which needs even more patches
174 #
175 subcmd  ''              Ult     Ull     Vlt     Vl
176 subcmd  stitch          Ns      Nu      Sltf    Stf
177 subcmd  prepush         Ns      Nu      Sltf    Stf
178 subcmd  quick           ns      Sl      Sltf    Sl
179 subcmd  conclude        "$Ec"   "$Ec"   Sltf    Sl
180 subcmd  make-patches    sPft    "$Ep"   uPft    "$Ep"
181 #subcmd dgit-upload-hook Psft   "$Ep"   SPft    "$Ep"
182 #
183 # result codes, each one is a check:
184 #   E:$pat      } this is an error (must come first)
185 #   F:$pat      } arg is passed to expect-fail
186 #
187 #   XX          crash out of script for manual debugging
188 #
189 #   N           this is a noop, error unless --noop-ok
190 #   n           this is a silent noop
191 # both of these imply tf; but, specify also one of   u s
192 #
193 # should normally specify one of these:
194 #   U           just unstiched: ffq-prev is exactly previous HEAD; implies u
195 #   u           result is unstitched
196 #   V           ffq-prev remains unchanged; implies also u
197 #   s           result is stitched, debrebase-last exists and is unchanged
198 #   S           result is stitch just made, remaining letters apply to result~
199 #
200 #   P           result is add-patches, remaining letters apply to result~
201 #
202 # should normally specify one or both of these:
203 #   l           result is laundered, tree is same as before minus d/patches
204 #   t           tree is exactly same as before
205 #
206 #   f           result is ff from previous HEAD
207
208 t-ok