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