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