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