Blame


1 0ebf8283 2019-07-24 stsp #!/bin/sh
2 0ebf8283 2019-07-24 stsp #
3 0ebf8283 2019-07-24 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 0ebf8283 2019-07-24 stsp #
5 0ebf8283 2019-07-24 stsp # Permission to use, copy, modify, and distribute this software for any
6 0ebf8283 2019-07-24 stsp # purpose with or without fee is hereby granted, provided that the above
7 0ebf8283 2019-07-24 stsp # copyright notice and this permission notice appear in all copies.
8 0ebf8283 2019-07-24 stsp #
9 0ebf8283 2019-07-24 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 0ebf8283 2019-07-24 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 0ebf8283 2019-07-24 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 0ebf8283 2019-07-24 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 0ebf8283 2019-07-24 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 0ebf8283 2019-07-24 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 0ebf8283 2019-07-24 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 0ebf8283 2019-07-24 stsp
17 0ebf8283 2019-07-24 stsp . ./common.sh
18 0ebf8283 2019-07-24 stsp
19 0ebf8283 2019-07-24 stsp function test_histedit_no_op {
20 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_no_op`
21 0ebf8283 2019-07-24 stsp
22 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
23 0ebf8283 2019-07-24 stsp
24 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
25 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
26 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
27 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
28 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
29 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
30 0ebf8283 2019-07-24 stsp
31 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
32 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
33 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
34 0ebf8283 2019-07-24 stsp
35 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
36 0ebf8283 2019-07-24 stsp ret="$?"
37 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
38 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
39 0ebf8283 2019-07-24 stsp return 1
40 0ebf8283 2019-07-24 stsp fi
41 0ebf8283 2019-07-24 stsp
42 0ebf8283 2019-07-24 stsp echo "pick $old_commit1" > $testroot/histedit-script
43 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" >> $testroot/histedit-script
44 0ebf8283 2019-07-24 stsp
45 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
46 0ebf8283 2019-07-24 stsp > $testroot/stdout)
47 0ebf8283 2019-07-24 stsp
48 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_parent_commit $testroot/repo`
49 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
50 0ebf8283 2019-07-24 stsp
51 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
52 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
53 0ebf8283 2019-07-24 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
54 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
55 0ebf8283 2019-07-24 stsp
56 0ebf8283 2019-07-24 stsp echo "G alpha" > $testroot/stdout.expected
57 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
58 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
59 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
60 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
61 0ebf8283 2019-07-24 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
62 0ebf8283 2019-07-24 stsp echo -n "$short_old_commit2 -> $short_new_commit2: " \
63 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
64 0ebf8283 2019-07-24 stsp echo "committing to zeta on master" >> $testroot/stdout.expected
65 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
66 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
67 0ebf8283 2019-07-24 stsp
68 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
69 0ebf8283 2019-07-24 stsp ret="$?"
70 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
71 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
72 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
73 0ebf8283 2019-07-24 stsp return 1
74 0ebf8283 2019-07-24 stsp fi
75 0ebf8283 2019-07-24 stsp
76 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/content.expected
77 0ebf8283 2019-07-24 stsp cat $testroot/wt/alpha > $testroot/content
78 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
79 0ebf8283 2019-07-24 stsp ret="$?"
80 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
81 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
82 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
83 0ebf8283 2019-07-24 stsp return 1
84 0ebf8283 2019-07-24 stsp fi
85 0ebf8283 2019-07-24 stsp
86 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/beta ]; then
87 0ebf8283 2019-07-24 stsp echo "removed file beta still exists on disk" >&2
88 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
89 0ebf8283 2019-07-24 stsp return 1
90 0ebf8283 2019-07-24 stsp fi
91 0ebf8283 2019-07-24 stsp
92 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/content.expected
93 0ebf8283 2019-07-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
94 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
95 0ebf8283 2019-07-24 stsp ret="$?"
96 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
97 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
98 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
99 0ebf8283 2019-07-24 stsp return 1
100 0ebf8283 2019-07-24 stsp fi
101 0ebf8283 2019-07-24 stsp
102 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
103 0ebf8283 2019-07-24 stsp
104 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
105 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
106 0ebf8283 2019-07-24 stsp ret="$?"
107 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
108 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
109 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
110 0ebf8283 2019-07-24 stsp return 1
111 0ebf8283 2019-07-24 stsp fi
112 0ebf8283 2019-07-24 stsp
113 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
114 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
115 0ebf8283 2019-07-24 stsp echo "commit $new_commit1" >> $testroot/stdout.expected
116 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
117 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
118 0ebf8283 2019-07-24 stsp ret="$?"
119 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
120 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
121 0ebf8283 2019-07-24 stsp fi
122 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
123 0ebf8283 2019-07-24 stsp }
124 0ebf8283 2019-07-24 stsp
125 0ebf8283 2019-07-24 stsp function test_histedit_swap {
126 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_swap`
127 0ebf8283 2019-07-24 stsp
128 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
129 0ebf8283 2019-07-24 stsp
130 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
131 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
132 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
133 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
134 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
135 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
136 0ebf8283 2019-07-24 stsp
137 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
138 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
139 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
140 0ebf8283 2019-07-24 stsp
141 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
142 0ebf8283 2019-07-24 stsp ret="$?"
143 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
144 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
145 0ebf8283 2019-07-24 stsp return 1
146 0ebf8283 2019-07-24 stsp fi
147 0ebf8283 2019-07-24 stsp
148 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" > $testroot/histedit-script
149 0ebf8283 2019-07-24 stsp echo "pick $old_commit1" >> $testroot/histedit-script
150 0ebf8283 2019-07-24 stsp
151 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
152 0ebf8283 2019-07-24 stsp > $testroot/stdout)
153 0ebf8283 2019-07-24 stsp
154 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_parent_commit $testroot/repo`
155 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_head $testroot/repo`
156 0ebf8283 2019-07-24 stsp
157 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
158 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
159 0ebf8283 2019-07-24 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
160 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
161 0ebf8283 2019-07-24 stsp
162 0ebf8283 2019-07-24 stsp echo "G epsilon/zeta" > $testroot/stdout.expected
163 0ebf8283 2019-07-24 stsp echo -n "$short_old_commit2 -> $short_new_commit2: " \
164 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
165 0ebf8283 2019-07-24 stsp echo "committing to zeta on master" >> $testroot/stdout.expected
166 0ebf8283 2019-07-24 stsp echo "G alpha" >> $testroot/stdout.expected
167 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
168 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
169 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
170 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
171 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
172 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
173 0ebf8283 2019-07-24 stsp
174 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
175 0ebf8283 2019-07-24 stsp ret="$?"
176 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
177 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
178 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
179 0ebf8283 2019-07-24 stsp return 1
180 0ebf8283 2019-07-24 stsp fi
181 0ebf8283 2019-07-24 stsp
182 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/content.expected
183 0ebf8283 2019-07-24 stsp cat $testroot/wt/alpha > $testroot/content
184 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
185 0ebf8283 2019-07-24 stsp ret="$?"
186 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
187 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
188 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
189 0ebf8283 2019-07-24 stsp return 1
190 0ebf8283 2019-07-24 stsp fi
191 0ebf8283 2019-07-24 stsp
192 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/beta ]; then
193 0ebf8283 2019-07-24 stsp echo "removed file beta still exists on disk" >&2
194 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
195 0ebf8283 2019-07-24 stsp return 1
196 0ebf8283 2019-07-24 stsp fi
197 0ebf8283 2019-07-24 stsp
198 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/content.expected
199 0ebf8283 2019-07-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
200 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
201 0ebf8283 2019-07-24 stsp ret="$?"
202 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
203 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
204 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
205 0ebf8283 2019-07-24 stsp return 1
206 0ebf8283 2019-07-24 stsp fi
207 0ebf8283 2019-07-24 stsp
208 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
209 0ebf8283 2019-07-24 stsp
210 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
211 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
212 0ebf8283 2019-07-24 stsp ret="$?"
213 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
214 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
215 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
216 0ebf8283 2019-07-24 stsp return 1
217 0ebf8283 2019-07-24 stsp fi
218 0ebf8283 2019-07-24 stsp
219 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
220 0ebf8283 2019-07-24 stsp echo "commit $new_commit1 (master)" > $testroot/stdout.expected
221 0ebf8283 2019-07-24 stsp echo "commit $new_commit2" >> $testroot/stdout.expected
222 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
223 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
224 0ebf8283 2019-07-24 stsp ret="$?"
225 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
226 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
227 0ebf8283 2019-07-24 stsp fi
228 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
229 0ebf8283 2019-07-24 stsp }
230 0ebf8283 2019-07-24 stsp
231 0ebf8283 2019-07-24 stsp function test_histedit_drop {
232 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_drop`
233 0ebf8283 2019-07-24 stsp
234 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
235 0ebf8283 2019-07-24 stsp
236 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
237 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
238 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
239 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
240 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
241 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
242 0ebf8283 2019-07-24 stsp
243 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
244 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
245 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
246 0ebf8283 2019-07-24 stsp
247 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
248 0ebf8283 2019-07-24 stsp ret="$?"
249 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
250 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
251 0ebf8283 2019-07-24 stsp return 1
252 0ebf8283 2019-07-24 stsp fi
253 0ebf8283 2019-07-24 stsp
254 0ebf8283 2019-07-24 stsp echo "drop $old_commit1" > $testroot/histedit-script
255 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" >> $testroot/histedit-script
256 0ebf8283 2019-07-24 stsp
257 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
258 0ebf8283 2019-07-24 stsp > $testroot/stdout)
259 0ebf8283 2019-07-24 stsp
260 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_parent_commit $testroot/repo`
261 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
262 0ebf8283 2019-07-24 stsp
263 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
264 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
265 0ebf8283 2019-07-24 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
266 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
267 0ebf8283 2019-07-24 stsp
268 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> drop commit: committing changes" \
269 0ebf8283 2019-07-24 stsp > $testroot/stdout.expected
270 0ebf8283 2019-07-24 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
271 0ebf8283 2019-07-24 stsp echo -n "$short_old_commit2 -> $short_new_commit2: " \
272 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
273 0ebf8283 2019-07-24 stsp echo "committing to zeta on master" >> $testroot/stdout.expected
274 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
275 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
276 0ebf8283 2019-07-24 stsp
277 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
278 0ebf8283 2019-07-24 stsp ret="$?"
279 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
280 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
281 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
282 0ebf8283 2019-07-24 stsp return 1
283 0ebf8283 2019-07-24 stsp fi
284 0ebf8283 2019-07-24 stsp
285 0ebf8283 2019-07-24 stsp for f in alpha beta; do
286 0ebf8283 2019-07-24 stsp echo "$f" > $testroot/content.expected
287 0ebf8283 2019-07-24 stsp cat $testroot/wt/$f > $testroot/content
288 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
289 0ebf8283 2019-07-24 stsp ret="$?"
290 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
291 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
292 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
293 0ebf8283 2019-07-24 stsp return 1
294 0ebf8283 2019-07-24 stsp fi
295 0ebf8283 2019-07-24 stsp done
296 0ebf8283 2019-07-24 stsp
297 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/new ]; then
298 0ebf8283 2019-07-24 stsp echo "file new exists on disk but should not" >&2
299 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
300 0ebf8283 2019-07-24 stsp return 1
301 0ebf8283 2019-07-24 stsp fi
302 0ebf8283 2019-07-24 stsp
303 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
304 0ebf8283 2019-07-24 stsp
305 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
306 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
307 0ebf8283 2019-07-24 stsp ret="$?"
308 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
309 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
310 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
311 0ebf8283 2019-07-24 stsp return 1
312 0ebf8283 2019-07-24 stsp fi
313 0ebf8283 2019-07-24 stsp
314 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
315 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
316 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
317 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
318 0ebf8283 2019-07-24 stsp ret="$?"
319 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
320 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
321 0ebf8283 2019-07-24 stsp fi
322 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
323 0ebf8283 2019-07-24 stsp }
324 0ebf8283 2019-07-24 stsp
325 0ebf8283 2019-07-24 stsp function test_histedit_fold {
326 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_fold`
327 0ebf8283 2019-07-24 stsp
328 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
329 0ebf8283 2019-07-24 stsp
330 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
331 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
332 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
333 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
334 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
335 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
336 0ebf8283 2019-07-24 stsp
337 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
338 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
339 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
340 0ebf8283 2019-07-24 stsp
341 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
342 0ebf8283 2019-07-24 stsp ret="$?"
343 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
344 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
345 0ebf8283 2019-07-24 stsp return 1
346 0ebf8283 2019-07-24 stsp fi
347 0ebf8283 2019-07-24 stsp
348 0ebf8283 2019-07-24 stsp echo "fold $old_commit1" > $testroot/histedit-script
349 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" >> $testroot/histedit-script
350 0ebf8283 2019-07-24 stsp echo "mesg committing folded changes" >> $testroot/histedit-script
351 0ebf8283 2019-07-24 stsp
352 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
353 0ebf8283 2019-07-24 stsp > $testroot/stdout)
354 0ebf8283 2019-07-24 stsp
355 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_parent_commit $testroot/repo`
356 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
357 0ebf8283 2019-07-24 stsp
358 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
359 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
360 0ebf8283 2019-07-24 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
361 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
362 0ebf8283 2019-07-24 stsp
363 0ebf8283 2019-07-24 stsp echo "G alpha" > $testroot/stdout.expected
364 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
365 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
366 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> fold commit: committing changes" \
367 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
368 0ebf8283 2019-07-24 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
369 0ebf8283 2019-07-24 stsp echo -n "$short_old_commit2 -> $short_new_commit2: " \
370 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
371 0ebf8283 2019-07-24 stsp echo "committing folded changes" >> $testroot/stdout.expected
372 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
373 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
374 0ebf8283 2019-07-24 stsp
375 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
376 0ebf8283 2019-07-24 stsp ret="$?"
377 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
378 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
379 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
380 0ebf8283 2019-07-24 stsp return 1
381 0ebf8283 2019-07-24 stsp fi
382 0ebf8283 2019-07-24 stsp
383 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/content.expected
384 0ebf8283 2019-07-24 stsp cat $testroot/wt/alpha > $testroot/content
385 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
386 0ebf8283 2019-07-24 stsp ret="$?"
387 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
388 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
389 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
390 0ebf8283 2019-07-24 stsp return 1
391 0ebf8283 2019-07-24 stsp fi
392 0ebf8283 2019-07-24 stsp
393 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/beta ]; then
394 0ebf8283 2019-07-24 stsp echo "removed file beta still exists on disk" >&2
395 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
396 0ebf8283 2019-07-24 stsp return 1
397 0ebf8283 2019-07-24 stsp fi
398 0ebf8283 2019-07-24 stsp
399 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/content.expected
400 0ebf8283 2019-07-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
401 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
402 0ebf8283 2019-07-24 stsp ret="$?"
403 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
404 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
405 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
406 0ebf8283 2019-07-24 stsp return 1
407 0ebf8283 2019-07-24 stsp fi
408 0ebf8283 2019-07-24 stsp
409 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
410 0ebf8283 2019-07-24 stsp
411 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
412 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
413 0ebf8283 2019-07-24 stsp ret="$?"
414 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
415 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
416 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
417 0ebf8283 2019-07-24 stsp return 1
418 0ebf8283 2019-07-24 stsp fi
419 0ebf8283 2019-07-24 stsp
420 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
421 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
422 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
423 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
424 0ebf8283 2019-07-24 stsp ret="$?"
425 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
426 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
427 0ebf8283 2019-07-24 stsp fi
428 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
429 0ebf8283 2019-07-24 stsp }
430 0ebf8283 2019-07-24 stsp
431 0ebf8283 2019-07-24 stsp function test_histedit_edit {
432 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_edit`
433 0ebf8283 2019-07-24 stsp
434 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
435 0ebf8283 2019-07-24 stsp
436 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
437 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
438 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
439 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
440 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
441 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
442 0ebf8283 2019-07-24 stsp
443 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
444 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
445 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
446 0ebf8283 2019-07-24 stsp
447 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
448 0ebf8283 2019-07-24 stsp ret="$?"
449 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
450 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
451 0ebf8283 2019-07-24 stsp return 1
452 0ebf8283 2019-07-24 stsp fi
453 0ebf8283 2019-07-24 stsp
454 0ebf8283 2019-07-24 stsp echo "edit $old_commit1" > $testroot/histedit-script
455 0ebf8283 2019-07-24 stsp echo "mesg committing changes" >> $testroot/histedit-script
456 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" >> $testroot/histedit-script
457 0ebf8283 2019-07-24 stsp
458 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
459 0ebf8283 2019-07-24 stsp > $testroot/stdout)
460 0ebf8283 2019-07-24 stsp
461 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
462 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
463 0ebf8283 2019-07-24 stsp
464 0ebf8283 2019-07-24 stsp echo "G alpha" > $testroot/stdout.expected
465 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
466 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
467 0ebf8283 2019-07-24 stsp echo "Stopping histedit for amending commit $old_commit1" \
468 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
469 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
470 0ebf8283 2019-07-24 stsp ret="$?"
471 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
472 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
473 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
474 0ebf8283 2019-07-24 stsp return 1
475 0ebf8283 2019-07-24 stsp fi
476 0ebf8283 2019-07-24 stsp
477 0ebf8283 2019-07-24 stsp echo "edited modified alpha on master" > $testroot/wt/alpha
478 0ebf8283 2019-07-24 stsp
479 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -c > $testroot/stdout)
480 0ebf8283 2019-07-24 stsp
481 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_parent_commit $testroot/repo`
482 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
483 0ebf8283 2019-07-24 stsp
484 0ebf8283 2019-07-24 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
485 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
486 0ebf8283 2019-07-24 stsp
487 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
488 0ebf8283 2019-07-24 stsp > $testroot/stdout.expected
489 0ebf8283 2019-07-24 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
490 0ebf8283 2019-07-24 stsp echo -n "$short_old_commit2 -> $short_new_commit2: " \
491 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
492 0ebf8283 2019-07-24 stsp echo "committing to zeta on master" >> $testroot/stdout.expected
493 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
494 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
495 0ebf8283 2019-07-24 stsp
496 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
497 0ebf8283 2019-07-24 stsp ret="$?"
498 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
499 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
500 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
501 0ebf8283 2019-07-24 stsp return 1
502 0ebf8283 2019-07-24 stsp fi
503 0ebf8283 2019-07-24 stsp
504 0ebf8283 2019-07-24 stsp echo "edited modified alpha on master" > $testroot/content.expected
505 0ebf8283 2019-07-24 stsp cat $testroot/wt/alpha > $testroot/content
506 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
507 0ebf8283 2019-07-24 stsp ret="$?"
508 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
509 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
510 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
511 0ebf8283 2019-07-24 stsp return 1
512 0ebf8283 2019-07-24 stsp fi
513 0ebf8283 2019-07-24 stsp
514 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/beta ]; then
515 0ebf8283 2019-07-24 stsp echo "removed file beta still exists on disk" >&2
516 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
517 0ebf8283 2019-07-24 stsp return 1
518 0ebf8283 2019-07-24 stsp fi
519 0ebf8283 2019-07-24 stsp
520 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/content.expected
521 0ebf8283 2019-07-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
522 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
523 0ebf8283 2019-07-24 stsp ret="$?"
524 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
525 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
526 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
527 0ebf8283 2019-07-24 stsp return 1
528 0ebf8283 2019-07-24 stsp fi
529 0ebf8283 2019-07-24 stsp
530 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
531 0ebf8283 2019-07-24 stsp
532 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
533 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
534 0ebf8283 2019-07-24 stsp ret="$?"
535 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
536 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
537 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
538 0ebf8283 2019-07-24 stsp return 1
539 0ebf8283 2019-07-24 stsp fi
540 0ebf8283 2019-07-24 stsp
541 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
542 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
543 0ebf8283 2019-07-24 stsp echo "commit $new_commit1" >> $testroot/stdout.expected
544 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
545 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
546 0ebf8283 2019-07-24 stsp ret="$?"
547 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
548 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
549 0ebf8283 2019-07-24 stsp fi
550 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
551 0ebf8283 2019-07-24 stsp }
552 0ebf8283 2019-07-24 stsp
553 0ebf8283 2019-07-24 stsp function test_histedit_fold_last_commit {
554 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_fold_last_commit`
555 0ebf8283 2019-07-24 stsp
556 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
557 0ebf8283 2019-07-24 stsp
558 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
559 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
560 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
561 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
562 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
563 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
564 0ebf8283 2019-07-24 stsp
565 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
566 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
567 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
568 0ebf8283 2019-07-24 stsp
569 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
570 0ebf8283 2019-07-24 stsp ret="$?"
571 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
572 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
573 0ebf8283 2019-07-24 stsp return 1
574 0ebf8283 2019-07-24 stsp fi
575 0ebf8283 2019-07-24 stsp
576 0ebf8283 2019-07-24 stsp echo "pick $old_commit1" > $testroot/histedit-script
577 0ebf8283 2019-07-24 stsp echo "fold $old_commit2" >> $testroot/histedit-script
578 0ebf8283 2019-07-24 stsp echo "mesg committing folded changes" >> $testroot/histedit-script
579 0ebf8283 2019-07-24 stsp
580 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
581 0ebf8283 2019-07-24 stsp > $testroot/stdout 2> $testroot/stderr)
582 0ebf8283 2019-07-24 stsp
583 0ebf8283 2019-07-24 stsp ret="$?"
584 0ebf8283 2019-07-24 stsp if [ "$ret" == "0" ]; then
585 0ebf8283 2019-07-24 stsp echo "histedit succeeded unexpectedly" >&2
586 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
587 0ebf8283 2019-07-24 stsp return 1
588 0ebf8283 2019-07-24 stsp fi
589 0ebf8283 2019-07-24 stsp
590 0ebf8283 2019-07-24 stsp echo "got: last commit in histedit script cannot be folded" \
591 0ebf8283 2019-07-24 stsp > $testroot/stderr.expected
592 0ebf8283 2019-07-24 stsp
593 0ebf8283 2019-07-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
594 0ebf8283 2019-07-24 stsp ret="$?"
595 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
596 0ebf8283 2019-07-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
597 0ebf8283 2019-07-24 stsp fi
598 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
599 0ebf8283 2019-07-24 stsp }
600 0ebf8283 2019-07-24 stsp
601 0ebf8283 2019-07-24 stsp function test_histedit_missing_commit {
602 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_missing_commit`
603 0ebf8283 2019-07-24 stsp
604 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
605 0ebf8283 2019-07-24 stsp
606 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
607 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
608 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
609 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
610 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
611 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
612 0ebf8283 2019-07-24 stsp
613 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
614 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
615 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
616 0ebf8283 2019-07-24 stsp
617 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
618 0ebf8283 2019-07-24 stsp ret="$?"
619 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
620 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
621 0ebf8283 2019-07-24 stsp return 1
622 0ebf8283 2019-07-24 stsp fi
623 0ebf8283 2019-07-24 stsp
624 0ebf8283 2019-07-24 stsp echo "pick $old_commit1" > $testroot/histedit-script
625 0ebf8283 2019-07-24 stsp echo "mesg committing changes" >> $testroot/histedit-script
626 0ebf8283 2019-07-24 stsp
627 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
628 0ebf8283 2019-07-24 stsp > $testroot/stdout 2> $testroot/stderr)
629 0ebf8283 2019-07-24 stsp
630 0ebf8283 2019-07-24 stsp ret="$?"
631 0ebf8283 2019-07-24 stsp if [ "$ret" == "0" ]; then
632 0ebf8283 2019-07-24 stsp echo "histedit succeeded unexpectedly" >&2
633 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
634 0ebf8283 2019-07-24 stsp return 1
635 0ebf8283 2019-07-24 stsp fi
636 0ebf8283 2019-07-24 stsp
637 0ebf8283 2019-07-24 stsp echo "got: commit $old_commit2 missing from histedit script" \
638 0ebf8283 2019-07-24 stsp > $testroot/stderr.expected
639 0ebf8283 2019-07-24 stsp
640 0ebf8283 2019-07-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
641 0ebf8283 2019-07-24 stsp ret="$?"
642 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
643 0ebf8283 2019-07-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
644 0ebf8283 2019-07-24 stsp fi
645 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
646 0ebf8283 2019-07-24 stsp }
647 0ebf8283 2019-07-24 stsp
648 0ebf8283 2019-07-24 stsp function test_histedit_abort {
649 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_abort`
650 0ebf8283 2019-07-24 stsp
651 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
652 0ebf8283 2019-07-24 stsp
653 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
654 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
655 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
656 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
657 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
658 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
659 0ebf8283 2019-07-24 stsp
660 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
661 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
662 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
663 0ebf8283 2019-07-24 stsp
664 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
665 0ebf8283 2019-07-24 stsp ret="$?"
666 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
667 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
668 0ebf8283 2019-07-24 stsp return 1
669 0ebf8283 2019-07-24 stsp fi
670 0ebf8283 2019-07-24 stsp
671 0ebf8283 2019-07-24 stsp echo "edit $old_commit1" > $testroot/histedit-script
672 0ebf8283 2019-07-24 stsp echo "mesg committing changes" >> $testroot/histedit-script
673 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" >> $testroot/histedit-script
674 0ebf8283 2019-07-24 stsp
675 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
676 0ebf8283 2019-07-24 stsp > $testroot/stdout)
677 0ebf8283 2019-07-24 stsp
678 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
679 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
680 0ebf8283 2019-07-24 stsp
681 0ebf8283 2019-07-24 stsp echo "G alpha" > $testroot/stdout.expected
682 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
683 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
684 0ebf8283 2019-07-24 stsp echo "Stopping histedit for amending commit $old_commit1" \
685 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
686 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
687 0ebf8283 2019-07-24 stsp ret="$?"
688 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
689 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
690 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
691 0ebf8283 2019-07-24 stsp return 1
692 0ebf8283 2019-07-24 stsp fi
693 0ebf8283 2019-07-24 stsp
694 0ebf8283 2019-07-24 stsp echo "edited modified alpha on master" > $testroot/wt/alpha
695 0ebf8283 2019-07-24 stsp
696 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -a > $testroot/stdout)
697 0ebf8283 2019-07-24 stsp
698 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_parent_commit $testroot/repo`
699 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
700 0ebf8283 2019-07-24 stsp
701 0ebf8283 2019-07-24 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
702 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
703 0ebf8283 2019-07-24 stsp
704 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
705 0ebf8283 2019-07-24 stsp > $testroot/stdout.expected
706 0ebf8283 2019-07-24 stsp echo "R alpha" >> $testroot/stdout.expected
707 0ebf8283 2019-07-24 stsp echo "R beta" >> $testroot/stdout.expected
708 0ebf8283 2019-07-24 stsp echo "R epsilon/new" >> $testroot/stdout.expected
709 0ebf8283 2019-07-24 stsp echo "Histedit of refs/heads/master aborted" \
710 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
711 0ebf8283 2019-07-24 stsp
712 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
713 0ebf8283 2019-07-24 stsp ret="$?"
714 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
715 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
716 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
717 0ebf8283 2019-07-24 stsp return 1
718 0ebf8283 2019-07-24 stsp fi
719 0ebf8283 2019-07-24 stsp
720 0ebf8283 2019-07-24 stsp for f in alpha beta; do
721 0ebf8283 2019-07-24 stsp echo "$f" > $testroot/content.expected
722 0ebf8283 2019-07-24 stsp cat $testroot/wt/$f > $testroot/content
723 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
724 0ebf8283 2019-07-24 stsp ret="$?"
725 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
726 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
727 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
728 0ebf8283 2019-07-24 stsp return 1
729 0ebf8283 2019-07-24 stsp fi
730 0ebf8283 2019-07-24 stsp done
731 0ebf8283 2019-07-24 stsp
732 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/content.expected
733 0ebf8283 2019-07-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
734 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
735 0ebf8283 2019-07-24 stsp ret="$?"
736 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
737 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
738 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
739 0ebf8283 2019-07-24 stsp return 1
740 0ebf8283 2019-07-24 stsp fi
741 0ebf8283 2019-07-24 stsp
742 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
743 0ebf8283 2019-07-24 stsp
744 0ebf8283 2019-07-24 stsp echo "? epsilon/new" > $testroot/stdout.expected
745 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
746 0ebf8283 2019-07-24 stsp ret="$?"
747 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
748 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
749 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
750 0ebf8283 2019-07-24 stsp return 1
751 0ebf8283 2019-07-24 stsp fi
752 0ebf8283 2019-07-24 stsp
753 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
754 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
755 0ebf8283 2019-07-24 stsp echo "commit $new_commit1" >> $testroot/stdout.expected
756 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
757 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
758 0ebf8283 2019-07-24 stsp ret="$?"
759 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
760 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
761 0ebf8283 2019-07-24 stsp fi
762 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
763 0ebf8283 2019-07-24 stsp }
764 0ebf8283 2019-07-24 stsp
765 0ebf8283 2019-07-24 stsp run_test test_histedit_no_op
766 0ebf8283 2019-07-24 stsp run_test test_histedit_swap
767 0ebf8283 2019-07-24 stsp run_test test_histedit_drop
768 0ebf8283 2019-07-24 stsp run_test test_histedit_fold
769 0ebf8283 2019-07-24 stsp run_test test_histedit_edit
770 0ebf8283 2019-07-24 stsp run_test test_histedit_fold_last_commit
771 0ebf8283 2019-07-24 stsp run_test test_histedit_missing_commit
772 0ebf8283 2019-07-24 stsp run_test test_histedit_abort