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 86ac67ee 2019-07-25 stsp got diff -r $testroot/repo $orig_commit $old_commit2 \
36 86ac67ee 2019-07-25 stsp > $testroot/diff.expected
37 86ac67ee 2019-07-25 stsp
38 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
39 0ebf8283 2019-07-24 stsp ret="$?"
40 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
41 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
42 0ebf8283 2019-07-24 stsp return 1
43 0ebf8283 2019-07-24 stsp fi
44 0ebf8283 2019-07-24 stsp
45 0ebf8283 2019-07-24 stsp echo "pick $old_commit1" > $testroot/histedit-script
46 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" >> $testroot/histedit-script
47 0ebf8283 2019-07-24 stsp
48 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
49 0ebf8283 2019-07-24 stsp > $testroot/stdout)
50 0ebf8283 2019-07-24 stsp
51 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_parent_commit $testroot/repo`
52 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
53 0ebf8283 2019-07-24 stsp
54 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
55 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
56 0ebf8283 2019-07-24 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
57 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
58 0ebf8283 2019-07-24 stsp
59 0ebf8283 2019-07-24 stsp echo "G alpha" > $testroot/stdout.expected
60 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
61 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
62 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
63 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
64 0ebf8283 2019-07-24 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
65 0ebf8283 2019-07-24 stsp echo -n "$short_old_commit2 -> $short_new_commit2: " \
66 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
67 0ebf8283 2019-07-24 stsp echo "committing to zeta on master" >> $testroot/stdout.expected
68 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
69 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
70 0ebf8283 2019-07-24 stsp
71 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
72 0ebf8283 2019-07-24 stsp ret="$?"
73 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
74 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
75 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
76 0ebf8283 2019-07-24 stsp return 1
77 0ebf8283 2019-07-24 stsp fi
78 0ebf8283 2019-07-24 stsp
79 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/content.expected
80 0ebf8283 2019-07-24 stsp cat $testroot/wt/alpha > $testroot/content
81 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
82 0ebf8283 2019-07-24 stsp ret="$?"
83 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
84 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
85 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
86 0ebf8283 2019-07-24 stsp return 1
87 0ebf8283 2019-07-24 stsp fi
88 0ebf8283 2019-07-24 stsp
89 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/beta ]; then
90 0ebf8283 2019-07-24 stsp echo "removed file beta still exists on disk" >&2
91 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
92 0ebf8283 2019-07-24 stsp return 1
93 0ebf8283 2019-07-24 stsp fi
94 0ebf8283 2019-07-24 stsp
95 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/content.expected
96 0ebf8283 2019-07-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
97 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
98 0ebf8283 2019-07-24 stsp ret="$?"
99 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
100 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
101 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
102 0ebf8283 2019-07-24 stsp return 1
103 0ebf8283 2019-07-24 stsp fi
104 0ebf8283 2019-07-24 stsp
105 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
106 0ebf8283 2019-07-24 stsp
107 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
108 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
109 0ebf8283 2019-07-24 stsp ret="$?"
110 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
111 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
112 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
113 0ebf8283 2019-07-24 stsp return 1
114 0ebf8283 2019-07-24 stsp fi
115 0ebf8283 2019-07-24 stsp
116 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
117 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
118 0ebf8283 2019-07-24 stsp echo "commit $new_commit1" >> $testroot/stdout.expected
119 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
120 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
121 0ebf8283 2019-07-24 stsp ret="$?"
122 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
123 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
124 86ac67ee 2019-07-25 stsp test_done "$testroot" "$ret"
125 86ac67ee 2019-07-25 stsp return 1
126 0ebf8283 2019-07-24 stsp fi
127 86ac67ee 2019-07-25 stsp
128 86ac67ee 2019-07-25 stsp got diff -r $testroot/repo $orig_commit $new_commit2 \
129 86ac67ee 2019-07-25 stsp > $testroot/diff
130 86ac67ee 2019-07-25 stsp sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
131 86ac67ee 2019-07-25 stsp cmp -s $testroot/diff.expected $testroot/diff
132 86ac67ee 2019-07-25 stsp ret="$?"
133 86ac67ee 2019-07-25 stsp if [ "$ret" != "0" ]; then
134 86ac67ee 2019-07-25 stsp diff -u $testroot/diff.expected $testroot/diff
135 86ac67ee 2019-07-25 stsp fi
136 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
137 0ebf8283 2019-07-24 stsp }
138 0ebf8283 2019-07-24 stsp
139 0ebf8283 2019-07-24 stsp function test_histedit_swap {
140 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_swap`
141 0ebf8283 2019-07-24 stsp
142 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
143 0ebf8283 2019-07-24 stsp
144 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
145 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
146 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
147 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
148 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
149 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
150 0ebf8283 2019-07-24 stsp
151 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
152 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
153 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
154 0ebf8283 2019-07-24 stsp
155 86ac67ee 2019-07-25 stsp got diff -r $testroot/repo $orig_commit $old_commit2 \
156 86ac67ee 2019-07-25 stsp > $testroot/diff.expected
157 86ac67ee 2019-07-25 stsp
158 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
159 0ebf8283 2019-07-24 stsp ret="$?"
160 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
161 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
162 0ebf8283 2019-07-24 stsp return 1
163 0ebf8283 2019-07-24 stsp fi
164 0ebf8283 2019-07-24 stsp
165 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" > $testroot/histedit-script
166 0ebf8283 2019-07-24 stsp echo "pick $old_commit1" >> $testroot/histedit-script
167 0ebf8283 2019-07-24 stsp
168 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
169 0ebf8283 2019-07-24 stsp > $testroot/stdout)
170 0ebf8283 2019-07-24 stsp
171 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_parent_commit $testroot/repo`
172 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_head $testroot/repo`
173 0ebf8283 2019-07-24 stsp
174 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
175 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
176 0ebf8283 2019-07-24 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
177 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
178 0ebf8283 2019-07-24 stsp
179 0ebf8283 2019-07-24 stsp echo "G epsilon/zeta" > $testroot/stdout.expected
180 0ebf8283 2019-07-24 stsp echo -n "$short_old_commit2 -> $short_new_commit2: " \
181 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
182 0ebf8283 2019-07-24 stsp echo "committing to zeta on master" >> $testroot/stdout.expected
183 0ebf8283 2019-07-24 stsp echo "G alpha" >> $testroot/stdout.expected
184 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
185 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
186 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
187 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
188 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
189 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
190 0ebf8283 2019-07-24 stsp
191 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
192 0ebf8283 2019-07-24 stsp ret="$?"
193 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
194 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
195 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
196 0ebf8283 2019-07-24 stsp return 1
197 0ebf8283 2019-07-24 stsp fi
198 0ebf8283 2019-07-24 stsp
199 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/content.expected
200 0ebf8283 2019-07-24 stsp cat $testroot/wt/alpha > $testroot/content
201 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
202 0ebf8283 2019-07-24 stsp ret="$?"
203 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
204 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
205 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
206 0ebf8283 2019-07-24 stsp return 1
207 0ebf8283 2019-07-24 stsp fi
208 0ebf8283 2019-07-24 stsp
209 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/beta ]; then
210 0ebf8283 2019-07-24 stsp echo "removed file beta still exists on disk" >&2
211 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
212 0ebf8283 2019-07-24 stsp return 1
213 0ebf8283 2019-07-24 stsp fi
214 0ebf8283 2019-07-24 stsp
215 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/content.expected
216 0ebf8283 2019-07-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
217 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
218 0ebf8283 2019-07-24 stsp ret="$?"
219 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
220 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
221 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
222 0ebf8283 2019-07-24 stsp return 1
223 0ebf8283 2019-07-24 stsp fi
224 0ebf8283 2019-07-24 stsp
225 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
226 0ebf8283 2019-07-24 stsp
227 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
228 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
229 0ebf8283 2019-07-24 stsp ret="$?"
230 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
231 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
232 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
233 0ebf8283 2019-07-24 stsp return 1
234 0ebf8283 2019-07-24 stsp fi
235 0ebf8283 2019-07-24 stsp
236 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
237 0ebf8283 2019-07-24 stsp echo "commit $new_commit1 (master)" > $testroot/stdout.expected
238 0ebf8283 2019-07-24 stsp echo "commit $new_commit2" >> $testroot/stdout.expected
239 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
240 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
241 0ebf8283 2019-07-24 stsp ret="$?"
242 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
243 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
244 86ac67ee 2019-07-25 stsp test_done "$testroot" "$ret"
245 86ac67ee 2019-07-25 stsp return 1
246 86ac67ee 2019-07-25 stsp fi
247 86ac67ee 2019-07-25 stsp
248 86ac67ee 2019-07-25 stsp got diff -r $testroot/repo $orig_commit $new_commit1 \
249 86ac67ee 2019-07-25 stsp > $testroot/diff
250 86ac67ee 2019-07-25 stsp sed -i -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected
251 86ac67ee 2019-07-25 stsp cmp -s $testroot/diff.expected $testroot/diff
252 86ac67ee 2019-07-25 stsp ret="$?"
253 86ac67ee 2019-07-25 stsp if [ "$ret" != "0" ]; then
254 86ac67ee 2019-07-25 stsp diff -u $testroot/diff.expected $testroot/diff
255 0ebf8283 2019-07-24 stsp fi
256 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
257 0ebf8283 2019-07-24 stsp }
258 0ebf8283 2019-07-24 stsp
259 0ebf8283 2019-07-24 stsp function test_histedit_drop {
260 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_drop`
261 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
262 0ebf8283 2019-07-24 stsp
263 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
264 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
265 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
266 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
267 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
268 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
269 0ebf8283 2019-07-24 stsp
270 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
271 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
272 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
273 0ebf8283 2019-07-24 stsp
274 86ac67ee 2019-07-25 stsp got diff -r $testroot/repo $old_commit1 $old_commit2 \
275 86ac67ee 2019-07-25 stsp > $testroot/diff.expected
276 86ac67ee 2019-07-25 stsp
277 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
278 0ebf8283 2019-07-24 stsp ret="$?"
279 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
280 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
281 0ebf8283 2019-07-24 stsp return 1
282 0ebf8283 2019-07-24 stsp fi
283 0ebf8283 2019-07-24 stsp
284 0ebf8283 2019-07-24 stsp echo "drop $old_commit1" > $testroot/histedit-script
285 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" >> $testroot/histedit-script
286 0ebf8283 2019-07-24 stsp
287 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
288 0ebf8283 2019-07-24 stsp > $testroot/stdout)
289 0ebf8283 2019-07-24 stsp
290 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
291 0ebf8283 2019-07-24 stsp
292 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
293 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
294 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
295 0ebf8283 2019-07-24 stsp
296 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> drop commit: committing changes" \
297 0ebf8283 2019-07-24 stsp > $testroot/stdout.expected
298 0ebf8283 2019-07-24 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
299 0ebf8283 2019-07-24 stsp echo -n "$short_old_commit2 -> $short_new_commit2: " \
300 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
301 0ebf8283 2019-07-24 stsp echo "committing to zeta on master" >> $testroot/stdout.expected
302 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
303 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
304 0ebf8283 2019-07-24 stsp
305 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
306 0ebf8283 2019-07-24 stsp ret="$?"
307 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
308 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
309 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
310 0ebf8283 2019-07-24 stsp return 1
311 0ebf8283 2019-07-24 stsp fi
312 0ebf8283 2019-07-24 stsp
313 0ebf8283 2019-07-24 stsp for f in alpha beta; do
314 0ebf8283 2019-07-24 stsp echo "$f" > $testroot/content.expected
315 0ebf8283 2019-07-24 stsp cat $testroot/wt/$f > $testroot/content
316 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
317 0ebf8283 2019-07-24 stsp ret="$?"
318 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
319 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
320 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
321 0ebf8283 2019-07-24 stsp return 1
322 0ebf8283 2019-07-24 stsp fi
323 0ebf8283 2019-07-24 stsp done
324 0ebf8283 2019-07-24 stsp
325 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/new ]; then
326 0ebf8283 2019-07-24 stsp echo "file new exists on disk but should not" >&2
327 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
328 0ebf8283 2019-07-24 stsp return 1
329 0ebf8283 2019-07-24 stsp fi
330 0ebf8283 2019-07-24 stsp
331 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
332 0ebf8283 2019-07-24 stsp
333 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
334 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
335 0ebf8283 2019-07-24 stsp ret="$?"
336 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
337 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
338 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
339 0ebf8283 2019-07-24 stsp return 1
340 0ebf8283 2019-07-24 stsp fi
341 0ebf8283 2019-07-24 stsp
342 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
343 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
344 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
345 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
346 0ebf8283 2019-07-24 stsp ret="$?"
347 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
348 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
349 86ac67ee 2019-07-25 stsp test_done "$testroot" "$ret"
350 86ac67ee 2019-07-25 stsp return 1
351 86ac67ee 2019-07-25 stsp fi
352 86ac67ee 2019-07-25 stsp
353 86ac67ee 2019-07-25 stsp got diff -r $testroot/repo $orig_commit $new_commit2 \
354 86ac67ee 2019-07-25 stsp > $testroot/diff
355 86ac67ee 2019-07-25 stsp sed -i -e "s/$old_commit1/$orig_commit/" $testroot/diff.expected
356 86ac67ee 2019-07-25 stsp sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
357 86ac67ee 2019-07-25 stsp cmp -s $testroot/diff.expected $testroot/diff
358 86ac67ee 2019-07-25 stsp ret="$?"
359 86ac67ee 2019-07-25 stsp if [ "$ret" != "0" ]; then
360 86ac67ee 2019-07-25 stsp diff -u $testroot/diff.expected $testroot/diff
361 0ebf8283 2019-07-24 stsp fi
362 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
363 0ebf8283 2019-07-24 stsp }
364 0ebf8283 2019-07-24 stsp
365 0ebf8283 2019-07-24 stsp function test_histedit_fold {
366 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_fold`
367 0ebf8283 2019-07-24 stsp
368 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
369 0ebf8283 2019-07-24 stsp
370 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
371 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
372 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
373 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
374 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
375 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
376 0ebf8283 2019-07-24 stsp
377 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
378 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
379 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
380 3f9de99f 2019-07-24 stsp
381 3f9de99f 2019-07-24 stsp echo "modified delta on master" > $testroot/repo/gamma/delta
382 3f9de99f 2019-07-24 stsp git_commit $testroot/repo -m "committing to delta on master"
383 3f9de99f 2019-07-24 stsp local old_commit3=`git_show_head $testroot/repo`
384 0ebf8283 2019-07-24 stsp
385 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
386 0ebf8283 2019-07-24 stsp ret="$?"
387 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
388 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
389 0ebf8283 2019-07-24 stsp return 1
390 0ebf8283 2019-07-24 stsp fi
391 0ebf8283 2019-07-24 stsp
392 0ebf8283 2019-07-24 stsp echo "fold $old_commit1" > $testroot/histedit-script
393 3f9de99f 2019-07-24 stsp echo "drop $old_commit2" >> $testroot/histedit-script
394 3f9de99f 2019-07-24 stsp echo "pick $old_commit3" >> $testroot/histedit-script
395 0ebf8283 2019-07-24 stsp echo "mesg committing folded changes" >> $testroot/histedit-script
396 0ebf8283 2019-07-24 stsp
397 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
398 0ebf8283 2019-07-24 stsp > $testroot/stdout)
399 0ebf8283 2019-07-24 stsp
400 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_parent_commit $testroot/repo`
401 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
402 0ebf8283 2019-07-24 stsp
403 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
404 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
405 3f9de99f 2019-07-24 stsp local short_old_commit3=`trim_obj_id 28 $old_commit3`
406 0ebf8283 2019-07-24 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
407 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
408 0ebf8283 2019-07-24 stsp
409 0ebf8283 2019-07-24 stsp echo "G alpha" > $testroot/stdout.expected
410 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
411 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
412 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> fold commit: committing changes" \
413 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
414 3f9de99f 2019-07-24 stsp echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
415 3f9de99f 2019-07-24 stsp echo "drop commit: committing to zeta on master" \
416 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
417 3f9de99f 2019-07-24 stsp echo "G gamma/delta" >> $testroot/stdout.expected
418 3f9de99f 2019-07-24 stsp echo -n "$short_old_commit3 -> $short_new_commit2: " \
419 3f9de99f 2019-07-24 stsp >> $testroot/stdout.expected
420 0ebf8283 2019-07-24 stsp echo "committing folded changes" >> $testroot/stdout.expected
421 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
422 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
423 0ebf8283 2019-07-24 stsp
424 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
425 0ebf8283 2019-07-24 stsp ret="$?"
426 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
427 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
428 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
429 0ebf8283 2019-07-24 stsp return 1
430 0ebf8283 2019-07-24 stsp fi
431 0ebf8283 2019-07-24 stsp
432 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/content.expected
433 0ebf8283 2019-07-24 stsp cat $testroot/wt/alpha > $testroot/content
434 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
435 0ebf8283 2019-07-24 stsp ret="$?"
436 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
437 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
438 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
439 0ebf8283 2019-07-24 stsp return 1
440 0ebf8283 2019-07-24 stsp fi
441 0ebf8283 2019-07-24 stsp
442 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/beta ]; then
443 0ebf8283 2019-07-24 stsp echo "removed file beta still exists on disk" >&2
444 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
445 0ebf8283 2019-07-24 stsp return 1
446 0ebf8283 2019-07-24 stsp fi
447 0ebf8283 2019-07-24 stsp
448 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/content.expected
449 0ebf8283 2019-07-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
450 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
451 0ebf8283 2019-07-24 stsp ret="$?"
452 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
453 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
454 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
455 0ebf8283 2019-07-24 stsp return 1
456 0ebf8283 2019-07-24 stsp fi
457 0ebf8283 2019-07-24 stsp
458 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
459 0ebf8283 2019-07-24 stsp
460 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
461 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
462 0ebf8283 2019-07-24 stsp ret="$?"
463 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
464 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
465 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
466 0ebf8283 2019-07-24 stsp return 1
467 0ebf8283 2019-07-24 stsp fi
468 0ebf8283 2019-07-24 stsp
469 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
470 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
471 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
472 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
473 0ebf8283 2019-07-24 stsp ret="$?"
474 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
475 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
476 0ebf8283 2019-07-24 stsp fi
477 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
478 0ebf8283 2019-07-24 stsp }
479 0ebf8283 2019-07-24 stsp
480 0ebf8283 2019-07-24 stsp function test_histedit_edit {
481 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_edit`
482 0ebf8283 2019-07-24 stsp
483 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
484 0ebf8283 2019-07-24 stsp
485 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
486 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
487 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
488 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
489 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
490 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
491 0ebf8283 2019-07-24 stsp
492 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
493 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
494 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
495 0ebf8283 2019-07-24 stsp
496 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
497 0ebf8283 2019-07-24 stsp ret="$?"
498 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
499 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
500 0ebf8283 2019-07-24 stsp return 1
501 0ebf8283 2019-07-24 stsp fi
502 0ebf8283 2019-07-24 stsp
503 0ebf8283 2019-07-24 stsp echo "edit $old_commit1" > $testroot/histedit-script
504 0ebf8283 2019-07-24 stsp echo "mesg committing changes" >> $testroot/histedit-script
505 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" >> $testroot/histedit-script
506 0ebf8283 2019-07-24 stsp
507 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
508 0ebf8283 2019-07-24 stsp > $testroot/stdout)
509 0ebf8283 2019-07-24 stsp
510 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
511 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
512 0ebf8283 2019-07-24 stsp
513 0ebf8283 2019-07-24 stsp echo "G alpha" > $testroot/stdout.expected
514 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
515 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
516 0ebf8283 2019-07-24 stsp echo "Stopping histedit for amending commit $old_commit1" \
517 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
518 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
519 0ebf8283 2019-07-24 stsp ret="$?"
520 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
521 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
522 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
523 0ebf8283 2019-07-24 stsp return 1
524 0ebf8283 2019-07-24 stsp fi
525 0ebf8283 2019-07-24 stsp
526 0ebf8283 2019-07-24 stsp echo "edited modified alpha on master" > $testroot/wt/alpha
527 0ebf8283 2019-07-24 stsp
528 f032f1f7 2019-08-04 stsp # test interaction of 'got stage' and histedit -c
529 f032f1f7 2019-08-04 stsp (cd $testroot/wt && got stage alpha > /dev/null)
530 f032f1f7 2019-08-04 stsp (cd $testroot/wt && got histedit -c > $testroot/stdout \
531 f032f1f7 2019-08-04 stsp 2> $testroot/stderr)
532 f032f1f7 2019-08-04 stsp ret="$?"
533 f032f1f7 2019-08-04 stsp if [ "$ret" == "0" ]; then
534 f032f1f7 2019-08-04 stsp echo "histedit succeeded unexpectedly" >&2
535 f032f1f7 2019-08-04 stsp test_done "$testroot" "1"
536 f032f1f7 2019-08-04 stsp return 1
537 f032f1f7 2019-08-04 stsp fi
538 f032f1f7 2019-08-04 stsp echo -n "got: work tree contains files with staged changes; " \
539 f032f1f7 2019-08-04 stsp > $testroot/stderr.expected
540 f032f1f7 2019-08-04 stsp echo "these changes must be committed or unstaged first" \
541 f032f1f7 2019-08-04 stsp >> $testroot/stderr.expected
542 f032f1f7 2019-08-04 stsp cmp -s $testroot/stderr.expected $testroot/stderr
543 f032f1f7 2019-08-04 stsp ret="$?"
544 f032f1f7 2019-08-04 stsp if [ "$ret" != "0" ]; then
545 f032f1f7 2019-08-04 stsp diff -u $testroot/stderr.expected $testroot/stderr
546 f032f1f7 2019-08-04 stsp test_done "$testroot" "$ret"
547 f032f1f7 2019-08-04 stsp return 1
548 f032f1f7 2019-08-04 stsp fi
549 f032f1f7 2019-08-04 stsp
550 f032f1f7 2019-08-04 stsp (cd $testroot/wt && got unstage alpha > /dev/null)
551 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -c > $testroot/stdout)
552 0ebf8283 2019-07-24 stsp
553 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_parent_commit $testroot/repo`
554 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
555 0ebf8283 2019-07-24 stsp
556 0ebf8283 2019-07-24 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
557 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
558 0ebf8283 2019-07-24 stsp
559 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
560 0ebf8283 2019-07-24 stsp > $testroot/stdout.expected
561 0ebf8283 2019-07-24 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
562 0ebf8283 2019-07-24 stsp echo -n "$short_old_commit2 -> $short_new_commit2: " \
563 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
564 0ebf8283 2019-07-24 stsp echo "committing to zeta on master" >> $testroot/stdout.expected
565 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
566 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
567 0ebf8283 2019-07-24 stsp
568 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
569 0ebf8283 2019-07-24 stsp ret="$?"
570 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
571 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
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 "edited modified alpha on master" > $testroot/content.expected
577 0ebf8283 2019-07-24 stsp cat $testroot/wt/alpha > $testroot/content
578 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
579 0ebf8283 2019-07-24 stsp ret="$?"
580 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
581 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
582 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
583 0ebf8283 2019-07-24 stsp return 1
584 0ebf8283 2019-07-24 stsp fi
585 0ebf8283 2019-07-24 stsp
586 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/beta ]; then
587 0ebf8283 2019-07-24 stsp echo "removed file beta still exists on disk" >&2
588 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
589 0ebf8283 2019-07-24 stsp return 1
590 0ebf8283 2019-07-24 stsp fi
591 0ebf8283 2019-07-24 stsp
592 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/content.expected
593 0ebf8283 2019-07-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
594 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
595 0ebf8283 2019-07-24 stsp ret="$?"
596 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
597 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
598 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
599 0ebf8283 2019-07-24 stsp return 1
600 0ebf8283 2019-07-24 stsp fi
601 0ebf8283 2019-07-24 stsp
602 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
603 0ebf8283 2019-07-24 stsp
604 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
605 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
606 0ebf8283 2019-07-24 stsp ret="$?"
607 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
608 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
609 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
610 0ebf8283 2019-07-24 stsp return 1
611 0ebf8283 2019-07-24 stsp fi
612 0ebf8283 2019-07-24 stsp
613 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
614 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
615 0ebf8283 2019-07-24 stsp echo "commit $new_commit1" >> $testroot/stdout.expected
616 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
617 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
618 0ebf8283 2019-07-24 stsp ret="$?"
619 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
620 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
621 0ebf8283 2019-07-24 stsp fi
622 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
623 0ebf8283 2019-07-24 stsp }
624 0ebf8283 2019-07-24 stsp
625 0ebf8283 2019-07-24 stsp function test_histedit_fold_last_commit {
626 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_fold_last_commit`
627 0ebf8283 2019-07-24 stsp
628 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
629 0ebf8283 2019-07-24 stsp
630 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
631 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
632 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
633 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
634 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
635 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
636 0ebf8283 2019-07-24 stsp
637 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
638 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
639 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
640 0ebf8283 2019-07-24 stsp
641 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
642 0ebf8283 2019-07-24 stsp ret="$?"
643 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
644 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
645 0ebf8283 2019-07-24 stsp return 1
646 0ebf8283 2019-07-24 stsp fi
647 0ebf8283 2019-07-24 stsp
648 0ebf8283 2019-07-24 stsp echo "pick $old_commit1" > $testroot/histedit-script
649 0ebf8283 2019-07-24 stsp echo "fold $old_commit2" >> $testroot/histedit-script
650 0ebf8283 2019-07-24 stsp echo "mesg committing folded changes" >> $testroot/histedit-script
651 0ebf8283 2019-07-24 stsp
652 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
653 0ebf8283 2019-07-24 stsp > $testroot/stdout 2> $testroot/stderr)
654 0ebf8283 2019-07-24 stsp
655 0ebf8283 2019-07-24 stsp ret="$?"
656 0ebf8283 2019-07-24 stsp if [ "$ret" == "0" ]; then
657 0ebf8283 2019-07-24 stsp echo "histedit succeeded unexpectedly" >&2
658 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
659 0ebf8283 2019-07-24 stsp return 1
660 0ebf8283 2019-07-24 stsp fi
661 0ebf8283 2019-07-24 stsp
662 0ebf8283 2019-07-24 stsp echo "got: last commit in histedit script cannot be folded" \
663 0ebf8283 2019-07-24 stsp > $testroot/stderr.expected
664 0ebf8283 2019-07-24 stsp
665 0ebf8283 2019-07-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
666 0ebf8283 2019-07-24 stsp ret="$?"
667 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
668 0ebf8283 2019-07-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
669 0ebf8283 2019-07-24 stsp fi
670 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
671 0ebf8283 2019-07-24 stsp }
672 0ebf8283 2019-07-24 stsp
673 0ebf8283 2019-07-24 stsp function test_histedit_missing_commit {
674 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_missing_commit`
675 0ebf8283 2019-07-24 stsp
676 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
677 0ebf8283 2019-07-24 stsp
678 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
679 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
680 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
681 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
682 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
683 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
684 0ebf8283 2019-07-24 stsp
685 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
686 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
687 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
688 0ebf8283 2019-07-24 stsp
689 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
690 0ebf8283 2019-07-24 stsp ret="$?"
691 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
692 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
693 0ebf8283 2019-07-24 stsp return 1
694 0ebf8283 2019-07-24 stsp fi
695 0ebf8283 2019-07-24 stsp
696 0ebf8283 2019-07-24 stsp echo "pick $old_commit1" > $testroot/histedit-script
697 0ebf8283 2019-07-24 stsp echo "mesg committing changes" >> $testroot/histedit-script
698 0ebf8283 2019-07-24 stsp
699 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
700 0ebf8283 2019-07-24 stsp > $testroot/stdout 2> $testroot/stderr)
701 0ebf8283 2019-07-24 stsp
702 0ebf8283 2019-07-24 stsp ret="$?"
703 0ebf8283 2019-07-24 stsp if [ "$ret" == "0" ]; then
704 0ebf8283 2019-07-24 stsp echo "histedit succeeded unexpectedly" >&2
705 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
706 0ebf8283 2019-07-24 stsp return 1
707 0ebf8283 2019-07-24 stsp fi
708 0ebf8283 2019-07-24 stsp
709 0ebf8283 2019-07-24 stsp echo "got: commit $old_commit2 missing from histedit script" \
710 0ebf8283 2019-07-24 stsp > $testroot/stderr.expected
711 0ebf8283 2019-07-24 stsp
712 0ebf8283 2019-07-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
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/stderr.expected $testroot/stderr
716 0ebf8283 2019-07-24 stsp fi
717 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
718 0ebf8283 2019-07-24 stsp }
719 0ebf8283 2019-07-24 stsp
720 0ebf8283 2019-07-24 stsp function test_histedit_abort {
721 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_abort`
722 0ebf8283 2019-07-24 stsp
723 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
724 0ebf8283 2019-07-24 stsp
725 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
726 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git rm -q beta)
727 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
728 0ebf8283 2019-07-24 stsp (cd $testroot/repo && git add epsilon/new)
729 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
730 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
731 0ebf8283 2019-07-24 stsp
732 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
733 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
734 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
735 0ebf8283 2019-07-24 stsp
736 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
737 0ebf8283 2019-07-24 stsp ret="$?"
738 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
739 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
740 0ebf8283 2019-07-24 stsp return 1
741 0ebf8283 2019-07-24 stsp fi
742 0ebf8283 2019-07-24 stsp
743 0ebf8283 2019-07-24 stsp echo "edit $old_commit1" > $testroot/histedit-script
744 0ebf8283 2019-07-24 stsp echo "mesg committing changes" >> $testroot/histedit-script
745 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" >> $testroot/histedit-script
746 0ebf8283 2019-07-24 stsp
747 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
748 0ebf8283 2019-07-24 stsp > $testroot/stdout)
749 0ebf8283 2019-07-24 stsp
750 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
751 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
752 0ebf8283 2019-07-24 stsp
753 0ebf8283 2019-07-24 stsp echo "G alpha" > $testroot/stdout.expected
754 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
755 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
756 0ebf8283 2019-07-24 stsp echo "Stopping histedit for amending commit $old_commit1" \
757 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
758 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
759 0ebf8283 2019-07-24 stsp ret="$?"
760 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
761 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
762 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
763 0ebf8283 2019-07-24 stsp return 1
764 0ebf8283 2019-07-24 stsp fi
765 0ebf8283 2019-07-24 stsp
766 0ebf8283 2019-07-24 stsp echo "edited modified alpha on master" > $testroot/wt/alpha
767 0ebf8283 2019-07-24 stsp
768 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -a > $testroot/stdout)
769 0ebf8283 2019-07-24 stsp
770 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_parent_commit $testroot/repo`
771 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
772 0ebf8283 2019-07-24 stsp
773 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
774 0ebf8283 2019-07-24 stsp > $testroot/stdout.expected
775 0ebf8283 2019-07-24 stsp echo "R alpha" >> $testroot/stdout.expected
776 0ebf8283 2019-07-24 stsp echo "R beta" >> $testroot/stdout.expected
777 0ebf8283 2019-07-24 stsp echo "R epsilon/new" >> $testroot/stdout.expected
778 0ebf8283 2019-07-24 stsp echo "Histedit of refs/heads/master aborted" \
779 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
780 0ebf8283 2019-07-24 stsp
781 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
782 0ebf8283 2019-07-24 stsp ret="$?"
783 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
784 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
785 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
786 0ebf8283 2019-07-24 stsp return 1
787 0ebf8283 2019-07-24 stsp fi
788 0ebf8283 2019-07-24 stsp
789 0ebf8283 2019-07-24 stsp for f in alpha beta; do
790 0ebf8283 2019-07-24 stsp echo "$f" > $testroot/content.expected
791 0ebf8283 2019-07-24 stsp cat $testroot/wt/$f > $testroot/content
792 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
793 0ebf8283 2019-07-24 stsp ret="$?"
794 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
795 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
796 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
797 0ebf8283 2019-07-24 stsp return 1
798 0ebf8283 2019-07-24 stsp fi
799 0ebf8283 2019-07-24 stsp done
800 0ebf8283 2019-07-24 stsp
801 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/content.expected
802 0ebf8283 2019-07-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
803 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
804 0ebf8283 2019-07-24 stsp ret="$?"
805 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
806 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
807 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
808 0ebf8283 2019-07-24 stsp return 1
809 0ebf8283 2019-07-24 stsp fi
810 0ebf8283 2019-07-24 stsp
811 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
812 0ebf8283 2019-07-24 stsp
813 0ebf8283 2019-07-24 stsp echo "? epsilon/new" > $testroot/stdout.expected
814 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
815 0ebf8283 2019-07-24 stsp ret="$?"
816 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
817 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
818 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
819 0ebf8283 2019-07-24 stsp return 1
820 0ebf8283 2019-07-24 stsp fi
821 0ebf8283 2019-07-24 stsp
822 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
823 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
824 0ebf8283 2019-07-24 stsp echo "commit $new_commit1" >> $testroot/stdout.expected
825 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
826 0160a755 2019-07-25 stsp cmp -s $testroot/stdout.expected $testroot/stdout
827 0160a755 2019-07-25 stsp ret="$?"
828 0160a755 2019-07-25 stsp if [ "$ret" != "0" ]; then
829 0160a755 2019-07-25 stsp diff -u $testroot/stdout.expected $testroot/stdout
830 0160a755 2019-07-25 stsp fi
831 0160a755 2019-07-25 stsp test_done "$testroot" "$ret"
832 0160a755 2019-07-25 stsp }
833 0160a755 2019-07-25 stsp
834 a4027091 2019-07-25 stsp function test_histedit_path_prefix_drop {
835 a4027091 2019-07-25 stsp local testroot=`test_init histedit_path_prefix_drop`
836 0160a755 2019-07-25 stsp local orig_commit=`git_show_head $testroot/repo`
837 0160a755 2019-07-25 stsp
838 0160a755 2019-07-25 stsp echo "modified zeta" > $testroot/repo/epsilon/zeta
839 0160a755 2019-07-25 stsp git_commit $testroot/repo -m "changing zeta"
840 0160a755 2019-07-25 stsp local old_commit1=`git_show_head $testroot/repo`
841 0160a755 2019-07-25 stsp
842 0160a755 2019-07-25 stsp got checkout -c $orig_commit -p gamma $testroot/repo \
843 0160a755 2019-07-25 stsp $testroot/wt > /dev/null
844 0160a755 2019-07-25 stsp ret="$?"
845 0160a755 2019-07-25 stsp if [ "$ret" != "0" ]; then
846 0160a755 2019-07-25 stsp test_done "$testroot" "$ret"
847 0160a755 2019-07-25 stsp return 1
848 0160a755 2019-07-25 stsp fi
849 0160a755 2019-07-25 stsp
850 0160a755 2019-07-25 stsp echo "drop $old_commit1" > $testroot/histedit-script
851 0160a755 2019-07-25 stsp
852 0160a755 2019-07-25 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
853 0160a755 2019-07-25 stsp > $testroot/stdout 2> $testroot/stderr)
854 0160a755 2019-07-25 stsp
855 0160a755 2019-07-25 stsp ret="$?"
856 0160a755 2019-07-25 stsp if [ "$ret" == "0" ]; then
857 0160a755 2019-07-25 stsp echo "histedit succeeded unexpectedly" >&2
858 0160a755 2019-07-25 stsp test_done "$testroot" "1"
859 0160a755 2019-07-25 stsp return 1
860 0160a755 2019-07-25 stsp fi
861 0160a755 2019-07-25 stsp
862 0160a755 2019-07-25 stsp echo -n "got: cannot edit branch history which contains changes " \
863 0160a755 2019-07-25 stsp > $testroot/stderr.expected
864 0160a755 2019-07-25 stsp echo "outside of this work tree's path prefix" \
865 0160a755 2019-07-25 stsp >> $testroot/stderr.expected
866 0160a755 2019-07-25 stsp
867 0160a755 2019-07-25 stsp cmp -s $testroot/stderr.expected $testroot/stderr
868 0160a755 2019-07-25 stsp ret="$?"
869 0160a755 2019-07-25 stsp if [ "$ret" != "0" ]; then
870 0160a755 2019-07-25 stsp diff -u $testroot/stderr.expected $testroot/stderr
871 0160a755 2019-07-25 stsp test_done "$testroot" "$ret"
872 0160a755 2019-07-25 stsp return 1
873 0160a755 2019-07-25 stsp fi
874 0160a755 2019-07-25 stsp
875 0160a755 2019-07-25 stsp rm -rf $testroot/wt
876 0160a755 2019-07-25 stsp got checkout -c $orig_commit -p epsilon $testroot/repo \
877 0160a755 2019-07-25 stsp $testroot/wt > /dev/null
878 0160a755 2019-07-25 stsp ret="$?"
879 0160a755 2019-07-25 stsp if [ "$ret" != "0" ]; then
880 0160a755 2019-07-25 stsp test_done "$testroot" "$ret"
881 0160a755 2019-07-25 stsp return 1
882 0160a755 2019-07-25 stsp fi
883 0160a755 2019-07-25 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
884 0160a755 2019-07-25 stsp > $testroot/stdout)
885 0160a755 2019-07-25 stsp
886 0160a755 2019-07-25 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
887 0160a755 2019-07-25 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
888 0160a755 2019-07-25 stsp
889 0160a755 2019-07-25 stsp echo "$short_old_commit1 -> drop commit: changing zeta" \
890 0160a755 2019-07-25 stsp > $testroot/stdout.expected
891 0160a755 2019-07-25 stsp echo "Switching work tree to refs/heads/master" \
892 0160a755 2019-07-25 stsp >> $testroot/stdout.expected
893 0160a755 2019-07-25 stsp
894 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
895 0ebf8283 2019-07-24 stsp ret="$?"
896 0ebf8283 2019-07-24 stsp if [ "$ret" != "0" ]; then
897 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
898 0160a755 2019-07-25 stsp test_done "$testroot" "$ret"
899 0160a755 2019-07-25 stsp return 1
900 0ebf8283 2019-07-24 stsp fi
901 0160a755 2019-07-25 stsp
902 0160a755 2019-07-25 stsp echo "zeta" > $testroot/content.expected
903 0160a755 2019-07-25 stsp cat $testroot/wt/zeta > $testroot/content
904 0160a755 2019-07-25 stsp cmp -s $testroot/content.expected $testroot/content
905 0160a755 2019-07-25 stsp ret="$?"
906 0160a755 2019-07-25 stsp if [ "$ret" != "0" ]; then
907 0160a755 2019-07-25 stsp diff -u $testroot/content.expected $testroot/content
908 0160a755 2019-07-25 stsp test_done "$testroot" "$ret"
909 0160a755 2019-07-25 stsp return 1
910 0160a755 2019-07-25 stsp fi
911 0160a755 2019-07-25 stsp
912 0160a755 2019-07-25 stsp
913 0160a755 2019-07-25 stsp (cd $testroot/wt && got status > $testroot/stdout)
914 0160a755 2019-07-25 stsp
915 0160a755 2019-07-25 stsp echo -n > $testroot/stdout.expected
916 0160a755 2019-07-25 stsp cmp -s $testroot/stdout.expected $testroot/stdout
917 0160a755 2019-07-25 stsp ret="$?"
918 0160a755 2019-07-25 stsp if [ "$ret" != "0" ]; then
919 0160a755 2019-07-25 stsp diff -u $testroot/stdout.expected $testroot/stdout
920 0160a755 2019-07-25 stsp test_done "$testroot" "$ret"
921 0160a755 2019-07-25 stsp return 1
922 0160a755 2019-07-25 stsp fi
923 0160a755 2019-07-25 stsp
924 0160a755 2019-07-25 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
925 0160a755 2019-07-25 stsp echo "commit $orig_commit (master)" > $testroot/stdout.expected
926 b2c50a0a 2019-07-25 stsp cmp -s $testroot/stdout.expected $testroot/stdout
927 b2c50a0a 2019-07-25 stsp ret="$?"
928 b2c50a0a 2019-07-25 stsp if [ "$ret" != "0" ]; then
929 b2c50a0a 2019-07-25 stsp diff -u $testroot/stdout.expected $testroot/stdout
930 b2c50a0a 2019-07-25 stsp fi
931 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
932 b2c50a0a 2019-07-25 stsp }
933 b2c50a0a 2019-07-25 stsp
934 b2c50a0a 2019-07-25 stsp function test_histedit_path_prefix_edit {
935 b2c50a0a 2019-07-25 stsp local testroot=`test_init histedit_path_prefix_edit`
936 b2c50a0a 2019-07-25 stsp local orig_commit=`git_show_head $testroot/repo`
937 b2c50a0a 2019-07-25 stsp
938 b2c50a0a 2019-07-25 stsp echo "modified zeta" > $testroot/repo/epsilon/zeta
939 b2c50a0a 2019-07-25 stsp git_commit $testroot/repo -m "changing zeta"
940 b2c50a0a 2019-07-25 stsp local old_commit1=`git_show_head $testroot/repo`
941 b2c50a0a 2019-07-25 stsp
942 b2c50a0a 2019-07-25 stsp got diff -r $testroot/repo $orig_commit $old_commit1 \
943 b2c50a0a 2019-07-25 stsp > $testroot/diff.expected
944 b2c50a0a 2019-07-25 stsp
945 b2c50a0a 2019-07-25 stsp got checkout -c $orig_commit -p gamma $testroot/repo \
946 b2c50a0a 2019-07-25 stsp $testroot/wt > /dev/null
947 b2c50a0a 2019-07-25 stsp ret="$?"
948 b2c50a0a 2019-07-25 stsp if [ "$ret" != "0" ]; then
949 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
950 b2c50a0a 2019-07-25 stsp return 1
951 b2c50a0a 2019-07-25 stsp fi
952 b2c50a0a 2019-07-25 stsp
953 b2c50a0a 2019-07-25 stsp echo "edit $old_commit1" > $testroot/histedit-script
954 b2c50a0a 2019-07-25 stsp echo "mesg modified zeta" >> $testroot/histedit-script
955 b2c50a0a 2019-07-25 stsp
956 b2c50a0a 2019-07-25 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
957 b2c50a0a 2019-07-25 stsp > $testroot/stdout 2> $testroot/stderr)
958 b2c50a0a 2019-07-25 stsp
959 b2c50a0a 2019-07-25 stsp ret="$?"
960 b2c50a0a 2019-07-25 stsp if [ "$ret" == "0" ]; then
961 b2c50a0a 2019-07-25 stsp echo "histedit succeeded unexpectedly" >&2
962 b2c50a0a 2019-07-25 stsp test_done "$testroot" "1"
963 b2c50a0a 2019-07-25 stsp return 1
964 b2c50a0a 2019-07-25 stsp fi
965 b2c50a0a 2019-07-25 stsp
966 b2c50a0a 2019-07-25 stsp echo -n "got: cannot edit branch history which contains changes " \
967 b2c50a0a 2019-07-25 stsp > $testroot/stderr.expected
968 b2c50a0a 2019-07-25 stsp echo "outside of this work tree's path prefix" \
969 b2c50a0a 2019-07-25 stsp >> $testroot/stderr.expected
970 b2c50a0a 2019-07-25 stsp
971 b2c50a0a 2019-07-25 stsp cmp -s $testroot/stderr.expected $testroot/stderr
972 b2c50a0a 2019-07-25 stsp ret="$?"
973 b2c50a0a 2019-07-25 stsp if [ "$ret" != "0" ]; then
974 b2c50a0a 2019-07-25 stsp diff -u $testroot/stderr.expected $testroot/stderr
975 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
976 b2c50a0a 2019-07-25 stsp return 1
977 b2c50a0a 2019-07-25 stsp fi
978 b2c50a0a 2019-07-25 stsp
979 b2c50a0a 2019-07-25 stsp rm -rf $testroot/wt
980 b2c50a0a 2019-07-25 stsp got checkout -c $orig_commit -p epsilon $testroot/repo \
981 b2c50a0a 2019-07-25 stsp $testroot/wt > /dev/null
982 b2c50a0a 2019-07-25 stsp ret="$?"
983 b2c50a0a 2019-07-25 stsp if [ "$ret" != "0" ]; then
984 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
985 b2c50a0a 2019-07-25 stsp return 1
986 b2c50a0a 2019-07-25 stsp fi
987 b2c50a0a 2019-07-25 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
988 b2c50a0a 2019-07-25 stsp > $testroot/stdout)
989 b2c50a0a 2019-07-25 stsp
990 b2c50a0a 2019-07-25 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
991 b2c50a0a 2019-07-25 stsp
992 b2c50a0a 2019-07-25 stsp echo "G zeta" > $testroot/stdout.expected
993 b2c50a0a 2019-07-25 stsp echo "Stopping histedit for amending commit $old_commit1" \
994 b2c50a0a 2019-07-25 stsp >> $testroot/stdout.expected
995 0160a755 2019-07-25 stsp cmp -s $testroot/stdout.expected $testroot/stdout
996 0160a755 2019-07-25 stsp ret="$?"
997 0160a755 2019-07-25 stsp if [ "$ret" != "0" ]; then
998 0160a755 2019-07-25 stsp diff -u $testroot/stdout.expected $testroot/stdout
999 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
1000 b2c50a0a 2019-07-25 stsp return 1
1001 0160a755 2019-07-25 stsp fi
1002 b2c50a0a 2019-07-25 stsp
1003 b2c50a0a 2019-07-25 stsp echo "modified zeta" > $testroot/content.expected
1004 b2c50a0a 2019-07-25 stsp cat $testroot/wt/zeta > $testroot/content
1005 b2c50a0a 2019-07-25 stsp cmp -s $testroot/content.expected $testroot/content
1006 b2c50a0a 2019-07-25 stsp ret="$?"
1007 b2c50a0a 2019-07-25 stsp if [ "$ret" != "0" ]; then
1008 b2c50a0a 2019-07-25 stsp diff -u $testroot/content.expected $testroot/content
1009 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
1010 b2c50a0a 2019-07-25 stsp return 1
1011 b2c50a0a 2019-07-25 stsp fi
1012 b2c50a0a 2019-07-25 stsp
1013 b2c50a0a 2019-07-25 stsp (cd $testroot/wt && got status > $testroot/stdout)
1014 b2c50a0a 2019-07-25 stsp
1015 b2c50a0a 2019-07-25 stsp echo "M zeta"> $testroot/stdout.expected
1016 b2c50a0a 2019-07-25 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1017 b2c50a0a 2019-07-25 stsp ret="$?"
1018 b2c50a0a 2019-07-25 stsp if [ "$ret" != "0" ]; then
1019 b2c50a0a 2019-07-25 stsp diff -u $testroot/stdout.expected $testroot/stdout
1020 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
1021 b2c50a0a 2019-07-25 stsp return 1
1022 b2c50a0a 2019-07-25 stsp fi
1023 b2c50a0a 2019-07-25 stsp
1024 b2c50a0a 2019-07-25 stsp (cd $testroot/wt && got histedit -c > $testroot/stdout)
1025 b2c50a0a 2019-07-25 stsp
1026 b2c50a0a 2019-07-25 stsp local new_commit1=`git_show_head $testroot/repo`
1027 b2c50a0a 2019-07-25 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
1028 b2c50a0a 2019-07-25 stsp
1029 b2c50a0a 2019-07-25 stsp echo -n "$short_old_commit1 -> $short_new_commit1: " \
1030 b2c50a0a 2019-07-25 stsp > $testroot/stdout.expected
1031 b2c50a0a 2019-07-25 stsp echo "modified zeta" >> $testroot/stdout.expected
1032 b2c50a0a 2019-07-25 stsp echo "Switching work tree to refs/heads/master" \
1033 b2c50a0a 2019-07-25 stsp >> $testroot/stdout.expected
1034 b2c50a0a 2019-07-25 stsp
1035 b2c50a0a 2019-07-25 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1036 b2c50a0a 2019-07-25 stsp ret="$?"
1037 b2c50a0a 2019-07-25 stsp if [ "$ret" != "0" ]; then
1038 b2c50a0a 2019-07-25 stsp diff -u $testroot/stdout.expected $testroot/stdout
1039 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
1040 b2c50a0a 2019-07-25 stsp return 1
1041 b2c50a0a 2019-07-25 stsp fi
1042 b2c50a0a 2019-07-25 stsp
1043 b2c50a0a 2019-07-25 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1044 b2c50a0a 2019-07-25 stsp echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1045 b2c50a0a 2019-07-25 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
1046 b2c50a0a 2019-07-25 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1047 b2c50a0a 2019-07-25 stsp ret="$?"
1048 b2c50a0a 2019-07-25 stsp if [ "$ret" != "0" ]; then
1049 b2c50a0a 2019-07-25 stsp diff -u $testroot/stdout.expected $testroot/stdout
1050 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
1051 b2c50a0a 2019-07-25 stsp return 1
1052 b2c50a0a 2019-07-25 stsp fi
1053 b2c50a0a 2019-07-25 stsp
1054 b2c50a0a 2019-07-25 stsp got diff -r $testroot/repo $orig_commit $new_commit1 \
1055 b2c50a0a 2019-07-25 stsp > $testroot/diff
1056 b2c50a0a 2019-07-25 stsp sed -i -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1057 b2c50a0a 2019-07-25 stsp cmp -s $testroot/diff.expected $testroot/diff
1058 b2c50a0a 2019-07-25 stsp ret="$?"
1059 b2c50a0a 2019-07-25 stsp if [ "$ret" != "0" ]; then
1060 b2c50a0a 2019-07-25 stsp diff -u $testroot/diff.expected $testroot/diff
1061 b2c50a0a 2019-07-25 stsp fi
1062 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
1063 0ebf8283 2019-07-24 stsp }
1064 c7d20a3f 2019-07-30 stsp
1065 c7d20a3f 2019-07-30 stsp function test_histedit_outside_refs_heads {
1066 c7d20a3f 2019-07-30 stsp local testroot=`test_init histedit_outside_refs_heads`
1067 c7d20a3f 2019-07-30 stsp local commit1=`git_show_head $testroot/repo`
1068 c7d20a3f 2019-07-30 stsp
1069 c7d20a3f 2019-07-30 stsp got checkout $testroot/repo $testroot/wt > /dev/null
1070 c7d20a3f 2019-07-30 stsp ret="$?"
1071 c7d20a3f 2019-07-30 stsp if [ "$ret" != "0" ]; then
1072 c7d20a3f 2019-07-30 stsp echo "got checkout failed unexpectedly"
1073 c7d20a3f 2019-07-30 stsp test_done "$testroot" "$ret"
1074 c7d20a3f 2019-07-30 stsp return 1
1075 c7d20a3f 2019-07-30 stsp fi
1076 c7d20a3f 2019-07-30 stsp
1077 c7d20a3f 2019-07-30 stsp echo "modified alpha" > $testroot/wt/alpha
1078 c7d20a3f 2019-07-30 stsp
1079 c7d20a3f 2019-07-30 stsp (cd $testroot/wt && got commit -m 'change alpha' \
1080 c7d20a3f 2019-07-30 stsp > $testroot/stdout 2> $testroot/stderr)
1081 c7d20a3f 2019-07-30 stsp ret="$?"
1082 c7d20a3f 2019-07-30 stsp if [ "$ret" != "0" ]; then
1083 c7d20a3f 2019-07-30 stsp echo "got commit failed unexpectedly" >&2
1084 c7d20a3f 2019-07-30 stsp test_done "$testroot" "1"
1085 c7d20a3f 2019-07-30 stsp return 1
1086 c7d20a3f 2019-07-30 stsp fi
1087 c7d20a3f 2019-07-30 stsp local commit2=`git_show_head $testroot/repo`
1088 0ebf8283 2019-07-24 stsp
1089 c7d20a3f 2019-07-30 stsp got ref -r $testroot/repo refs/remotes/origin/master master
1090 c7d20a3f 2019-07-30 stsp ret="$?"
1091 c7d20a3f 2019-07-30 stsp if [ "$ret" != "0" ]; then
1092 c7d20a3f 2019-07-30 stsp echo "got ref failed unexpectedly" >&2
1093 c7d20a3f 2019-07-30 stsp test_done "$testroot" "1"
1094 c7d20a3f 2019-07-30 stsp return 1
1095 c7d20a3f 2019-07-30 stsp fi
1096 c7d20a3f 2019-07-30 stsp
1097 c7d20a3f 2019-07-30 stsp (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1098 c7d20a3f 2019-07-30 stsp ret="$?"
1099 c7d20a3f 2019-07-30 stsp if [ "$ret" != "0" ]; then
1100 c7d20a3f 2019-07-30 stsp echo "got update failed unexpectedly"
1101 c7d20a3f 2019-07-30 stsp test_done "$testroot" "$ret"
1102 c7d20a3f 2019-07-30 stsp return 1
1103 c7d20a3f 2019-07-30 stsp fi
1104 c7d20a3f 2019-07-30 stsp
1105 c7d20a3f 2019-07-30 stsp echo "edit $commit2" > $testroot/histedit-script
1106 c7d20a3f 2019-07-30 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1107 c7d20a3f 2019-07-30 stsp 2> $testroot/stderr)
1108 c7d20a3f 2019-07-30 stsp
1109 c7d20a3f 2019-07-30 stsp echo -n "got: will not edit commit history of a branch outside the " \
1110 c7d20a3f 2019-07-30 stsp > $testroot/stderr.expected
1111 c7d20a3f 2019-07-30 stsp echo '"refs/heads/" reference namespace' \
1112 c7d20a3f 2019-07-30 stsp >> $testroot/stderr.expected
1113 c7d20a3f 2019-07-30 stsp cmp -s $testroot/stderr.expected $testroot/stderr
1114 c7d20a3f 2019-07-30 stsp ret="$?"
1115 c7d20a3f 2019-07-30 stsp if [ "$ret" != "0" ]; then
1116 c7d20a3f 2019-07-30 stsp diff -u $testroot/stderr.expected $testroot/stderr
1117 0def28b1 2019-08-17 stsp fi
1118 0def28b1 2019-08-17 stsp test_done "$testroot" "$ret"
1119 0def28b1 2019-08-17 stsp }
1120 0def28b1 2019-08-17 stsp
1121 0def28b1 2019-08-17 stsp function test_histedit_fold_last_commit_swap {
1122 0def28b1 2019-08-17 stsp local testroot=`test_init histedit_fold_last_commit_swap`
1123 0def28b1 2019-08-17 stsp
1124 0def28b1 2019-08-17 stsp local orig_commit=`git_show_head $testroot/repo`
1125 0def28b1 2019-08-17 stsp
1126 0def28b1 2019-08-17 stsp echo "modified alpha on master" > $testroot/repo/alpha
1127 0def28b1 2019-08-17 stsp (cd $testroot/repo && git rm -q beta)
1128 0def28b1 2019-08-17 stsp echo "new file on master" > $testroot/repo/epsilon/new
1129 0def28b1 2019-08-17 stsp (cd $testroot/repo && git add epsilon/new)
1130 0def28b1 2019-08-17 stsp git_commit $testroot/repo -m "committing changes"
1131 0def28b1 2019-08-17 stsp local old_commit1=`git_show_head $testroot/repo`
1132 0def28b1 2019-08-17 stsp
1133 0def28b1 2019-08-17 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1134 0def28b1 2019-08-17 stsp git_commit $testroot/repo -m "committing to zeta on master"
1135 0def28b1 2019-08-17 stsp local old_commit2=`git_show_head $testroot/repo`
1136 0def28b1 2019-08-17 stsp
1137 0def28b1 2019-08-17 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1138 0def28b1 2019-08-17 stsp ret="$?"
1139 0def28b1 2019-08-17 stsp if [ "$ret" != "0" ]; then
1140 0def28b1 2019-08-17 stsp test_done "$testroot" "$ret"
1141 0def28b1 2019-08-17 stsp return 1
1142 0def28b1 2019-08-17 stsp fi
1143 0def28b1 2019-08-17 stsp
1144 0def28b1 2019-08-17 stsp # fold commit2 into commit1 (requires swapping commits)
1145 0def28b1 2019-08-17 stsp echo "fold $old_commit2" > $testroot/histedit-script
1146 0def28b1 2019-08-17 stsp echo "pick $old_commit1" >> $testroot/histedit-script
1147 0def28b1 2019-08-17 stsp echo "mesg committing folded changes" >> $testroot/histedit-script
1148 0def28b1 2019-08-17 stsp
1149 0def28b1 2019-08-17 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1150 0def28b1 2019-08-17 stsp > $testroot/stdout 2> $testroot/stderr)
1151 0def28b1 2019-08-17 stsp
1152 0def28b1 2019-08-17 stsp ret="$?"
1153 0def28b1 2019-08-17 stsp if [ "$ret" != "0" ]; then
1154 0def28b1 2019-08-17 stsp echo "histedit failed unexpectedly" >&2
1155 0def28b1 2019-08-17 stsp test_done "$testroot" "$ret"
1156 0def28b1 2019-08-17 stsp return 1
1157 c7d20a3f 2019-07-30 stsp fi
1158 0def28b1 2019-08-17 stsp
1159 0def28b1 2019-08-17 stsp local new_commit=`git_show_head $testroot/repo`
1160 0def28b1 2019-08-17 stsp
1161 0def28b1 2019-08-17 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
1162 0def28b1 2019-08-17 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
1163 0def28b1 2019-08-17 stsp local short_new_commit=`trim_obj_id 28 $new_commit`
1164 0def28b1 2019-08-17 stsp
1165 0def28b1 2019-08-17 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
1166 0def28b1 2019-08-17 stsp echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1167 0def28b1 2019-08-17 stsp >> $testroot/stdout.expected
1168 0def28b1 2019-08-17 stsp echo "on master" >> $testroot/stdout.expected
1169 0def28b1 2019-08-17 stsp echo "G alpha" >> $testroot/stdout.expected
1170 0def28b1 2019-08-17 stsp echo "D beta" >> $testroot/stdout.expected
1171 0def28b1 2019-08-17 stsp echo "A epsilon/new" >> $testroot/stdout.expected
1172 0def28b1 2019-08-17 stsp echo -n "$short_old_commit1 -> $short_new_commit: " \
1173 0def28b1 2019-08-17 stsp >> $testroot/stdout.expected
1174 0def28b1 2019-08-17 stsp echo "committing folded changes" >> $testroot/stdout.expected
1175 0def28b1 2019-08-17 stsp echo "Switching work tree to refs/heads/master" \
1176 0def28b1 2019-08-17 stsp >> $testroot/stdout.expected
1177 0def28b1 2019-08-17 stsp
1178 0def28b1 2019-08-17 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1179 0def28b1 2019-08-17 stsp ret="$?"
1180 0def28b1 2019-08-17 stsp if [ "$ret" != "0" ]; then
1181 0def28b1 2019-08-17 stsp diff -u $testroot/stdout.expected $testroot/stdout
1182 0def28b1 2019-08-17 stsp fi
1183 c7d20a3f 2019-07-30 stsp test_done "$testroot" "$ret"
1184 c7d20a3f 2019-07-30 stsp }
1185 c7d20a3f 2019-07-30 stsp
1186 0ebf8283 2019-07-24 stsp run_test test_histedit_no_op
1187 0ebf8283 2019-07-24 stsp run_test test_histedit_swap
1188 0ebf8283 2019-07-24 stsp run_test test_histedit_drop
1189 0ebf8283 2019-07-24 stsp run_test test_histedit_fold
1190 0ebf8283 2019-07-24 stsp run_test test_histedit_edit
1191 0ebf8283 2019-07-24 stsp run_test test_histedit_fold_last_commit
1192 0ebf8283 2019-07-24 stsp run_test test_histedit_missing_commit
1193 0ebf8283 2019-07-24 stsp run_test test_histedit_abort
1194 a4027091 2019-07-25 stsp run_test test_histedit_path_prefix_drop
1195 b2c50a0a 2019-07-25 stsp run_test test_histedit_path_prefix_edit
1196 c7d20a3f 2019-07-30 stsp run_test test_histedit_outside_refs_heads
1197 0def28b1 2019-08-17 stsp run_test test_histedit_fold_last_commit_swap