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 f6cae3ed 2020-09-13 naddy 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 e600f124 2021-03-21 stsp local orig_author_time=`git_show_author_time $testroot/repo`
24 0ebf8283 2019-07-24 stsp
25 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
26 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
27 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
28 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
29 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
30 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
31 ad324bf5 2021-09-21 stsp local old_author_time1=`git_show_author_time $testroot/repo`
32 0ebf8283 2019-07-24 stsp
33 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
34 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
35 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
36 e600f124 2021-03-21 stsp local old_author_time2=`git_show_author_time $testroot/repo`
37 0ebf8283 2019-07-24 stsp
38 86ac67ee 2019-07-25 stsp got diff -r $testroot/repo $orig_commit $old_commit2 \
39 86ac67ee 2019-07-25 stsp > $testroot/diff.expected
40 86ac67ee 2019-07-25 stsp
41 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
42 fc414659 2022-04-16 thomas ret=$?
43 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
44 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
45 0ebf8283 2019-07-24 stsp return 1
46 0ebf8283 2019-07-24 stsp fi
47 0ebf8283 2019-07-24 stsp
48 0ebf8283 2019-07-24 stsp echo "pick $old_commit1" > $testroot/histedit-script
49 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" >> $testroot/histedit-script
50 0ebf8283 2019-07-24 stsp
51 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
52 0ebf8283 2019-07-24 stsp > $testroot/stdout)
53 0ebf8283 2019-07-24 stsp
54 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_parent_commit $testroot/repo`
55 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
56 e600f124 2021-03-21 stsp local new_author_time2=`git_show_author_time $testroot/repo`
57 0ebf8283 2019-07-24 stsp
58 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
59 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
60 0ebf8283 2019-07-24 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
61 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
62 0ebf8283 2019-07-24 stsp
63 0ebf8283 2019-07-24 stsp echo "G alpha" > $testroot/stdout.expected
64 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
65 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
66 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
67 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
68 0ebf8283 2019-07-24 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
69 0ebf8283 2019-07-24 stsp echo -n "$short_old_commit2 -> $short_new_commit2: " \
70 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
71 0ebf8283 2019-07-24 stsp echo "committing to zeta on master" >> $testroot/stdout.expected
72 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
73 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
74 0ebf8283 2019-07-24 stsp
75 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
76 fc414659 2022-04-16 thomas ret=$?
77 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
78 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
79 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
80 0ebf8283 2019-07-24 stsp return 1
81 0ebf8283 2019-07-24 stsp fi
82 0ebf8283 2019-07-24 stsp
83 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/content.expected
84 0ebf8283 2019-07-24 stsp cat $testroot/wt/alpha > $testroot/content
85 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
86 fc414659 2022-04-16 thomas ret=$?
87 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
88 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
89 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
90 0ebf8283 2019-07-24 stsp return 1
91 0ebf8283 2019-07-24 stsp fi
92 0ebf8283 2019-07-24 stsp
93 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/beta ]; then
94 0ebf8283 2019-07-24 stsp echo "removed file beta still exists on disk" >&2
95 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
96 0ebf8283 2019-07-24 stsp return 1
97 0ebf8283 2019-07-24 stsp fi
98 0ebf8283 2019-07-24 stsp
99 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/content.expected
100 0ebf8283 2019-07-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
101 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
102 fc414659 2022-04-16 thomas ret=$?
103 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
104 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
105 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
106 0ebf8283 2019-07-24 stsp return 1
107 0ebf8283 2019-07-24 stsp fi
108 0ebf8283 2019-07-24 stsp
109 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
110 0ebf8283 2019-07-24 stsp
111 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
112 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
113 fc414659 2022-04-16 thomas ret=$?
114 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
115 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
116 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
117 0ebf8283 2019-07-24 stsp return 1
118 0ebf8283 2019-07-24 stsp fi
119 0ebf8283 2019-07-24 stsp
120 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
121 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
122 0ebf8283 2019-07-24 stsp echo "commit $new_commit1" >> $testroot/stdout.expected
123 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
124 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
125 fc414659 2022-04-16 thomas ret=$?
126 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
127 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
128 86ac67ee 2019-07-25 stsp test_done "$testroot" "$ret"
129 86ac67ee 2019-07-25 stsp return 1
130 0ebf8283 2019-07-24 stsp fi
131 86ac67ee 2019-07-25 stsp
132 86ac67ee 2019-07-25 stsp got diff -r $testroot/repo $orig_commit $new_commit2 \
133 86ac67ee 2019-07-25 stsp > $testroot/diff
134 ac3cdf31 2023-03-06 thomas ed -s $testroot/diff.expected <<-EOF
135 ac3cdf31 2023-03-06 thomas ,s/$old_commit2/$new_commit2/
136 ac3cdf31 2023-03-06 thomas w
137 ac3cdf31 2023-03-06 thomas EOF
138 86ac67ee 2019-07-25 stsp cmp -s $testroot/diff.expected $testroot/diff
139 fc414659 2022-04-16 thomas ret=$?
140 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
141 86ac67ee 2019-07-25 stsp diff -u $testroot/diff.expected $testroot/diff
142 a615e0e7 2020-12-16 stsp test_done "$testroot" "$ret"
143 a615e0e7 2020-12-16 stsp return 1
144 86ac67ee 2019-07-25 stsp fi
145 a615e0e7 2020-12-16 stsp
146 a615e0e7 2020-12-16 stsp (cd $testroot/wt && got update > $testroot/stdout)
147 a615e0e7 2020-12-16 stsp
148 a615e0e7 2020-12-16 stsp echo 'Already up-to-date' > $testroot/stdout.expected
149 e600f124 2021-03-21 stsp cmp -s $testroot/stdout.expected $testroot/stdout
150 fc414659 2022-04-16 thomas ret=$?
151 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
152 e600f124 2021-03-21 stsp diff -u $testroot/stdout.expected $testroot/stdout
153 e600f124 2021-03-21 stsp test_done "$testroot" "$ret"
154 a9662115 2021-08-29 naddy return 1
155 e600f124 2021-03-21 stsp fi
156 e600f124 2021-03-21 stsp
157 e600f124 2021-03-21 stsp # We should have a backup of old commits
158 e600f124 2021-03-21 stsp (cd $testroot/repo && got histedit -l > $testroot/stdout)
159 1c72bab5 2023-03-03 thomas d_orig1=`date -u -r $old_author_time1 +"%G-%m-%d"`
160 1c72bab5 2023-03-03 thomas d_orig2=`date -u -r $old_author_time2 +"%a %b %e %X %Y UTC"`
161 1c72bab5 2023-03-03 thomas d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"`
162 1c72bab5 2023-03-03 thomas d_orig=`date -u -r $orig_author_time +"%G-%m-%d"`
163 e600f124 2021-03-21 stsp cat > $testroot/stdout.expected <<EOF
164 e600f124 2021-03-21 stsp -----------------------------------------------
165 e600f124 2021-03-21 stsp commit $old_commit2 (formerly master)
166 e600f124 2021-03-21 stsp from: $GOT_AUTHOR
167 e600f124 2021-03-21 stsp date: $d_orig2
168 e600f124 2021-03-21 stsp
169 e600f124 2021-03-21 stsp committing to zeta on master
170 e600f124 2021-03-21 stsp
171 e600f124 2021-03-21 stsp has become commit $new_commit2 (master)
172 e600f124 2021-03-21 stsp $d_new2 $GOT_AUTHOR_11 committing to zeta on master
173 ad324bf5 2021-09-21 stsp EOF
174 ad324bf5 2021-09-21 stsp
175 ad324bf5 2021-09-21 stsp local is_forked=true d_fork fork_commit fork_commit_msg
176 ad324bf5 2021-09-21 stsp
177 ad324bf5 2021-09-21 stsp if [ "$old_commit1" = "$new_commit1" ]; then
178 ad324bf5 2021-09-21 stsp if [ "$old_commit2" = "$new_commit2" ]; then
179 ad324bf5 2021-09-21 stsp is_forked=false
180 ad324bf5 2021-09-21 stsp else
181 ad324bf5 2021-09-21 stsp d_fork=$d_orig1
182 ad324bf5 2021-09-21 stsp fork_commit=$new_commit1
183 ad324bf5 2021-09-21 stsp fork_commit_msg="committing changes"
184 ad324bf5 2021-09-21 stsp fi
185 ad324bf5 2021-09-21 stsp else
186 ad324bf5 2021-09-21 stsp d_fork=$d_orig
187 ad324bf5 2021-09-21 stsp fork_commit=$orig_commit
188 ad324bf5 2021-09-21 stsp fork_commit_msg="adding the test tree"
189 ad324bf5 2021-09-21 stsp fi
190 ad324bf5 2021-09-21 stsp
191 ad324bf5 2021-09-21 stsp $is_forked && cat >> $testroot/stdout.expected <<EOF
192 ad324bf5 2021-09-21 stsp history forked at $fork_commit
193 ad324bf5 2021-09-21 stsp $d_fork $GOT_AUTHOR_11 $fork_commit_msg
194 e600f124 2021-03-21 stsp EOF
195 ad324bf5 2021-09-21 stsp
196 a615e0e7 2020-12-16 stsp cmp -s $testroot/stdout.expected $testroot/stdout
197 fc414659 2022-04-16 thomas ret=$?
198 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
199 a615e0e7 2020-12-16 stsp diff -u $testroot/stdout.expected $testroot/stdout
200 643b85bc 2021-07-16 stsp test_done "$testroot" "$ret"
201 643b85bc 2021-07-16 stsp return 1
202 a615e0e7 2020-12-16 stsp fi
203 643b85bc 2021-07-16 stsp
204 643b85bc 2021-07-16 stsp (cd $testroot/repo && got histedit -X master \
205 643b85bc 2021-07-16 stsp > $testroot/stdout 2> $testroot/stderr)
206 643b85bc 2021-07-16 stsp echo -n "Deleted refs/got/backup/histedit/master/$new_commit2: " \
207 643b85bc 2021-07-16 stsp > $testroot/stdout.expected
208 643b85bc 2021-07-16 stsp echo "$old_commit2" >> $testroot/stdout.expected
209 643b85bc 2021-07-16 stsp echo -n > $testroot/stderr.expected
210 643b85bc 2021-07-16 stsp cmp -s $testroot/stdout.expected $testroot/stdout
211 fc414659 2022-04-16 thomas ret=$?
212 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
213 643b85bc 2021-07-16 stsp diff -u $testroot/stdout.expected $testroot/stdout
214 643b85bc 2021-07-16 stsp test_done "$testroot" "$ret"
215 643b85bc 2021-07-16 stsp return 1
216 643b85bc 2021-07-16 stsp fi
217 643b85bc 2021-07-16 stsp cmp -s $testroot/stderr.expected $testroot/stderr
218 fc414659 2022-04-16 thomas ret=$?
219 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
220 643b85bc 2021-07-16 stsp diff -u $testroot/stderr.expected $testroot/stderr
221 643b85bc 2021-07-16 stsp test_done "$testroot" "$ret"
222 643b85bc 2021-07-16 stsp return 1
223 643b85bc 2021-07-16 stsp fi
224 643b85bc 2021-07-16 stsp
225 643b85bc 2021-07-16 stsp (cd $testroot/repo && got histedit -l > $testroot/stdout)
226 643b85bc 2021-07-16 stsp echo -n > $testroot/stdout.expected
227 643b85bc 2021-07-16 stsp cmp -s $testroot/stdout.expected $testroot/stdout
228 fc414659 2022-04-16 thomas ret=$?
229 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
230 643b85bc 2021-07-16 stsp diff -u $testroot/stdout.expected $testroot/stdout
231 643b85bc 2021-07-16 stsp fi
232 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
233 0ebf8283 2019-07-24 stsp }
234 0ebf8283 2019-07-24 stsp
235 f6cae3ed 2020-09-13 naddy test_histedit_swap() {
236 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_swap`
237 0ebf8283 2019-07-24 stsp
238 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
239 0ebf8283 2019-07-24 stsp
240 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
241 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
242 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
243 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
244 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
245 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
246 0ebf8283 2019-07-24 stsp
247 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
248 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
249 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
250 0ebf8283 2019-07-24 stsp
251 86ac67ee 2019-07-25 stsp got diff -r $testroot/repo $orig_commit $old_commit2 \
252 86ac67ee 2019-07-25 stsp > $testroot/diff.expected
253 86ac67ee 2019-07-25 stsp
254 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
255 fc414659 2022-04-16 thomas ret=$?
256 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
257 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
258 0ebf8283 2019-07-24 stsp return 1
259 0ebf8283 2019-07-24 stsp fi
260 0ebf8283 2019-07-24 stsp
261 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" > $testroot/histedit-script
262 0ebf8283 2019-07-24 stsp echo "pick $old_commit1" >> $testroot/histedit-script
263 0ebf8283 2019-07-24 stsp
264 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
265 0ebf8283 2019-07-24 stsp > $testroot/stdout)
266 0ebf8283 2019-07-24 stsp
267 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_parent_commit $testroot/repo`
268 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_head $testroot/repo`
269 0ebf8283 2019-07-24 stsp
270 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
271 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
272 0ebf8283 2019-07-24 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
273 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
274 0ebf8283 2019-07-24 stsp
275 0ebf8283 2019-07-24 stsp echo "G epsilon/zeta" > $testroot/stdout.expected
276 0ebf8283 2019-07-24 stsp echo -n "$short_old_commit2 -> $short_new_commit2: " \
277 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
278 0ebf8283 2019-07-24 stsp echo "committing to zeta on master" >> $testroot/stdout.expected
279 0ebf8283 2019-07-24 stsp echo "G alpha" >> $testroot/stdout.expected
280 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
281 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
282 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
283 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
284 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
285 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
286 0ebf8283 2019-07-24 stsp
287 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
288 fc414659 2022-04-16 thomas ret=$?
289 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
290 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
291 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
292 0ebf8283 2019-07-24 stsp return 1
293 0ebf8283 2019-07-24 stsp fi
294 0ebf8283 2019-07-24 stsp
295 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/content.expected
296 0ebf8283 2019-07-24 stsp cat $testroot/wt/alpha > $testroot/content
297 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
298 fc414659 2022-04-16 thomas ret=$?
299 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
300 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
301 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
302 0ebf8283 2019-07-24 stsp return 1
303 0ebf8283 2019-07-24 stsp fi
304 0ebf8283 2019-07-24 stsp
305 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/beta ]; then
306 0ebf8283 2019-07-24 stsp echo "removed file beta still exists on disk" >&2
307 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
308 0ebf8283 2019-07-24 stsp return 1
309 0ebf8283 2019-07-24 stsp fi
310 0ebf8283 2019-07-24 stsp
311 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/content.expected
312 0ebf8283 2019-07-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
313 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
314 fc414659 2022-04-16 thomas ret=$?
315 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
316 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
317 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
318 0ebf8283 2019-07-24 stsp return 1
319 0ebf8283 2019-07-24 stsp fi
320 0ebf8283 2019-07-24 stsp
321 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
322 0ebf8283 2019-07-24 stsp
323 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
324 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
325 fc414659 2022-04-16 thomas ret=$?
326 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
327 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
328 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
329 0ebf8283 2019-07-24 stsp return 1
330 0ebf8283 2019-07-24 stsp fi
331 0ebf8283 2019-07-24 stsp
332 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
333 0ebf8283 2019-07-24 stsp echo "commit $new_commit1 (master)" > $testroot/stdout.expected
334 0ebf8283 2019-07-24 stsp echo "commit $new_commit2" >> $testroot/stdout.expected
335 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
336 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
337 fc414659 2022-04-16 thomas ret=$?
338 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
339 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
340 86ac67ee 2019-07-25 stsp test_done "$testroot" "$ret"
341 86ac67ee 2019-07-25 stsp return 1
342 86ac67ee 2019-07-25 stsp fi
343 86ac67ee 2019-07-25 stsp
344 86ac67ee 2019-07-25 stsp got diff -r $testroot/repo $orig_commit $new_commit1 \
345 86ac67ee 2019-07-25 stsp > $testroot/diff
346 ac3cdf31 2023-03-06 thomas ed -s $testroot/diff.expected <<-EOF
347 ac3cdf31 2023-03-06 thomas ,s/$old_commit2/$new_commit1/
348 ac3cdf31 2023-03-06 thomas w
349 ac3cdf31 2023-03-06 thomas EOF
350 86ac67ee 2019-07-25 stsp cmp -s $testroot/diff.expected $testroot/diff
351 fc414659 2022-04-16 thomas ret=$?
352 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
353 86ac67ee 2019-07-25 stsp diff -u $testroot/diff.expected $testroot/diff
354 0ebf8283 2019-07-24 stsp fi
355 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
356 0ebf8283 2019-07-24 stsp }
357 0ebf8283 2019-07-24 stsp
358 f6cae3ed 2020-09-13 naddy test_histedit_drop() {
359 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_drop`
360 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
361 0ebf8283 2019-07-24 stsp
362 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
363 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
364 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
365 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
366 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
367 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
368 0ebf8283 2019-07-24 stsp
369 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
370 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
371 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
372 0ebf8283 2019-07-24 stsp
373 86ac67ee 2019-07-25 stsp got diff -r $testroot/repo $old_commit1 $old_commit2 \
374 86ac67ee 2019-07-25 stsp > $testroot/diff.expected
375 86ac67ee 2019-07-25 stsp
376 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
377 fc414659 2022-04-16 thomas ret=$?
378 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
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 "drop $old_commit1" > $testroot/histedit-script
384 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" >> $testroot/histedit-script
385 0ebf8283 2019-07-24 stsp
386 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
387 0ebf8283 2019-07-24 stsp > $testroot/stdout)
388 0ebf8283 2019-07-24 stsp
389 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
390 0ebf8283 2019-07-24 stsp
391 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
392 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
393 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
394 0ebf8283 2019-07-24 stsp
395 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> drop commit: committing changes" \
396 0ebf8283 2019-07-24 stsp > $testroot/stdout.expected
397 0ebf8283 2019-07-24 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
398 0ebf8283 2019-07-24 stsp echo -n "$short_old_commit2 -> $short_new_commit2: " \
399 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
400 0ebf8283 2019-07-24 stsp echo "committing to zeta on master" >> $testroot/stdout.expected
401 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
402 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
403 0ebf8283 2019-07-24 stsp
404 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
405 fc414659 2022-04-16 thomas ret=$?
406 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
407 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
408 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
409 0ebf8283 2019-07-24 stsp return 1
410 0ebf8283 2019-07-24 stsp fi
411 0ebf8283 2019-07-24 stsp
412 0ebf8283 2019-07-24 stsp for f in alpha beta; do
413 0ebf8283 2019-07-24 stsp echo "$f" > $testroot/content.expected
414 0ebf8283 2019-07-24 stsp cat $testroot/wt/$f > $testroot/content
415 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
416 fc414659 2022-04-16 thomas ret=$?
417 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
418 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
419 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
420 0ebf8283 2019-07-24 stsp return 1
421 0ebf8283 2019-07-24 stsp fi
422 0ebf8283 2019-07-24 stsp done
423 0ebf8283 2019-07-24 stsp
424 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/new ]; then
425 0ebf8283 2019-07-24 stsp echo "file new exists on disk but should not" >&2
426 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
427 0ebf8283 2019-07-24 stsp return 1
428 0ebf8283 2019-07-24 stsp fi
429 0ebf8283 2019-07-24 stsp
430 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
431 0ebf8283 2019-07-24 stsp
432 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
433 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
434 fc414659 2022-04-16 thomas ret=$?
435 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
436 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
437 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
438 0ebf8283 2019-07-24 stsp return 1
439 0ebf8283 2019-07-24 stsp fi
440 0ebf8283 2019-07-24 stsp
441 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
442 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
443 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
444 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
445 fc414659 2022-04-16 thomas ret=$?
446 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
447 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
448 86ac67ee 2019-07-25 stsp test_done "$testroot" "$ret"
449 86ac67ee 2019-07-25 stsp return 1
450 86ac67ee 2019-07-25 stsp fi
451 86ac67ee 2019-07-25 stsp
452 86ac67ee 2019-07-25 stsp got diff -r $testroot/repo $orig_commit $new_commit2 \
453 86ac67ee 2019-07-25 stsp > $testroot/diff
454 ac3cdf31 2023-03-06 thomas ed -s $testroot/diff.expected <<-EOF
455 ac3cdf31 2023-03-06 thomas ,s/$old_commit1/$orig_commit/
456 ac3cdf31 2023-03-06 thomas ,s/$old_commit2/$new_commit2/
457 ac3cdf31 2023-03-06 thomas w
458 ac3cdf31 2023-03-06 thomas EOF
459 86ac67ee 2019-07-25 stsp cmp -s $testroot/diff.expected $testroot/diff
460 fc414659 2022-04-16 thomas ret=$?
461 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
462 86ac67ee 2019-07-25 stsp diff -u $testroot/diff.expected $testroot/diff
463 0ebf8283 2019-07-24 stsp fi
464 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
465 0ebf8283 2019-07-24 stsp }
466 0ebf8283 2019-07-24 stsp
467 f6cae3ed 2020-09-13 naddy test_histedit_fold() {
468 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_fold`
469 0ebf8283 2019-07-24 stsp
470 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
471 0ebf8283 2019-07-24 stsp
472 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
473 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
474 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
475 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
476 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
477 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
478 0ebf8283 2019-07-24 stsp
479 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
480 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
481 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
482 3f9de99f 2019-07-24 stsp
483 3f9de99f 2019-07-24 stsp echo "modified delta on master" > $testroot/repo/gamma/delta
484 3f9de99f 2019-07-24 stsp git_commit $testroot/repo -m "committing to delta on master"
485 3f9de99f 2019-07-24 stsp local old_commit3=`git_show_head $testroot/repo`
486 0ebf8283 2019-07-24 stsp
487 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
488 fc414659 2022-04-16 thomas ret=$?
489 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
490 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
491 0ebf8283 2019-07-24 stsp return 1
492 0ebf8283 2019-07-24 stsp fi
493 f52e24d8 2023-10-28 thomas
494 f52e24d8 2023-10-28 thomas cat > $testroot/editor.sh <<EOF
495 f52e24d8 2023-10-28 thomas #!/bin/sh
496 f52e24d8 2023-10-28 thomas ed -s "\$1" <<-EOF
497 f52e24d8 2023-10-28 thomas ,s/.*/committing folded changes/
498 f52e24d8 2023-10-28 thomas w
499 f52e24d8 2023-10-28 thomas EOF
500 f52e24d8 2023-10-28 thomas EOF
501 f52e24d8 2023-10-28 thomas chmod +x $testroot/editor.sh
502 0ebf8283 2019-07-24 stsp
503 0ebf8283 2019-07-24 stsp echo "fold $old_commit1" > $testroot/histedit-script
504 3f9de99f 2019-07-24 stsp echo "drop $old_commit2" >> $testroot/histedit-script
505 3f9de99f 2019-07-24 stsp echo "pick $old_commit3" >> $testroot/histedit-script
506 0ebf8283 2019-07-24 stsp
507 f52e24d8 2023-10-28 thomas (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
508 f52e24d8 2023-10-28 thomas VISUAL="$testroot/editor.sh" \
509 f52e24d8 2023-10-28 thomas got histedit -F $testroot/histedit-script > $testroot/stdout)
510 0ebf8283 2019-07-24 stsp
511 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_parent_commit $testroot/repo`
512 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
513 0ebf8283 2019-07-24 stsp
514 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
515 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
516 3f9de99f 2019-07-24 stsp local short_old_commit3=`trim_obj_id 28 $old_commit3`
517 0ebf8283 2019-07-24 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
518 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
519 0ebf8283 2019-07-24 stsp
520 0ebf8283 2019-07-24 stsp echo "G alpha" > $testroot/stdout.expected
521 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
522 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
523 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> fold commit: committing changes" \
524 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
525 3f9de99f 2019-07-24 stsp echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
526 3f9de99f 2019-07-24 stsp echo "drop commit: committing to zeta on master" \
527 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
528 3f9de99f 2019-07-24 stsp echo "G gamma/delta" >> $testroot/stdout.expected
529 3f9de99f 2019-07-24 stsp echo -n "$short_old_commit3 -> $short_new_commit2: " \
530 3f9de99f 2019-07-24 stsp >> $testroot/stdout.expected
531 0ebf8283 2019-07-24 stsp echo "committing folded changes" >> $testroot/stdout.expected
532 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
533 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
534 0ebf8283 2019-07-24 stsp
535 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
536 fc414659 2022-04-16 thomas ret=$?
537 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
538 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
539 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
540 0ebf8283 2019-07-24 stsp return 1
541 0ebf8283 2019-07-24 stsp fi
542 0ebf8283 2019-07-24 stsp
543 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/content.expected
544 0ebf8283 2019-07-24 stsp cat $testroot/wt/alpha > $testroot/content
545 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
546 fc414659 2022-04-16 thomas ret=$?
547 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
548 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
549 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
550 0ebf8283 2019-07-24 stsp return 1
551 0ebf8283 2019-07-24 stsp fi
552 0ebf8283 2019-07-24 stsp
553 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/beta ]; then
554 0ebf8283 2019-07-24 stsp echo "removed file beta still exists on disk" >&2
555 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
556 0ebf8283 2019-07-24 stsp return 1
557 0ebf8283 2019-07-24 stsp fi
558 0ebf8283 2019-07-24 stsp
559 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/content.expected
560 0ebf8283 2019-07-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
561 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
562 fc414659 2022-04-16 thomas ret=$?
563 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
564 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
565 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
566 0ebf8283 2019-07-24 stsp return 1
567 0ebf8283 2019-07-24 stsp fi
568 0ebf8283 2019-07-24 stsp
569 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
570 0ebf8283 2019-07-24 stsp
571 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
572 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
573 fc414659 2022-04-16 thomas ret=$?
574 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
575 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
576 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
577 0ebf8283 2019-07-24 stsp return 1
578 0ebf8283 2019-07-24 stsp fi
579 0ebf8283 2019-07-24 stsp
580 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
581 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
582 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
583 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
584 fc414659 2022-04-16 thomas ret=$?
585 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
586 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
587 0ebf8283 2019-07-24 stsp fi
588 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
589 0ebf8283 2019-07-24 stsp }
590 0ebf8283 2019-07-24 stsp
591 f6cae3ed 2020-09-13 naddy test_histedit_edit() {
592 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_edit`
593 0ebf8283 2019-07-24 stsp
594 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
595 0ebf8283 2019-07-24 stsp
596 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
597 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
598 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
599 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
600 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
601 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
602 0ebf8283 2019-07-24 stsp
603 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
604 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
605 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
606 0ebf8283 2019-07-24 stsp
607 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
608 fc414659 2022-04-16 thomas ret=$?
609 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
610 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
611 0ebf8283 2019-07-24 stsp return 1
612 0ebf8283 2019-07-24 stsp fi
613 0ebf8283 2019-07-24 stsp
614 0ebf8283 2019-07-24 stsp echo "edit $old_commit1" > $testroot/histedit-script
615 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" >> $testroot/histedit-script
616 0ebf8283 2019-07-24 stsp
617 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
618 0ebf8283 2019-07-24 stsp > $testroot/stdout)
619 0ebf8283 2019-07-24 stsp
620 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
621 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
622 0ebf8283 2019-07-24 stsp
623 0ebf8283 2019-07-24 stsp echo "G alpha" > $testroot/stdout.expected
624 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
625 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
626 0ebf8283 2019-07-24 stsp echo "Stopping histedit for amending commit $old_commit1" \
627 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
628 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
629 fc414659 2022-04-16 thomas ret=$?
630 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
631 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
632 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
633 0ebf8283 2019-07-24 stsp return 1
634 0ebf8283 2019-07-24 stsp fi
635 0ebf8283 2019-07-24 stsp
636 0ebf8283 2019-07-24 stsp echo "edited modified alpha on master" > $testroot/wt/alpha
637 0ebf8283 2019-07-24 stsp
638 f032f1f7 2019-08-04 stsp # test interaction of 'got stage' and histedit -c
639 f032f1f7 2019-08-04 stsp (cd $testroot/wt && got stage alpha > /dev/null)
640 f032f1f7 2019-08-04 stsp (cd $testroot/wt && got histedit -c > $testroot/stdout \
641 f032f1f7 2019-08-04 stsp 2> $testroot/stderr)
642 fc414659 2022-04-16 thomas ret=$?
643 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
644 f032f1f7 2019-08-04 stsp echo "histedit succeeded unexpectedly" >&2
645 f032f1f7 2019-08-04 stsp test_done "$testroot" "1"
646 f032f1f7 2019-08-04 stsp return 1
647 f032f1f7 2019-08-04 stsp fi
648 f032f1f7 2019-08-04 stsp echo -n "got: work tree contains files with staged changes; " \
649 f032f1f7 2019-08-04 stsp > $testroot/stderr.expected
650 f032f1f7 2019-08-04 stsp echo "these changes must be committed or unstaged first" \
651 f032f1f7 2019-08-04 stsp >> $testroot/stderr.expected
652 f032f1f7 2019-08-04 stsp cmp -s $testroot/stderr.expected $testroot/stderr
653 fc414659 2022-04-16 thomas ret=$?
654 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
655 f032f1f7 2019-08-04 stsp diff -u $testroot/stderr.expected $testroot/stderr
656 f032f1f7 2019-08-04 stsp test_done "$testroot" "$ret"
657 f032f1f7 2019-08-04 stsp return 1
658 f032f1f7 2019-08-04 stsp fi
659 f032f1f7 2019-08-04 stsp
660 f032f1f7 2019-08-04 stsp (cd $testroot/wt && got unstage alpha > /dev/null)
661 0ebf8283 2019-07-24 stsp
662 f52e24d8 2023-10-28 thomas cat > $testroot/editor.sh <<EOF
663 f52e24d8 2023-10-28 thomas #!/bin/sh
664 f52e24d8 2023-10-28 thomas ed -s "\$1" <<-EOF
665 f52e24d8 2023-10-28 thomas ,s/.*/committing changes/
666 f52e24d8 2023-10-28 thomas w
667 f52e24d8 2023-10-28 thomas EOF
668 f52e24d8 2023-10-28 thomas EOF
669 f52e24d8 2023-10-28 thomas chmod +x $testroot/editor.sh
670 f52e24d8 2023-10-28 thomas
671 f52e24d8 2023-10-28 thomas (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
672 f52e24d8 2023-10-28 thomas VISUAL="$testroot/editor.sh" \
673 f52e24d8 2023-10-28 thomas got histedit -c > $testroot/stdout)
674 f52e24d8 2023-10-28 thomas
675 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_parent_commit $testroot/repo`
676 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
677 0ebf8283 2019-07-24 stsp
678 0ebf8283 2019-07-24 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
679 0ebf8283 2019-07-24 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
680 0ebf8283 2019-07-24 stsp
681 0ebf8283 2019-07-24 stsp echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
682 0ebf8283 2019-07-24 stsp > $testroot/stdout.expected
683 0ebf8283 2019-07-24 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
684 0ebf8283 2019-07-24 stsp echo -n "$short_old_commit2 -> $short_new_commit2: " \
685 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
686 0ebf8283 2019-07-24 stsp echo "committing to zeta on master" >> $testroot/stdout.expected
687 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
688 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
689 0ebf8283 2019-07-24 stsp
690 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
691 fc414659 2022-04-16 thomas ret=$?
692 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
693 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
694 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
695 0ebf8283 2019-07-24 stsp return 1
696 0ebf8283 2019-07-24 stsp fi
697 0ebf8283 2019-07-24 stsp
698 0ebf8283 2019-07-24 stsp echo "edited modified alpha on master" > $testroot/content.expected
699 0ebf8283 2019-07-24 stsp cat $testroot/wt/alpha > $testroot/content
700 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
701 fc414659 2022-04-16 thomas ret=$?
702 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
703 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
704 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
705 0ebf8283 2019-07-24 stsp return 1
706 0ebf8283 2019-07-24 stsp fi
707 0ebf8283 2019-07-24 stsp
708 0ebf8283 2019-07-24 stsp if [ -e $testroot/wt/beta ]; then
709 0ebf8283 2019-07-24 stsp echo "removed file beta still exists on disk" >&2
710 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
711 0ebf8283 2019-07-24 stsp return 1
712 0ebf8283 2019-07-24 stsp fi
713 0ebf8283 2019-07-24 stsp
714 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/content.expected
715 0ebf8283 2019-07-24 stsp cat $testroot/wt/epsilon/new > $testroot/content
716 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
717 fc414659 2022-04-16 thomas ret=$?
718 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
719 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
720 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
721 0ebf8283 2019-07-24 stsp return 1
722 0ebf8283 2019-07-24 stsp fi
723 0ebf8283 2019-07-24 stsp
724 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
725 0ebf8283 2019-07-24 stsp
726 0ebf8283 2019-07-24 stsp echo -n > $testroot/stdout.expected
727 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
728 fc414659 2022-04-16 thomas ret=$?
729 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
730 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
731 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
732 0ebf8283 2019-07-24 stsp return 1
733 0ebf8283 2019-07-24 stsp fi
734 0ebf8283 2019-07-24 stsp
735 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
736 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
737 0ebf8283 2019-07-24 stsp echo "commit $new_commit1" >> $testroot/stdout.expected
738 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
739 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
740 fc414659 2022-04-16 thomas ret=$?
741 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
742 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
743 0ebf8283 2019-07-24 stsp fi
744 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
745 0ebf8283 2019-07-24 stsp }
746 0ebf8283 2019-07-24 stsp
747 f6cae3ed 2020-09-13 naddy test_histedit_fold_last_commit() {
748 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_fold_last_commit`
749 0ebf8283 2019-07-24 stsp
750 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
751 0ebf8283 2019-07-24 stsp
752 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
753 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
754 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
755 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
756 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
757 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
758 0ebf8283 2019-07-24 stsp
759 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
760 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
761 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
762 0ebf8283 2019-07-24 stsp
763 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
764 fc414659 2022-04-16 thomas ret=$?
765 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
766 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
767 0ebf8283 2019-07-24 stsp return 1
768 0ebf8283 2019-07-24 stsp fi
769 0ebf8283 2019-07-24 stsp
770 0ebf8283 2019-07-24 stsp echo "pick $old_commit1" > $testroot/histedit-script
771 0ebf8283 2019-07-24 stsp echo "fold $old_commit2" >> $testroot/histedit-script
772 0ebf8283 2019-07-24 stsp
773 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
774 0ebf8283 2019-07-24 stsp > $testroot/stdout 2> $testroot/stderr)
775 0ebf8283 2019-07-24 stsp
776 fc414659 2022-04-16 thomas ret=$?
777 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
778 0ebf8283 2019-07-24 stsp echo "histedit succeeded unexpectedly" >&2
779 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
780 0ebf8283 2019-07-24 stsp return 1
781 0ebf8283 2019-07-24 stsp fi
782 0ebf8283 2019-07-24 stsp
783 0ebf8283 2019-07-24 stsp echo "got: last commit in histedit script cannot be folded" \
784 0ebf8283 2019-07-24 stsp > $testroot/stderr.expected
785 0ebf8283 2019-07-24 stsp
786 0ebf8283 2019-07-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
787 fc414659 2022-04-16 thomas ret=$?
788 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
789 0ebf8283 2019-07-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
790 0ebf8283 2019-07-24 stsp fi
791 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
792 0ebf8283 2019-07-24 stsp }
793 0ebf8283 2019-07-24 stsp
794 f52e24d8 2023-10-28 thomas test_histedit_missing_commit_pick() {
795 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_missing_commit`
796 0ebf8283 2019-07-24 stsp
797 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
798 0ebf8283 2019-07-24 stsp
799 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
800 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
801 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
802 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
803 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
804 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
805 0ebf8283 2019-07-24 stsp
806 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
807 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
808 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
809 0ebf8283 2019-07-24 stsp
810 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
811 fc414659 2022-04-16 thomas ret=$?
812 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
813 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
814 0ebf8283 2019-07-24 stsp return 1
815 0ebf8283 2019-07-24 stsp fi
816 0ebf8283 2019-07-24 stsp
817 0ebf8283 2019-07-24 stsp echo "pick $old_commit1" > $testroot/histedit-script
818 0ebf8283 2019-07-24 stsp
819 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
820 0ebf8283 2019-07-24 stsp > $testroot/stdout 2> $testroot/stderr)
821 0ebf8283 2019-07-24 stsp
822 fc414659 2022-04-16 thomas ret=$?
823 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
824 0ebf8283 2019-07-24 stsp echo "histedit succeeded unexpectedly" >&2
825 0ebf8283 2019-07-24 stsp test_done "$testroot" "1"
826 0ebf8283 2019-07-24 stsp return 1
827 0ebf8283 2019-07-24 stsp fi
828 0ebf8283 2019-07-24 stsp
829 0ebf8283 2019-07-24 stsp echo "got: commit $old_commit2 missing from histedit script" \
830 0ebf8283 2019-07-24 stsp > $testroot/stderr.expected
831 0ebf8283 2019-07-24 stsp
832 0ebf8283 2019-07-24 stsp cmp -s $testroot/stderr.expected $testroot/stderr
833 fc414659 2022-04-16 thomas ret=$?
834 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
835 0ebf8283 2019-07-24 stsp diff -u $testroot/stderr.expected $testroot/stderr
836 0ebf8283 2019-07-24 stsp fi
837 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
838 0ebf8283 2019-07-24 stsp }
839 0ebf8283 2019-07-24 stsp
840 f52e24d8 2023-10-28 thomas test_histedit_missing_commit_mesg() {
841 f52e24d8 2023-10-28 thomas local testroot=`test_init histedit_missing_commit`
842 f52e24d8 2023-10-28 thomas
843 f52e24d8 2023-10-28 thomas local orig_commit=`git_show_head $testroot/repo`
844 f52e24d8 2023-10-28 thomas
845 f52e24d8 2023-10-28 thomas echo "modified alpha on master" > $testroot/repo/alpha
846 f52e24d8 2023-10-28 thomas git -C $testroot/repo rm -q beta
847 f52e24d8 2023-10-28 thomas echo "new file on master" > $testroot/repo/epsilon/new
848 f52e24d8 2023-10-28 thomas git -C $testroot/repo add epsilon/new
849 f52e24d8 2023-10-28 thomas git_commit $testroot/repo -m "committing changes"
850 f52e24d8 2023-10-28 thomas local old_commit1=`git_show_head $testroot/repo`
851 f52e24d8 2023-10-28 thomas
852 f52e24d8 2023-10-28 thomas echo "modified zeta on master" > $testroot/repo/epsilon/zeta
853 f52e24d8 2023-10-28 thomas git_commit $testroot/repo -m "committing to zeta on master"
854 f52e24d8 2023-10-28 thomas local old_commit2=`git_show_head $testroot/repo`
855 f52e24d8 2023-10-28 thomas
856 f52e24d8 2023-10-28 thomas got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
857 f52e24d8 2023-10-28 thomas ret=$?
858 f52e24d8 2023-10-28 thomas if [ $ret -ne 0 ]; then
859 f52e24d8 2023-10-28 thomas test_done "$testroot" "$ret"
860 f52e24d8 2023-10-28 thomas return 1
861 f52e24d8 2023-10-28 thomas fi
862 f52e24d8 2023-10-28 thomas
863 f52e24d8 2023-10-28 thomas cat > $testroot/editor.sh <<EOF
864 f52e24d8 2023-10-28 thomas #!/bin/sh
865 f52e24d8 2023-10-28 thomas ed -s "\$1" <<-EOF
866 f52e24d8 2023-10-28 thomas ,s/.*/committing folded changes/
867 f52e24d8 2023-10-28 thomas w
868 f52e24d8 2023-10-28 thomas EOF
869 f52e24d8 2023-10-28 thomas EOF
870 f52e24d8 2023-10-28 thomas chmod +x $testroot/editor.sh
871 f52e24d8 2023-10-28 thomas
872 f52e24d8 2023-10-28 thomas echo "mesg $old_commit1" > $testroot/histedit-script
873 f52e24d8 2023-10-28 thomas
874 f52e24d8 2023-10-28 thomas (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
875 f52e24d8 2023-10-28 thomas VISUAL="$testroot/editor.sh" \
876 f52e24d8 2023-10-28 thomas got histedit -F $testroot/histedit-script > $testroot/stdout \
877 f52e24d8 2023-10-28 thomas 2>$testroot/stderr)
878 f52e24d8 2023-10-28 thomas
879 f52e24d8 2023-10-28 thomas ret=$?
880 f52e24d8 2023-10-28 thomas if [ $ret -eq 0 ]; then
881 f52e24d8 2023-10-28 thomas echo "histedit succeeded unexpectedly" >&2
882 f52e24d8 2023-10-28 thomas test_done "$testroot" "1"
883 f52e24d8 2023-10-28 thomas return 1
884 f52e24d8 2023-10-28 thomas fi
885 f52e24d8 2023-10-28 thomas
886 f52e24d8 2023-10-28 thomas echo "got: commit $old_commit2 missing from histedit script" \
887 f52e24d8 2023-10-28 thomas > $testroot/stderr.expected
888 f52e24d8 2023-10-28 thomas
889 f52e24d8 2023-10-28 thomas cmp -s $testroot/stderr.expected $testroot/stderr
890 f52e24d8 2023-10-28 thomas ret=$?
891 f52e24d8 2023-10-28 thomas if [ $ret -ne 0 ]; then
892 f52e24d8 2023-10-28 thomas diff -u $testroot/stderr.expected $testroot/stderr
893 f52e24d8 2023-10-28 thomas fi
894 f52e24d8 2023-10-28 thomas test_done "$testroot" "$ret"
895 f52e24d8 2023-10-28 thomas }
896 f52e24d8 2023-10-28 thomas
897 f6cae3ed 2020-09-13 naddy test_histedit_abort() {
898 0ebf8283 2019-07-24 stsp local testroot=`test_init histedit_abort`
899 0ebf8283 2019-07-24 stsp
900 0ebf8283 2019-07-24 stsp local orig_commit=`git_show_head $testroot/repo`
901 0ebf8283 2019-07-24 stsp
902 0ebf8283 2019-07-24 stsp echo "modified alpha on master" > $testroot/repo/alpha
903 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
904 0ebf8283 2019-07-24 stsp echo "new file on master" > $testroot/repo/epsilon/new
905 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
906 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing changes"
907 0ebf8283 2019-07-24 stsp local old_commit1=`git_show_head $testroot/repo`
908 0ebf8283 2019-07-24 stsp
909 0ebf8283 2019-07-24 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
910 0ebf8283 2019-07-24 stsp git_commit $testroot/repo -m "committing to zeta on master"
911 0ebf8283 2019-07-24 stsp local old_commit2=`git_show_head $testroot/repo`
912 0ebf8283 2019-07-24 stsp
913 0ebf8283 2019-07-24 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
914 fc414659 2022-04-16 thomas ret=$?
915 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
916 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
917 0ebf8283 2019-07-24 stsp return 1
918 0ebf8283 2019-07-24 stsp fi
919 d52bac28 2021-10-08 thomas
920 d52bac28 2021-10-08 thomas # unrelated unversioned file in work tree
921 d52bac28 2021-10-08 thomas touch $testroot/wt/unversioned-file
922 0ebf8283 2019-07-24 stsp
923 0ebf8283 2019-07-24 stsp echo "edit $old_commit1" > $testroot/histedit-script
924 0ebf8283 2019-07-24 stsp echo "pick $old_commit2" >> $testroot/histedit-script
925 0ebf8283 2019-07-24 stsp
926 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
927 0ebf8283 2019-07-24 stsp > $testroot/stdout)
928 0ebf8283 2019-07-24 stsp
929 0ebf8283 2019-07-24 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
930 0ebf8283 2019-07-24 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
931 0ebf8283 2019-07-24 stsp
932 0ebf8283 2019-07-24 stsp echo "G alpha" > $testroot/stdout.expected
933 0ebf8283 2019-07-24 stsp echo "D beta" >> $testroot/stdout.expected
934 0ebf8283 2019-07-24 stsp echo "A epsilon/new" >> $testroot/stdout.expected
935 0ebf8283 2019-07-24 stsp echo "Stopping histedit for amending commit $old_commit1" \
936 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
937 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
938 fc414659 2022-04-16 thomas ret=$?
939 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
940 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
941 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
942 0ebf8283 2019-07-24 stsp return 1
943 0ebf8283 2019-07-24 stsp fi
944 0ebf8283 2019-07-24 stsp
945 0ebf8283 2019-07-24 stsp echo "edited modified alpha on master" > $testroot/wt/alpha
946 0ebf8283 2019-07-24 stsp
947 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got histedit -a > $testroot/stdout)
948 0ebf8283 2019-07-24 stsp
949 0ebf8283 2019-07-24 stsp local new_commit1=`git_show_parent_commit $testroot/repo`
950 0ebf8283 2019-07-24 stsp local new_commit2=`git_show_head $testroot/repo`
951 0ebf8283 2019-07-24 stsp
952 0ebf8283 2019-07-24 stsp echo "Switching work tree to refs/heads/master" \
953 0ebf8283 2019-07-24 stsp > $testroot/stdout.expected
954 0ebf8283 2019-07-24 stsp echo "R alpha" >> $testroot/stdout.expected
955 0ebf8283 2019-07-24 stsp echo "R beta" >> $testroot/stdout.expected
956 0ebf8283 2019-07-24 stsp echo "R epsilon/new" >> $testroot/stdout.expected
957 0ebf8283 2019-07-24 stsp echo "Histedit of refs/heads/master aborted" \
958 0ebf8283 2019-07-24 stsp >> $testroot/stdout.expected
959 0ebf8283 2019-07-24 stsp
960 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
961 fc414659 2022-04-16 thomas ret=$?
962 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
963 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
964 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
965 0ebf8283 2019-07-24 stsp return 1
966 0ebf8283 2019-07-24 stsp fi
967 0ebf8283 2019-07-24 stsp
968 0ebf8283 2019-07-24 stsp for f in alpha beta; do
969 0ebf8283 2019-07-24 stsp echo "$f" > $testroot/content.expected
970 0ebf8283 2019-07-24 stsp cat $testroot/wt/$f > $testroot/content
971 0ebf8283 2019-07-24 stsp cmp -s $testroot/content.expected $testroot/content
972 fc414659 2022-04-16 thomas ret=$?
973 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
974 0ebf8283 2019-07-24 stsp diff -u $testroot/content.expected $testroot/content
975 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
976 0ebf8283 2019-07-24 stsp return 1
977 0ebf8283 2019-07-24 stsp fi
978 0ebf8283 2019-07-24 stsp done
979 0ebf8283 2019-07-24 stsp
980 8641a332 2023-04-14 thomas if [ -e $testroot/wt/epsilon/new ]; then
981 8641a332 2023-04-14 thomas echo "removed file new still exists on disk" >&2
982 8641a332 2023-04-14 thomas test_done "$testroot" "1"
983 0ebf8283 2019-07-24 stsp return 1
984 0ebf8283 2019-07-24 stsp fi
985 0ebf8283 2019-07-24 stsp
986 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got status > $testroot/stdout)
987 0ebf8283 2019-07-24 stsp
988 8641a332 2023-04-14 thomas echo "? unversioned-file" > $testroot/stdout.expected
989 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
990 fc414659 2022-04-16 thomas ret=$?
991 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
992 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
993 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
994 0ebf8283 2019-07-24 stsp return 1
995 0ebf8283 2019-07-24 stsp fi
996 0ebf8283 2019-07-24 stsp
997 0ebf8283 2019-07-24 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
998 0ebf8283 2019-07-24 stsp echo "commit $new_commit2 (master)" > $testroot/stdout.expected
999 0ebf8283 2019-07-24 stsp echo "commit $new_commit1" >> $testroot/stdout.expected
1000 0ebf8283 2019-07-24 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
1001 0160a755 2019-07-25 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1002 fc414659 2022-04-16 thomas ret=$?
1003 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1004 0160a755 2019-07-25 stsp diff -u $testroot/stdout.expected $testroot/stdout
1005 0160a755 2019-07-25 stsp fi
1006 0160a755 2019-07-25 stsp test_done "$testroot" "$ret"
1007 0160a755 2019-07-25 stsp }
1008 0160a755 2019-07-25 stsp
1009 f6cae3ed 2020-09-13 naddy test_histedit_path_prefix_drop() {
1010 a4027091 2019-07-25 stsp local testroot=`test_init histedit_path_prefix_drop`
1011 0160a755 2019-07-25 stsp local orig_commit=`git_show_head $testroot/repo`
1012 0160a755 2019-07-25 stsp
1013 0160a755 2019-07-25 stsp echo "modified zeta" > $testroot/repo/epsilon/zeta
1014 0160a755 2019-07-25 stsp git_commit $testroot/repo -m "changing zeta"
1015 0160a755 2019-07-25 stsp local old_commit1=`git_show_head $testroot/repo`
1016 0160a755 2019-07-25 stsp
1017 0160a755 2019-07-25 stsp got checkout -c $orig_commit -p gamma $testroot/repo \
1018 0160a755 2019-07-25 stsp $testroot/wt > /dev/null
1019 fc414659 2022-04-16 thomas ret=$?
1020 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1021 0160a755 2019-07-25 stsp test_done "$testroot" "$ret"
1022 0160a755 2019-07-25 stsp return 1
1023 0160a755 2019-07-25 stsp fi
1024 0160a755 2019-07-25 stsp
1025 0160a755 2019-07-25 stsp echo "drop $old_commit1" > $testroot/histedit-script
1026 0160a755 2019-07-25 stsp
1027 0160a755 2019-07-25 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1028 0160a755 2019-07-25 stsp > $testroot/stdout 2> $testroot/stderr)
1029 0160a755 2019-07-25 stsp
1030 fc414659 2022-04-16 thomas ret=$?
1031 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1032 0160a755 2019-07-25 stsp echo "histedit succeeded unexpectedly" >&2
1033 0160a755 2019-07-25 stsp test_done "$testroot" "1"
1034 0160a755 2019-07-25 stsp return 1
1035 0160a755 2019-07-25 stsp fi
1036 0160a755 2019-07-25 stsp
1037 0160a755 2019-07-25 stsp echo -n "got: cannot edit branch history which contains changes " \
1038 0160a755 2019-07-25 stsp > $testroot/stderr.expected
1039 0160a755 2019-07-25 stsp echo "outside of this work tree's path prefix" \
1040 0160a755 2019-07-25 stsp >> $testroot/stderr.expected
1041 0160a755 2019-07-25 stsp
1042 0160a755 2019-07-25 stsp cmp -s $testroot/stderr.expected $testroot/stderr
1043 fc414659 2022-04-16 thomas ret=$?
1044 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1045 0160a755 2019-07-25 stsp diff -u $testroot/stderr.expected $testroot/stderr
1046 0160a755 2019-07-25 stsp test_done "$testroot" "$ret"
1047 0160a755 2019-07-25 stsp return 1
1048 0160a755 2019-07-25 stsp fi
1049 0160a755 2019-07-25 stsp
1050 0160a755 2019-07-25 stsp rm -rf $testroot/wt
1051 0160a755 2019-07-25 stsp got checkout -c $orig_commit -p epsilon $testroot/repo \
1052 0160a755 2019-07-25 stsp $testroot/wt > /dev/null
1053 fc414659 2022-04-16 thomas ret=$?
1054 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1055 0160a755 2019-07-25 stsp test_done "$testroot" "$ret"
1056 0160a755 2019-07-25 stsp return 1
1057 0160a755 2019-07-25 stsp fi
1058 0160a755 2019-07-25 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1059 0160a755 2019-07-25 stsp > $testroot/stdout)
1060 0160a755 2019-07-25 stsp
1061 0160a755 2019-07-25 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
1062 0160a755 2019-07-25 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
1063 0160a755 2019-07-25 stsp
1064 0160a755 2019-07-25 stsp echo "$short_old_commit1 -> drop commit: changing zeta" \
1065 0160a755 2019-07-25 stsp > $testroot/stdout.expected
1066 0160a755 2019-07-25 stsp echo "Switching work tree to refs/heads/master" \
1067 0160a755 2019-07-25 stsp >> $testroot/stdout.expected
1068 0160a755 2019-07-25 stsp
1069 0ebf8283 2019-07-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1070 fc414659 2022-04-16 thomas ret=$?
1071 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1072 0ebf8283 2019-07-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
1073 0160a755 2019-07-25 stsp test_done "$testroot" "$ret"
1074 0160a755 2019-07-25 stsp return 1
1075 0ebf8283 2019-07-24 stsp fi
1076 0160a755 2019-07-25 stsp
1077 0160a755 2019-07-25 stsp echo "zeta" > $testroot/content.expected
1078 0160a755 2019-07-25 stsp cat $testroot/wt/zeta > $testroot/content
1079 0160a755 2019-07-25 stsp cmp -s $testroot/content.expected $testroot/content
1080 fc414659 2022-04-16 thomas ret=$?
1081 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1082 0160a755 2019-07-25 stsp diff -u $testroot/content.expected $testroot/content
1083 0160a755 2019-07-25 stsp test_done "$testroot" "$ret"
1084 0160a755 2019-07-25 stsp return 1
1085 0160a755 2019-07-25 stsp fi
1086 0160a755 2019-07-25 stsp
1087 0160a755 2019-07-25 stsp
1088 0160a755 2019-07-25 stsp (cd $testroot/wt && got status > $testroot/stdout)
1089 0160a755 2019-07-25 stsp
1090 0160a755 2019-07-25 stsp echo -n > $testroot/stdout.expected
1091 0160a755 2019-07-25 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1092 fc414659 2022-04-16 thomas ret=$?
1093 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1094 0160a755 2019-07-25 stsp diff -u $testroot/stdout.expected $testroot/stdout
1095 0160a755 2019-07-25 stsp test_done "$testroot" "$ret"
1096 0160a755 2019-07-25 stsp return 1
1097 0160a755 2019-07-25 stsp fi
1098 0160a755 2019-07-25 stsp
1099 0160a755 2019-07-25 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1100 0160a755 2019-07-25 stsp echo "commit $orig_commit (master)" > $testroot/stdout.expected
1101 b2c50a0a 2019-07-25 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1102 fc414659 2022-04-16 thomas ret=$?
1103 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1104 b2c50a0a 2019-07-25 stsp diff -u $testroot/stdout.expected $testroot/stdout
1105 b2c50a0a 2019-07-25 stsp fi
1106 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
1107 b2c50a0a 2019-07-25 stsp }
1108 b2c50a0a 2019-07-25 stsp
1109 f6cae3ed 2020-09-13 naddy test_histedit_path_prefix_edit() {
1110 b2c50a0a 2019-07-25 stsp local testroot=`test_init histedit_path_prefix_edit`
1111 b2c50a0a 2019-07-25 stsp local orig_commit=`git_show_head $testroot/repo`
1112 b2c50a0a 2019-07-25 stsp
1113 b2c50a0a 2019-07-25 stsp echo "modified zeta" > $testroot/repo/epsilon/zeta
1114 b2c50a0a 2019-07-25 stsp git_commit $testroot/repo -m "changing zeta"
1115 b2c50a0a 2019-07-25 stsp local old_commit1=`git_show_head $testroot/repo`
1116 b2c50a0a 2019-07-25 stsp
1117 b2c50a0a 2019-07-25 stsp got diff -r $testroot/repo $orig_commit $old_commit1 \
1118 b2c50a0a 2019-07-25 stsp > $testroot/diff.expected
1119 b2c50a0a 2019-07-25 stsp
1120 b2c50a0a 2019-07-25 stsp got checkout -c $orig_commit -p gamma $testroot/repo \
1121 b2c50a0a 2019-07-25 stsp $testroot/wt > /dev/null
1122 fc414659 2022-04-16 thomas ret=$?
1123 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1124 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
1125 b2c50a0a 2019-07-25 stsp return 1
1126 b2c50a0a 2019-07-25 stsp fi
1127 b2c50a0a 2019-07-25 stsp
1128 b2c50a0a 2019-07-25 stsp echo "edit $old_commit1" > $testroot/histedit-script
1129 b2c50a0a 2019-07-25 stsp
1130 b2c50a0a 2019-07-25 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1131 b2c50a0a 2019-07-25 stsp > $testroot/stdout 2> $testroot/stderr)
1132 b2c50a0a 2019-07-25 stsp
1133 fc414659 2022-04-16 thomas ret=$?
1134 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1135 b2c50a0a 2019-07-25 stsp echo "histedit succeeded unexpectedly" >&2
1136 b2c50a0a 2019-07-25 stsp test_done "$testroot" "1"
1137 b2c50a0a 2019-07-25 stsp return 1
1138 b2c50a0a 2019-07-25 stsp fi
1139 b2c50a0a 2019-07-25 stsp
1140 b2c50a0a 2019-07-25 stsp echo -n "got: cannot edit branch history which contains changes " \
1141 b2c50a0a 2019-07-25 stsp > $testroot/stderr.expected
1142 b2c50a0a 2019-07-25 stsp echo "outside of this work tree's path prefix" \
1143 b2c50a0a 2019-07-25 stsp >> $testroot/stderr.expected
1144 b2c50a0a 2019-07-25 stsp
1145 b2c50a0a 2019-07-25 stsp cmp -s $testroot/stderr.expected $testroot/stderr
1146 fc414659 2022-04-16 thomas ret=$?
1147 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1148 b2c50a0a 2019-07-25 stsp diff -u $testroot/stderr.expected $testroot/stderr
1149 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
1150 b2c50a0a 2019-07-25 stsp return 1
1151 b2c50a0a 2019-07-25 stsp fi
1152 b2c50a0a 2019-07-25 stsp
1153 b2c50a0a 2019-07-25 stsp rm -rf $testroot/wt
1154 b2c50a0a 2019-07-25 stsp got checkout -c $orig_commit -p epsilon $testroot/repo \
1155 b2c50a0a 2019-07-25 stsp $testroot/wt > /dev/null
1156 fc414659 2022-04-16 thomas ret=$?
1157 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1158 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
1159 b2c50a0a 2019-07-25 stsp return 1
1160 b2c50a0a 2019-07-25 stsp fi
1161 b2c50a0a 2019-07-25 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1162 b2c50a0a 2019-07-25 stsp > $testroot/stdout)
1163 b2c50a0a 2019-07-25 stsp
1164 b2c50a0a 2019-07-25 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
1165 b2c50a0a 2019-07-25 stsp
1166 b2c50a0a 2019-07-25 stsp echo "G zeta" > $testroot/stdout.expected
1167 b2c50a0a 2019-07-25 stsp echo "Stopping histedit for amending commit $old_commit1" \
1168 b2c50a0a 2019-07-25 stsp >> $testroot/stdout.expected
1169 0160a755 2019-07-25 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1170 fc414659 2022-04-16 thomas ret=$?
1171 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1172 0160a755 2019-07-25 stsp diff -u $testroot/stdout.expected $testroot/stdout
1173 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
1174 b2c50a0a 2019-07-25 stsp return 1
1175 0160a755 2019-07-25 stsp fi
1176 b2c50a0a 2019-07-25 stsp
1177 b2c50a0a 2019-07-25 stsp echo "modified zeta" > $testroot/content.expected
1178 b2c50a0a 2019-07-25 stsp cat $testroot/wt/zeta > $testroot/content
1179 b2c50a0a 2019-07-25 stsp cmp -s $testroot/content.expected $testroot/content
1180 fc414659 2022-04-16 thomas ret=$?
1181 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1182 b2c50a0a 2019-07-25 stsp diff -u $testroot/content.expected $testroot/content
1183 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
1184 b2c50a0a 2019-07-25 stsp return 1
1185 b2c50a0a 2019-07-25 stsp fi
1186 b2c50a0a 2019-07-25 stsp
1187 b2c50a0a 2019-07-25 stsp (cd $testroot/wt && got status > $testroot/stdout)
1188 b2c50a0a 2019-07-25 stsp
1189 b2c50a0a 2019-07-25 stsp echo "M zeta"> $testroot/stdout.expected
1190 b2c50a0a 2019-07-25 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1191 fc414659 2022-04-16 thomas ret=$?
1192 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1193 b2c50a0a 2019-07-25 stsp diff -u $testroot/stdout.expected $testroot/stdout
1194 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
1195 b2c50a0a 2019-07-25 stsp return 1
1196 b2c50a0a 2019-07-25 stsp fi
1197 f52e24d8 2023-10-28 thomas
1198 f52e24d8 2023-10-28 thomas cat > $testroot/editor.sh <<EOF
1199 f52e24d8 2023-10-28 thomas #!/bin/sh
1200 f52e24d8 2023-10-28 thomas ed -s "\$1" <<-EOF
1201 f52e24d8 2023-10-28 thomas ,s/.*/modified zeta/
1202 f52e24d8 2023-10-28 thomas w
1203 f52e24d8 2023-10-28 thomas EOF
1204 f52e24d8 2023-10-28 thomas EOF
1205 f52e24d8 2023-10-28 thomas chmod +x $testroot/editor.sh
1206 b2c50a0a 2019-07-25 stsp
1207 f52e24d8 2023-10-28 thomas (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1208 f52e24d8 2023-10-28 thomas VISUAL="$testroot/editor.sh" \
1209 f52e24d8 2023-10-28 thomas got histedit -c > $testroot/stdout)
1210 b2c50a0a 2019-07-25 stsp
1211 b2c50a0a 2019-07-25 stsp local new_commit1=`git_show_head $testroot/repo`
1212 b2c50a0a 2019-07-25 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
1213 b2c50a0a 2019-07-25 stsp
1214 b2c50a0a 2019-07-25 stsp echo -n "$short_old_commit1 -> $short_new_commit1: " \
1215 b2c50a0a 2019-07-25 stsp > $testroot/stdout.expected
1216 b2c50a0a 2019-07-25 stsp echo "modified zeta" >> $testroot/stdout.expected
1217 b2c50a0a 2019-07-25 stsp echo "Switching work tree to refs/heads/master" \
1218 b2c50a0a 2019-07-25 stsp >> $testroot/stdout.expected
1219 b2c50a0a 2019-07-25 stsp
1220 b2c50a0a 2019-07-25 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1221 fc414659 2022-04-16 thomas ret=$?
1222 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1223 b2c50a0a 2019-07-25 stsp diff -u $testroot/stdout.expected $testroot/stdout
1224 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
1225 b2c50a0a 2019-07-25 stsp return 1
1226 b2c50a0a 2019-07-25 stsp fi
1227 b2c50a0a 2019-07-25 stsp
1228 b2c50a0a 2019-07-25 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1229 b2c50a0a 2019-07-25 stsp echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1230 b2c50a0a 2019-07-25 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
1231 b2c50a0a 2019-07-25 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1232 fc414659 2022-04-16 thomas ret=$?
1233 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1234 b2c50a0a 2019-07-25 stsp diff -u $testroot/stdout.expected $testroot/stdout
1235 b2c50a0a 2019-07-25 stsp test_done "$testroot" "$ret"
1236 b2c50a0a 2019-07-25 stsp return 1
1237 b2c50a0a 2019-07-25 stsp fi
1238 b2c50a0a 2019-07-25 stsp
1239 b2c50a0a 2019-07-25 stsp got diff -r $testroot/repo $orig_commit $new_commit1 \
1240 b2c50a0a 2019-07-25 stsp > $testroot/diff
1241 ac3cdf31 2023-03-06 thomas ed -s $testroot/diff.expected <<-EOF
1242 ac3cdf31 2023-03-06 thomas ,s/$old_commit1/$new_commit1/
1243 ac3cdf31 2023-03-06 thomas w
1244 ac3cdf31 2023-03-06 thomas EOF
1245 b2c50a0a 2019-07-25 stsp cmp -s $testroot/diff.expected $testroot/diff
1246 fc414659 2022-04-16 thomas ret=$?
1247 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1248 b2c50a0a 2019-07-25 stsp diff -u $testroot/diff.expected $testroot/diff
1249 b2c50a0a 2019-07-25 stsp fi
1250 0ebf8283 2019-07-24 stsp test_done "$testroot" "$ret"
1251 0ebf8283 2019-07-24 stsp }
1252 c7d20a3f 2019-07-30 stsp
1253 f6cae3ed 2020-09-13 naddy test_histedit_outside_refs_heads() {
1254 c7d20a3f 2019-07-30 stsp local testroot=`test_init histedit_outside_refs_heads`
1255 c7d20a3f 2019-07-30 stsp local commit1=`git_show_head $testroot/repo`
1256 c7d20a3f 2019-07-30 stsp
1257 c7d20a3f 2019-07-30 stsp got checkout $testroot/repo $testroot/wt > /dev/null
1258 fc414659 2022-04-16 thomas ret=$?
1259 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1260 c7d20a3f 2019-07-30 stsp echo "got checkout failed unexpectedly"
1261 c7d20a3f 2019-07-30 stsp test_done "$testroot" "$ret"
1262 c7d20a3f 2019-07-30 stsp return 1
1263 c7d20a3f 2019-07-30 stsp fi
1264 c7d20a3f 2019-07-30 stsp
1265 c7d20a3f 2019-07-30 stsp echo "modified alpha" > $testroot/wt/alpha
1266 c7d20a3f 2019-07-30 stsp
1267 c7d20a3f 2019-07-30 stsp (cd $testroot/wt && got commit -m 'change alpha' \
1268 c7d20a3f 2019-07-30 stsp > $testroot/stdout 2> $testroot/stderr)
1269 fc414659 2022-04-16 thomas ret=$?
1270 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1271 c7d20a3f 2019-07-30 stsp echo "got commit failed unexpectedly" >&2
1272 c7d20a3f 2019-07-30 stsp test_done "$testroot" "1"
1273 c7d20a3f 2019-07-30 stsp return 1
1274 c7d20a3f 2019-07-30 stsp fi
1275 c7d20a3f 2019-07-30 stsp local commit2=`git_show_head $testroot/repo`
1276 0ebf8283 2019-07-24 stsp
1277 e31abbf2 2020-03-22 stsp got ref -r $testroot/repo -c master refs/remotes/origin/master
1278 fc414659 2022-04-16 thomas ret=$?
1279 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1280 c7d20a3f 2019-07-30 stsp echo "got ref failed unexpectedly" >&2
1281 c7d20a3f 2019-07-30 stsp test_done "$testroot" "1"
1282 c7d20a3f 2019-07-30 stsp return 1
1283 c7d20a3f 2019-07-30 stsp fi
1284 c7d20a3f 2019-07-30 stsp
1285 c7d20a3f 2019-07-30 stsp (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1286 fc414659 2022-04-16 thomas ret=$?
1287 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1288 c7d20a3f 2019-07-30 stsp echo "got update failed unexpectedly"
1289 c7d20a3f 2019-07-30 stsp test_done "$testroot" "$ret"
1290 c7d20a3f 2019-07-30 stsp return 1
1291 c7d20a3f 2019-07-30 stsp fi
1292 c7d20a3f 2019-07-30 stsp
1293 c7d20a3f 2019-07-30 stsp echo "edit $commit2" > $testroot/histedit-script
1294 c7d20a3f 2019-07-30 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1295 c7d20a3f 2019-07-30 stsp 2> $testroot/stderr)
1296 c7d20a3f 2019-07-30 stsp
1297 c7d20a3f 2019-07-30 stsp echo -n "got: will not edit commit history of a branch outside the " \
1298 c7d20a3f 2019-07-30 stsp > $testroot/stderr.expected
1299 c7d20a3f 2019-07-30 stsp echo '"refs/heads/" reference namespace' \
1300 c7d20a3f 2019-07-30 stsp >> $testroot/stderr.expected
1301 c7d20a3f 2019-07-30 stsp cmp -s $testroot/stderr.expected $testroot/stderr
1302 fc414659 2022-04-16 thomas ret=$?
1303 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1304 c7d20a3f 2019-07-30 stsp diff -u $testroot/stderr.expected $testroot/stderr
1305 0def28b1 2019-08-17 stsp fi
1306 0def28b1 2019-08-17 stsp test_done "$testroot" "$ret"
1307 0def28b1 2019-08-17 stsp }
1308 0def28b1 2019-08-17 stsp
1309 f6cae3ed 2020-09-13 naddy test_histedit_fold_last_commit_swap() {
1310 0def28b1 2019-08-17 stsp local testroot=`test_init histedit_fold_last_commit_swap`
1311 0def28b1 2019-08-17 stsp
1312 0def28b1 2019-08-17 stsp local orig_commit=`git_show_head $testroot/repo`
1313 0def28b1 2019-08-17 stsp
1314 0def28b1 2019-08-17 stsp echo "modified alpha on master" > $testroot/repo/alpha
1315 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
1316 0def28b1 2019-08-17 stsp echo "new file on master" > $testroot/repo/epsilon/new
1317 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
1318 0def28b1 2019-08-17 stsp git_commit $testroot/repo -m "committing changes"
1319 0def28b1 2019-08-17 stsp local old_commit1=`git_show_head $testroot/repo`
1320 0def28b1 2019-08-17 stsp
1321 0def28b1 2019-08-17 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1322 0def28b1 2019-08-17 stsp git_commit $testroot/repo -m "committing to zeta on master"
1323 0def28b1 2019-08-17 stsp local old_commit2=`git_show_head $testroot/repo`
1324 0def28b1 2019-08-17 stsp
1325 0def28b1 2019-08-17 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1326 fc414659 2022-04-16 thomas ret=$?
1327 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1328 0def28b1 2019-08-17 stsp test_done "$testroot" "$ret"
1329 0def28b1 2019-08-17 stsp return 1
1330 0def28b1 2019-08-17 stsp fi
1331 0def28b1 2019-08-17 stsp
1332 f52e24d8 2023-10-28 thomas cat > $testroot/editor.sh <<EOF
1333 f52e24d8 2023-10-28 thomas #!/bin/sh
1334 f52e24d8 2023-10-28 thomas ed -s "\$1" <<-EOF
1335 f52e24d8 2023-10-28 thomas ,s/.*/committing folded changes/
1336 f52e24d8 2023-10-28 thomas w
1337 f52e24d8 2023-10-28 thomas EOF
1338 f52e24d8 2023-10-28 thomas EOF
1339 f52e24d8 2023-10-28 thomas chmod +x $testroot/editor.sh
1340 f52e24d8 2023-10-28 thomas
1341 0def28b1 2019-08-17 stsp # fold commit2 into commit1 (requires swapping commits)
1342 0def28b1 2019-08-17 stsp echo "fold $old_commit2" > $testroot/histedit-script
1343 f52e24d8 2023-10-28 thomas echo "mesg $old_commit1" >> $testroot/histedit-script
1344 0def28b1 2019-08-17 stsp
1345 f52e24d8 2023-10-28 thomas (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1346 f52e24d8 2023-10-28 thomas VISUAL="$testroot/editor.sh" \
1347 f52e24d8 2023-10-28 thomas got histedit -F $testroot/histedit-script > $testroot/stdout \
1348 f52e24d8 2023-10-28 thomas 2> $testroot/stderr)
1349 0def28b1 2019-08-17 stsp
1350 fc414659 2022-04-16 thomas ret=$?
1351 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1352 0def28b1 2019-08-17 stsp echo "histedit failed unexpectedly" >&2
1353 0def28b1 2019-08-17 stsp test_done "$testroot" "$ret"
1354 0def28b1 2019-08-17 stsp return 1
1355 c7d20a3f 2019-07-30 stsp fi
1356 0def28b1 2019-08-17 stsp
1357 0def28b1 2019-08-17 stsp local new_commit=`git_show_head $testroot/repo`
1358 0def28b1 2019-08-17 stsp
1359 0def28b1 2019-08-17 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
1360 0def28b1 2019-08-17 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
1361 0def28b1 2019-08-17 stsp local short_new_commit=`trim_obj_id 28 $new_commit`
1362 0def28b1 2019-08-17 stsp
1363 0def28b1 2019-08-17 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
1364 0def28b1 2019-08-17 stsp echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1365 0def28b1 2019-08-17 stsp >> $testroot/stdout.expected
1366 0def28b1 2019-08-17 stsp echo "on master" >> $testroot/stdout.expected
1367 0def28b1 2019-08-17 stsp echo "G alpha" >> $testroot/stdout.expected
1368 0def28b1 2019-08-17 stsp echo "D beta" >> $testroot/stdout.expected
1369 0def28b1 2019-08-17 stsp echo "A epsilon/new" >> $testroot/stdout.expected
1370 0def28b1 2019-08-17 stsp echo -n "$short_old_commit1 -> $short_new_commit: " \
1371 0def28b1 2019-08-17 stsp >> $testroot/stdout.expected
1372 0def28b1 2019-08-17 stsp echo "committing folded changes" >> $testroot/stdout.expected
1373 0def28b1 2019-08-17 stsp echo "Switching work tree to refs/heads/master" \
1374 0def28b1 2019-08-17 stsp >> $testroot/stdout.expected
1375 0def28b1 2019-08-17 stsp
1376 0def28b1 2019-08-17 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1377 fc414659 2022-04-16 thomas ret=$?
1378 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1379 0def28b1 2019-08-17 stsp diff -u $testroot/stdout.expected $testroot/stdout
1380 0def28b1 2019-08-17 stsp fi
1381 c7d20a3f 2019-07-30 stsp test_done "$testroot" "$ret"
1382 c7d20a3f 2019-07-30 stsp }
1383 de05890f 2020-03-05 stsp
1384 f6cae3ed 2020-09-13 naddy test_histedit_split_commit() {
1385 de05890f 2020-03-05 stsp local testroot=`test_init histedit_split_commit`
1386 de05890f 2020-03-05 stsp
1387 de05890f 2020-03-05 stsp local orig_commit=`git_show_head $testroot/repo`
1388 de05890f 2020-03-05 stsp
1389 de05890f 2020-03-05 stsp echo "modified alpha on master" > $testroot/repo/alpha
1390 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
1391 de05890f 2020-03-05 stsp echo "new file on master" > $testroot/repo/epsilon/new
1392 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
1393 de05890f 2020-03-05 stsp git_commit $testroot/repo -m "committing changes 1"
1394 de05890f 2020-03-05 stsp local old_commit1=`git_show_head $testroot/repo`
1395 de05890f 2020-03-05 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
1396 de05890f 2020-03-05 stsp
1397 de05890f 2020-03-05 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1398 de05890f 2020-03-05 stsp git_commit $testroot/repo -m "committing changes 2"
1399 de05890f 2020-03-05 stsp local old_commit2=`git_show_head $testroot/repo`
1400 de05890f 2020-03-05 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
1401 c7d20a3f 2019-07-30 stsp
1402 de05890f 2020-03-05 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1403 fc414659 2022-04-16 thomas ret=$?
1404 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1405 de05890f 2020-03-05 stsp test_done "$testroot" "$ret"
1406 de05890f 2020-03-05 stsp return 1
1407 de05890f 2020-03-05 stsp fi
1408 de05890f 2020-03-05 stsp
1409 de05890f 2020-03-05 stsp # split commit1 into commitA and commitB and commitC
1410 de05890f 2020-03-05 stsp echo "e $old_commit1" > $testroot/histedit-script
1411 de05890f 2020-03-05 stsp echo "p $old_commit2" >> $testroot/histedit-script
1412 de05890f 2020-03-05 stsp
1413 de05890f 2020-03-05 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1414 de05890f 2020-03-05 stsp > $testroot/stdout 2> $testroot/stderr)
1415 fc414659 2022-04-16 thomas ret=$?
1416 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1417 de05890f 2020-03-05 stsp echo "histedit failed unexpectedly:" >&2
1418 de05890f 2020-03-05 stsp cat $testroot/stderr >&2
1419 de05890f 2020-03-05 stsp test_done "$testroot" "$ret"
1420 de05890f 2020-03-05 stsp return 1
1421 de05890f 2020-03-05 stsp fi
1422 de05890f 2020-03-05 stsp
1423 de05890f 2020-03-05 stsp echo "G alpha" > $testroot/stdout.expected
1424 de05890f 2020-03-05 stsp echo "D beta" >> $testroot/stdout.expected
1425 de05890f 2020-03-05 stsp echo "A epsilon/new" >> $testroot/stdout.expected
1426 de05890f 2020-03-05 stsp echo "Stopping histedit for amending commit $old_commit1" \
1427 de05890f 2020-03-05 stsp >> $testroot/stdout.expected
1428 de05890f 2020-03-05 stsp
1429 de05890f 2020-03-05 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1430 fc414659 2022-04-16 thomas ret=$?
1431 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1432 de05890f 2020-03-05 stsp diff -u $testroot/stdout.expected $testroot/stdout
1433 de05890f 2020-03-05 stsp test_done "$testroot" "$ret"
1434 de05890f 2020-03-05 stsp return 1
1435 de05890f 2020-03-05 stsp fi
1436 de05890f 2020-03-05 stsp
1437 de05890f 2020-03-05 stsp (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
1438 fc414659 2022-04-16 thomas ret=$?
1439 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1440 de05890f 2020-03-05 stsp echo "commit failed unexpectedly" >&2
1441 de05890f 2020-03-05 stsp test_done "$testroot" "$ret"
1442 de05890f 2020-03-05 stsp return 1
1443 de05890f 2020-03-05 stsp fi
1444 de05890f 2020-03-05 stsp
1445 de05890f 2020-03-05 stsp (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
1446 fc414659 2022-04-16 thomas ret=$?
1447 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1448 de05890f 2020-03-05 stsp echo "commit failed unexpectedly" >&2
1449 de05890f 2020-03-05 stsp test_done "$testroot" "$ret"
1450 de05890f 2020-03-05 stsp return 1
1451 de05890f 2020-03-05 stsp fi
1452 de05890f 2020-03-05 stsp
1453 de05890f 2020-03-05 stsp (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
1454 fc414659 2022-04-16 thomas ret=$?
1455 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1456 de05890f 2020-03-05 stsp echo "commit failed unexpectedly" >&2
1457 de05890f 2020-03-05 stsp test_done "$testroot" "$ret"
1458 de05890f 2020-03-05 stsp return 1
1459 de05890f 2020-03-05 stsp fi
1460 de05890f 2020-03-05 stsp
1461 de05890f 2020-03-05 stsp (cd $testroot/wt && got histedit -c \
1462 de05890f 2020-03-05 stsp > $testroot/stdout 2> $testroot/stderr)
1463 fc414659 2022-04-16 thomas ret=$?
1464 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1465 de05890f 2020-03-05 stsp echo "histedit failed unexpectedly:" >&2
1466 de05890f 2020-03-05 stsp cat $testroot/stderr >&2
1467 de05890f 2020-03-05 stsp test_done "$testroot" "$ret"
1468 de05890f 2020-03-05 stsp return 1
1469 de05890f 2020-03-05 stsp fi
1470 de05890f 2020-03-05 stsp local new_commit2=`git_show_head $testroot/repo`
1471 de05890f 2020-03-05 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
1472 de05890f 2020-03-05 stsp
1473 de05890f 2020-03-05 stsp echo "$short_old_commit1 -> no-op change: committing changes 1" \
1474 de05890f 2020-03-05 stsp > $testroot/stdout.expected
1475 de05890f 2020-03-05 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
1476 de05890f 2020-03-05 stsp echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1477 de05890f 2020-03-05 stsp >> $testroot/stdout.expected
1478 de05890f 2020-03-05 stsp echo "Switching work tree to refs/heads/master" \
1479 de05890f 2020-03-05 stsp >> $testroot/stdout.expected
1480 de05890f 2020-03-05 stsp
1481 de05890f 2020-03-05 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1482 fc414659 2022-04-16 thomas ret=$?
1483 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1484 de05890f 2020-03-05 stsp diff -u $testroot/stdout.expected $testroot/stdout
1485 5b87815e 2020-03-05 stsp fi
1486 5b87815e 2020-03-05 stsp test_done "$testroot" "$ret"
1487 5b87815e 2020-03-05 stsp
1488 5b87815e 2020-03-05 stsp }
1489 5b87815e 2020-03-05 stsp
1490 f6cae3ed 2020-09-13 naddy test_histedit_duplicate_commit_in_script() {
1491 5b87815e 2020-03-05 stsp local testroot=`test_init histedit_duplicate_commit_in_script`
1492 5b87815e 2020-03-05 stsp
1493 5b87815e 2020-03-05 stsp local orig_commit=`git_show_head $testroot/repo`
1494 5b87815e 2020-03-05 stsp
1495 5b87815e 2020-03-05 stsp echo "modified alpha on master" > $testroot/repo/alpha
1496 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
1497 5b87815e 2020-03-05 stsp echo "new file on master" > $testroot/repo/epsilon/new
1498 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
1499 5b87815e 2020-03-05 stsp git_commit $testroot/repo -m "committing changes 1"
1500 5b87815e 2020-03-05 stsp local old_commit1=`git_show_head $testroot/repo`
1501 5b87815e 2020-03-05 stsp
1502 5b87815e 2020-03-05 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1503 5b87815e 2020-03-05 stsp git_commit $testroot/repo -m "committing changes 2"
1504 5b87815e 2020-03-05 stsp local old_commit2=`git_show_head $testroot/repo`
1505 5b87815e 2020-03-05 stsp
1506 5b87815e 2020-03-05 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1507 fc414659 2022-04-16 thomas ret=$?
1508 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1509 5b87815e 2020-03-05 stsp test_done "$testroot" "$ret"
1510 5b87815e 2020-03-05 stsp return 1
1511 5b87815e 2020-03-05 stsp fi
1512 5b87815e 2020-03-05 stsp
1513 5b87815e 2020-03-05 stsp # This histedit script lists commit1 more than once
1514 5b87815e 2020-03-05 stsp echo "p $old_commit1" > $testroot/histedit-script
1515 5b87815e 2020-03-05 stsp echo "p $old_commit1" >> $testroot/histedit-script
1516 5b87815e 2020-03-05 stsp echo "p $old_commit2" >> $testroot/histedit-script
1517 5b87815e 2020-03-05 stsp
1518 5b87815e 2020-03-05 stsp (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1519 5b87815e 2020-03-05 stsp > $testroot/stdout 2> $testroot/stderr)
1520 fc414659 2022-04-16 thomas ret=$?
1521 fc414659 2022-04-16 thomas if [ $ret -eq 0 ]; then
1522 5b87815e 2020-03-05 stsp echo "histedit succeeded unexpectedly:" >&2
1523 5b87815e 2020-03-05 stsp cat $testroot/stdout >&2
1524 0b477035 2023-06-22 thomas test_done "$testroot" 1
1525 5b87815e 2020-03-05 stsp return 1
1526 de05890f 2020-03-05 stsp fi
1527 5b87815e 2020-03-05 stsp
1528 5b87815e 2020-03-05 stsp echo -n "got: commit $old_commit1 is listed more than once " \
1529 5b87815e 2020-03-05 stsp > $testroot/stderr.expected
1530 5b87815e 2020-03-05 stsp echo "in histedit script" >> $testroot/stderr.expected
1531 5b87815e 2020-03-05 stsp
1532 5b87815e 2020-03-05 stsp cmp -s $testroot/stderr.expected $testroot/stderr
1533 fc414659 2022-04-16 thomas ret=$?
1534 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1535 5b87815e 2020-03-05 stsp diff -u $testroot/stderr.expected $testroot/stderr
1536 5b87815e 2020-03-05 stsp fi
1537 de05890f 2020-03-05 stsp test_done "$testroot" "$ret"
1538 de05890f 2020-03-05 stsp
1539 de05890f 2020-03-05 stsp }
1540 ecfff807 2020-09-23 stsp
1541 ecfff807 2020-09-23 stsp # if a previous commit introduces a new file, and it is folded into a commit
1542 ecfff807 2020-09-23 stsp # that deletes the same file, the file still exists after the histedit
1543 ecfff807 2020-09-23 stsp test_histedit_fold_add_delete() {
1544 4c662b1d 2021-09-01 stsp local testroot=`test_init histedit_fold_add_delete`
1545 ecfff807 2020-09-23 stsp
1546 ecfff807 2020-09-23 stsp local orig_commit=`git_show_head $testroot/repo`
1547 ecfff807 2020-09-23 stsp
1548 ecfff807 2020-09-23 stsp echo "added new file epsilon/psi" > $testroot/repo/epsilon/psi
1549 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/psi
1550 ecfff807 2020-09-23 stsp git_commit $testroot/repo -m "committing changes"
1551 ecfff807 2020-09-23 stsp local old_commit1=`git_show_head $testroot/repo`
1552 ecfff807 2020-09-23 stsp
1553 ecfff807 2020-09-23 stsp echo "modified epsilon/psi" > $testroot/repo/epsilon/psi
1554 ecfff807 2020-09-23 stsp git_commit $testroot/repo -m "editing psi"
1555 ecfff807 2020-09-23 stsp local old_commit2=`git_show_head $testroot/repo`
1556 ecfff807 2020-09-23 stsp
1557 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q epsilon/psi
1558 ecfff807 2020-09-23 stsp git_commit $testroot/repo -m "removing psi"
1559 ecfff807 2020-09-23 stsp local old_commit3=`git_show_head $testroot/repo`
1560 ecfff807 2020-09-23 stsp
1561 ecfff807 2020-09-23 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1562 fc414659 2022-04-16 thomas ret=$?
1563 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1564 ecfff807 2020-09-23 stsp test_done "$testroot" "$ret"
1565 ecfff807 2020-09-23 stsp return 1
1566 ecfff807 2020-09-23 stsp fi
1567 de05890f 2020-03-05 stsp
1568 f52e24d8 2023-10-28 thomas cat > $testroot/editor.sh <<EOF
1569 f52e24d8 2023-10-28 thomas #!/bin/sh
1570 f52e24d8 2023-10-28 thomas ed -s "\$1" <<-EOF
1571 f52e24d8 2023-10-28 thomas ,s/.*/folded changes/
1572 f52e24d8 2023-10-28 thomas w
1573 f52e24d8 2023-10-28 thomas EOF
1574 f52e24d8 2023-10-28 thomas EOF
1575 f52e24d8 2023-10-28 thomas chmod +x $testroot/editor.sh
1576 f52e24d8 2023-10-28 thomas
1577 ecfff807 2020-09-23 stsp echo "fold $old_commit1" > $testroot/histedit-script
1578 ecfff807 2020-09-23 stsp echo "fold $old_commit2" >> $testroot/histedit-script
1579 ecfff807 2020-09-23 stsp echo "pick $old_commit3" >> $testroot/histedit-script
1580 ecfff807 2020-09-23 stsp
1581 f52e24d8 2023-10-28 thomas (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1582 f52e24d8 2023-10-28 thomas VISUAL="$testroot/editor.sh" \
1583 f52e24d8 2023-10-28 thomas got histedit -F $testroot/histedit-script > $testroot/stdout)
1584 ecfff807 2020-09-23 stsp
1585 ecfff807 2020-09-23 stsp local new_commit1=`git_show_head $testroot/repo`
1586 ecfff807 2020-09-23 stsp
1587 ecfff807 2020-09-23 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
1588 ecfff807 2020-09-23 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
1589 ecfff807 2020-09-23 stsp local short_old_commit3=`trim_obj_id 28 $old_commit3`
1590 ecfff807 2020-09-23 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
1591 ecfff807 2020-09-23 stsp
1592 ecfff807 2020-09-23 stsp echo "A epsilon/psi" >> $testroot/stdout.expected
1593 ecfff807 2020-09-23 stsp echo "$short_old_commit1 -> fold commit: committing changes" \
1594 ecfff807 2020-09-23 stsp >> $testroot/stdout.expected
1595 ecfff807 2020-09-23 stsp echo "G epsilon/psi" >> $testroot/stdout.expected
1596 ecfff807 2020-09-23 stsp echo "$short_old_commit2 -> fold commit: editing psi" \
1597 ecfff807 2020-09-23 stsp >> $testroot/stdout.expected
1598 0a22ca1a 2020-09-23 stsp echo "D epsilon/psi" >> $testroot/stdout.expected
1599 0a22ca1a 2020-09-23 stsp echo "$short_old_commit3 -> no-op change: folded changes" \
1600 ecfff807 2020-09-23 stsp >> $testroot/stdout.expected
1601 ecfff807 2020-09-23 stsp echo "Switching work tree to refs/heads/master" \
1602 ecfff807 2020-09-23 stsp >> $testroot/stdout.expected
1603 ecfff807 2020-09-23 stsp
1604 ecfff807 2020-09-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1605 fc414659 2022-04-16 thomas ret=$?
1606 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1607 ecfff807 2020-09-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
1608 ecfff807 2020-09-23 stsp test_done "$testroot" "$ret"
1609 ecfff807 2020-09-23 stsp return 1
1610 ecfff807 2020-09-23 stsp fi
1611 ecfff807 2020-09-23 stsp
1612 ecfff807 2020-09-23 stsp if [ -e $testroot/wt/epsilon/psi ]; then
1613 0a22ca1a 2020-09-23 stsp echo "removed file psi still exists on disk" >&2
1614 0a22ca1a 2020-09-23 stsp test_done "$testroot" "1"
1615 ecfff807 2020-09-23 stsp return 1
1616 ecfff807 2020-09-23 stsp fi
1617 ecfff807 2020-09-23 stsp
1618 ecfff807 2020-09-23 stsp (cd $testroot/wt && got status > $testroot/stdout)
1619 ecfff807 2020-09-23 stsp
1620 ecfff807 2020-09-23 stsp echo -n > $testroot/stdout.expected
1621 ecfff807 2020-09-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1622 fc414659 2022-04-16 thomas ret=$?
1623 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1624 ecfff807 2020-09-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
1625 ecfff807 2020-09-23 stsp test_done "$testroot" "$ret"
1626 ecfff807 2020-09-23 stsp return 1
1627 ecfff807 2020-09-23 stsp fi
1628 ecfff807 2020-09-23 stsp
1629 ecfff807 2020-09-23 stsp (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1630 ecfff807 2020-09-23 stsp echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1631 29c68398 2020-09-24 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1632 fc414659 2022-04-16 thomas ret=$?
1633 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1634 29c68398 2020-09-24 stsp diff -u $testroot/stdout.expected $testroot/stdout
1635 29c68398 2020-09-24 stsp test_done "$testroot" "$ret"
1636 29c68398 2020-09-24 stsp return 1
1637 29c68398 2020-09-24 stsp fi
1638 29c68398 2020-09-24 stsp
1639 29c68398 2020-09-24 stsp got tree -r $testroot/repo epsilon > $testroot/stdout
1640 29c68398 2020-09-24 stsp echo "zeta" > $testroot/stdout.expected
1641 ecfff807 2020-09-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1642 fc414659 2022-04-16 thomas ret=$?
1643 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1644 ecfff807 2020-09-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
1645 99fe3033 2023-03-08 thomas fi
1646 99fe3033 2023-03-08 thomas test_done "$testroot" "$ret"
1647 99fe3033 2023-03-08 thomas }
1648 4c3671a9 2023-07-26 thomas
1649 4c3671a9 2023-07-26 thomas # if a previous commit edits a file, and it is folded into a commit
1650 4c3671a9 2023-07-26 thomas # that deletes the same file, the file will be deleted by histedit
1651 4c3671a9 2023-07-26 thomas test_histedit_fold_edit_delete() {
1652 4c3671a9 2023-07-26 thomas local testroot=`test_init histedit_fold_edit_delete`
1653 4c3671a9 2023-07-26 thomas
1654 4c3671a9 2023-07-26 thomas local orig_commit=`git_show_head $testroot/repo`
1655 4c3671a9 2023-07-26 thomas
1656 4c3671a9 2023-07-26 thomas echo "modify alpha" > $testroot/repo/alpha
1657 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add alpha
1658 4c3671a9 2023-07-26 thomas git_commit $testroot/repo -m "modified alpha"
1659 4c3671a9 2023-07-26 thomas local old_commit1=`git_show_head $testroot/repo`
1660 99fe3033 2023-03-08 thomas
1661 4c3671a9 2023-07-26 thomas git_rm $testroot/repo alpha
1662 4c3671a9 2023-07-26 thomas git_commit $testroot/repo -m "deleted alpha"
1663 4c3671a9 2023-07-26 thomas local old_commit2=`git_show_head $testroot/repo`
1664 4c3671a9 2023-07-26 thomas
1665 4c3671a9 2023-07-26 thomas got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1666 4c3671a9 2023-07-26 thomas ret=$?
1667 4c3671a9 2023-07-26 thomas if [ $ret -ne 0 ]; then
1668 4c3671a9 2023-07-26 thomas test_done "$testroot" "$ret"
1669 4c3671a9 2023-07-26 thomas return 1
1670 4c3671a9 2023-07-26 thomas fi
1671 4c3671a9 2023-07-26 thomas
1672 f52e24d8 2023-10-28 thomas cat > $testroot/editor.sh <<EOF
1673 f52e24d8 2023-10-28 thomas #!/bin/sh
1674 f52e24d8 2023-10-28 thomas ed -s "\$1" <<-EOF
1675 f52e24d8 2023-10-28 thomas ,s/.*/folded changes/
1676 f52e24d8 2023-10-28 thomas w
1677 f52e24d8 2023-10-28 thomas EOF
1678 f52e24d8 2023-10-28 thomas EOF
1679 f52e24d8 2023-10-28 thomas chmod +x $testroot/editor.sh
1680 f52e24d8 2023-10-28 thomas
1681 4c3671a9 2023-07-26 thomas echo "fold $old_commit1" > $testroot/histedit-script
1682 4c3671a9 2023-07-26 thomas echo "pick $old_commit2" >> $testroot/histedit-script
1683 4c3671a9 2023-07-26 thomas
1684 f52e24d8 2023-10-28 thomas (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1685 f52e24d8 2023-10-28 thomas VISUAL="$testroot/editor.sh" \
1686 f52e24d8 2023-10-28 thomas got histedit -F $testroot/histedit-script > $testroot/stdout)
1687 4c3671a9 2023-07-26 thomas
1688 4c3671a9 2023-07-26 thomas local new_commit1=`git_show_head $testroot/repo`
1689 4c3671a9 2023-07-26 thomas
1690 4c3671a9 2023-07-26 thomas local short_old_commit1=`trim_obj_id 28 $old_commit1`
1691 4c3671a9 2023-07-26 thomas local short_old_commit2=`trim_obj_id 28 $old_commit2`
1692 4c3671a9 2023-07-26 thomas local short_new_commit1=`trim_obj_id 28 $new_commit1`
1693 4c3671a9 2023-07-26 thomas
1694 4c3671a9 2023-07-26 thomas echo "G alpha" >> $testroot/stdout.expected
1695 4c3671a9 2023-07-26 thomas echo "$short_old_commit1 -> fold commit: modified alpha" \
1696 4c3671a9 2023-07-26 thomas >> $testroot/stdout.expected
1697 4c3671a9 2023-07-26 thomas echo "D alpha" >> $testroot/stdout.expected
1698 4c3671a9 2023-07-26 thomas echo "$short_old_commit2 -> $short_new_commit1: folded changes" \
1699 4c3671a9 2023-07-26 thomas >> $testroot/stdout.expected
1700 4c3671a9 2023-07-26 thomas echo "Switching work tree to refs/heads/master" \
1701 4c3671a9 2023-07-26 thomas >> $testroot/stdout.expected
1702 4c3671a9 2023-07-26 thomas
1703 4c3671a9 2023-07-26 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1704 4c3671a9 2023-07-26 thomas ret=$?
1705 4c3671a9 2023-07-26 thomas if [ $ret -ne 0 ]; then
1706 4c3671a9 2023-07-26 thomas diff -u $testroot/stdout.expected $testroot/stdout
1707 4c3671a9 2023-07-26 thomas test_done "$testroot" "$ret"
1708 4c3671a9 2023-07-26 thomas return 1
1709 4c3671a9 2023-07-26 thomas fi
1710 4c3671a9 2023-07-26 thomas
1711 4c3671a9 2023-07-26 thomas if [ -e $testroot/wt/alpha ]; then
1712 4c3671a9 2023-07-26 thomas echo "removed file alpha still exists on disk" >&2
1713 4c3671a9 2023-07-26 thomas test_done "$testroot" "1"
1714 4c3671a9 2023-07-26 thomas return 1
1715 4c3671a9 2023-07-26 thomas fi
1716 4c3671a9 2023-07-26 thomas
1717 4c3671a9 2023-07-26 thomas (cd $testroot/wt && got status > $testroot/stdout)
1718 4c3671a9 2023-07-26 thomas
1719 4c3671a9 2023-07-26 thomas echo -n > $testroot/stdout.expected
1720 4c3671a9 2023-07-26 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1721 4c3671a9 2023-07-26 thomas ret=$?
1722 4c3671a9 2023-07-26 thomas if [ $ret -ne 0 ]; then
1723 4c3671a9 2023-07-26 thomas diff -u $testroot/stdout.expected $testroot/stdout
1724 4c3671a9 2023-07-26 thomas test_done "$testroot" "$ret"
1725 4c3671a9 2023-07-26 thomas return 1
1726 4c3671a9 2023-07-26 thomas fi
1727 4c3671a9 2023-07-26 thomas
1728 4c3671a9 2023-07-26 thomas (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
1729 4c3671a9 2023-07-26 thomas echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1730 4c3671a9 2023-07-26 thomas echo "commit $orig_commit" >> $testroot/stdout.expected
1731 4c3671a9 2023-07-26 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1732 4c3671a9 2023-07-26 thomas ret=$?
1733 4c3671a9 2023-07-26 thomas if [ $ret -ne 0 ]; then
1734 4c3671a9 2023-07-26 thomas diff -u $testroot/stdout.expected $testroot/stdout
1735 4c3671a9 2023-07-26 thomas fi
1736 4c3671a9 2023-07-26 thomas
1737 4c3671a9 2023-07-26 thomas test_done "$testroot" "$ret"
1738 4c3671a9 2023-07-26 thomas }
1739 4c3671a9 2023-07-26 thomas
1740 99fe3033 2023-03-08 thomas test_histedit_fold_delete_add() {
1741 99fe3033 2023-03-08 thomas local testroot=`test_init histedit_fold_delete_add`
1742 99fe3033 2023-03-08 thomas
1743 99fe3033 2023-03-08 thomas local orig_commit=`git_show_head $testroot/repo`
1744 99fe3033 2023-03-08 thomas
1745 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q alpha
1746 99fe3033 2023-03-08 thomas git_commit $testroot/repo -m "removing alpha"
1747 99fe3033 2023-03-08 thomas local old_commit1=`git_show_head $testroot/repo`
1748 99fe3033 2023-03-08 thomas
1749 99fe3033 2023-03-08 thomas echo "modified alpha" >$testroot/repo/alpha
1750 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add alpha
1751 99fe3033 2023-03-08 thomas git_commit $testroot/repo -m "add back modified alpha"
1752 99fe3033 2023-03-08 thomas local old_commit2=`git_show_head $testroot/repo`
1753 99fe3033 2023-03-08 thomas
1754 99fe3033 2023-03-08 thomas got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1755 99fe3033 2023-03-08 thomas ret=$?
1756 99fe3033 2023-03-08 thomas if [ $ret -ne 0 ]; then
1757 99fe3033 2023-03-08 thomas test_done "$testroot" "$ret"
1758 99fe3033 2023-03-08 thomas return 1
1759 99fe3033 2023-03-08 thomas fi
1760 99fe3033 2023-03-08 thomas
1761 f52e24d8 2023-10-28 thomas cat > $testroot/editor.sh <<EOF
1762 f52e24d8 2023-10-28 thomas #!/bin/sh
1763 f52e24d8 2023-10-28 thomas ed -s "\$1" <<-EOF
1764 f52e24d8 2023-10-28 thomas ,s/.*/folded changes/
1765 f52e24d8 2023-10-28 thomas w
1766 f52e24d8 2023-10-28 thomas EOF
1767 f52e24d8 2023-10-28 thomas EOF
1768 f52e24d8 2023-10-28 thomas chmod +x $testroot/editor.sh
1769 f52e24d8 2023-10-28 thomas
1770 99fe3033 2023-03-08 thomas echo "fold $old_commit1" > $testroot/histedit-script
1771 99fe3033 2023-03-08 thomas echo "pick $old_commit2" >> $testroot/histedit-script
1772 f52e24d8 2023-10-28 thomas
1773 f52e24d8 2023-10-28 thomas (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1774 f52e24d8 2023-10-28 thomas VISUAL="$testroot/editor.sh" \
1775 f52e24d8 2023-10-28 thomas got histedit -F $testroot/histedit-script > $testroot/stdout)
1776 99fe3033 2023-03-08 thomas
1777 99fe3033 2023-03-08 thomas local new_commit1=`git_show_head $testroot/repo`
1778 99fe3033 2023-03-08 thomas
1779 99fe3033 2023-03-08 thomas local short_old_commit1=`trim_obj_id 28 $old_commit1`
1780 99fe3033 2023-03-08 thomas local short_old_commit2=`trim_obj_id 28 $old_commit2`
1781 99fe3033 2023-03-08 thomas local short_new_commit1=`trim_obj_id 28 $new_commit1`
1782 99fe3033 2023-03-08 thomas
1783 99fe3033 2023-03-08 thomas echo "D alpha" > $testroot/stdout.expected
1784 99fe3033 2023-03-08 thomas echo "$short_old_commit1 -> fold commit: removing alpha" \
1785 99fe3033 2023-03-08 thomas >> $testroot/stdout.expected
1786 99fe3033 2023-03-08 thomas echo "A alpha" >> $testroot/stdout.expected
1787 99fe3033 2023-03-08 thomas echo "$short_old_commit2 -> $short_new_commit1: folded changes" \
1788 99fe3033 2023-03-08 thomas >> $testroot/stdout.expected
1789 99fe3033 2023-03-08 thomas echo "Switching work tree to refs/heads/master" \
1790 99fe3033 2023-03-08 thomas >> $testroot/stdout.expected
1791 99fe3033 2023-03-08 thomas
1792 0529f8df 2023-03-10 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1793 0529f8df 2023-03-10 thomas ret=$?
1794 0529f8df 2023-03-10 thomas if [ $ret -ne 0 ]; then
1795 0529f8df 2023-03-10 thomas diff -u $testroot/stdout.expected $testroot/stdout
1796 0529f8df 2023-03-10 thomas test_done "$testroot" "$ret"
1797 0529f8df 2023-03-10 thomas return 1
1798 0529f8df 2023-03-10 thomas fi
1799 99fe3033 2023-03-08 thomas
1800 99fe3033 2023-03-08 thomas if [ ! -e $testroot/wt/alpha ]; then
1801 0529f8df 2023-03-10 thomas echo "file alpha is missing on disk" >&2
1802 0529f8df 2023-03-10 thomas test_done "$testroot" "1"
1803 0e5a098a 2023-03-14 thomas return 1
1804 0e5a098a 2023-03-14 thomas fi
1805 0e5a098a 2023-03-14 thomas
1806 0e5a098a 2023-03-14 thomas echo "modified alpha" > $testroot/content.expected
1807 0e5a098a 2023-03-14 thomas cat $testroot/wt/alpha > $testroot/content
1808 0e5a098a 2023-03-14 thomas cmp -s $testroot/content.expected $testroot/content
1809 0e5a098a 2023-03-14 thomas ret=$?
1810 0e5a098a 2023-03-14 thomas if [ $ret -ne 0 ]; then
1811 0e5a098a 2023-03-14 thomas diff -u $testroot/content.expected $testroot/content
1812 0e5a098a 2023-03-14 thomas test_done "$testroot" "$ret"
1813 0529f8df 2023-03-10 thomas return 1
1814 ecfff807 2020-09-23 stsp fi
1815 0529f8df 2023-03-10 thomas test_done "$testroot" "0"
1816 ecfff807 2020-09-23 stsp }
1817 239f5c5a 2020-12-13 stsp
1818 239f5c5a 2020-12-13 stsp test_histedit_fold_only() {
1819 239f5c5a 2020-12-13 stsp local testroot=`test_init histedit_fold_only`
1820 239f5c5a 2020-12-13 stsp
1821 239f5c5a 2020-12-13 stsp local orig_commit=`git_show_head $testroot/repo`
1822 239f5c5a 2020-12-13 stsp
1823 239f5c5a 2020-12-13 stsp echo "modified alpha on master" > $testroot/repo/alpha
1824 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
1825 239f5c5a 2020-12-13 stsp echo "new file on master" > $testroot/repo/epsilon/new
1826 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
1827 239f5c5a 2020-12-13 stsp git_commit $testroot/repo -m "committing changes"
1828 239f5c5a 2020-12-13 stsp local old_commit1=`git_show_head $testroot/repo`
1829 239f5c5a 2020-12-13 stsp
1830 239f5c5a 2020-12-13 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1831 239f5c5a 2020-12-13 stsp git_commit $testroot/repo -m "committing to zeta on master"
1832 239f5c5a 2020-12-13 stsp local old_commit2=`git_show_head $testroot/repo`
1833 239f5c5a 2020-12-13 stsp
1834 239f5c5a 2020-12-13 stsp echo "modified delta on master" > $testroot/repo/gamma/delta
1835 239f5c5a 2020-12-13 stsp git_commit $testroot/repo -m "committing to delta on master"
1836 239f5c5a 2020-12-13 stsp local old_commit3=`git_show_head $testroot/repo`
1837 239f5c5a 2020-12-13 stsp
1838 239f5c5a 2020-12-13 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1839 fc414659 2022-04-16 thomas ret=$?
1840 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1841 239f5c5a 2020-12-13 stsp test_done "$testroot" "$ret"
1842 239f5c5a 2020-12-13 stsp return 1
1843 239f5c5a 2020-12-13 stsp fi
1844 239f5c5a 2020-12-13 stsp
1845 239f5c5a 2020-12-13 stsp cat > $testroot/editor.sh <<EOF
1846 239f5c5a 2020-12-13 stsp #!/bin/sh
1847 ac3cdf31 2023-03-06 thomas ed -s "\$1" <<-EOF
1848 ac3cdf31 2023-03-06 thomas ,s/.*/committing folded changes/
1849 ac3cdf31 2023-03-06 thomas w
1850 ac3cdf31 2023-03-06 thomas EOF
1851 239f5c5a 2020-12-13 stsp EOF
1852 239f5c5a 2020-12-13 stsp chmod +x $testroot/editor.sh
1853 239f5c5a 2020-12-13 stsp
1854 239f5c5a 2020-12-13 stsp (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1855 239f5c5a 2020-12-13 stsp VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1856 239f5c5a 2020-12-13 stsp
1857 239f5c5a 2020-12-13 stsp local new_commit1=`git_show_head $testroot/repo`
1858 239f5c5a 2020-12-13 stsp
1859 239f5c5a 2020-12-13 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
1860 239f5c5a 2020-12-13 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
1861 239f5c5a 2020-12-13 stsp local short_old_commit3=`trim_obj_id 28 $old_commit3`
1862 239f5c5a 2020-12-13 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
1863 239f5c5a 2020-12-13 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
1864 239f5c5a 2020-12-13 stsp
1865 239f5c5a 2020-12-13 stsp echo "G alpha" > $testroot/stdout.expected
1866 239f5c5a 2020-12-13 stsp echo "D beta" >> $testroot/stdout.expected
1867 239f5c5a 2020-12-13 stsp echo "A epsilon/new" >> $testroot/stdout.expected
1868 239f5c5a 2020-12-13 stsp echo "$short_old_commit1 -> fold commit: committing changes" \
1869 239f5c5a 2020-12-13 stsp >> $testroot/stdout.expected
1870 239f5c5a 2020-12-13 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
1871 239f5c5a 2020-12-13 stsp echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1872 239f5c5a 2020-12-13 stsp echo "fold commit: committing to zeta on master" \
1873 239f5c5a 2020-12-13 stsp >> $testroot/stdout.expected
1874 239f5c5a 2020-12-13 stsp echo "G gamma/delta" >> $testroot/stdout.expected
1875 239f5c5a 2020-12-13 stsp echo -n "$short_old_commit3 -> $short_new_commit1: " \
1876 239f5c5a 2020-12-13 stsp >> $testroot/stdout.expected
1877 239f5c5a 2020-12-13 stsp echo "committing folded changes" >> $testroot/stdout.expected
1878 239f5c5a 2020-12-13 stsp echo "Switching work tree to refs/heads/master" \
1879 239f5c5a 2020-12-13 stsp >> $testroot/stdout.expected
1880 ecfff807 2020-09-23 stsp
1881 239f5c5a 2020-12-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1882 fc414659 2022-04-16 thomas ret=$?
1883 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1884 239f5c5a 2020-12-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
1885 239f5c5a 2020-12-13 stsp test_done "$testroot" "$ret"
1886 239f5c5a 2020-12-13 stsp return 1
1887 239f5c5a 2020-12-13 stsp fi
1888 ecfff807 2020-09-23 stsp
1889 239f5c5a 2020-12-13 stsp echo "modified alpha on master" > $testroot/content.expected
1890 239f5c5a 2020-12-13 stsp cat $testroot/wt/alpha > $testroot/content
1891 239f5c5a 2020-12-13 stsp cmp -s $testroot/content.expected $testroot/content
1892 fc414659 2022-04-16 thomas ret=$?
1893 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1894 239f5c5a 2020-12-13 stsp diff -u $testroot/content.expected $testroot/content
1895 239f5c5a 2020-12-13 stsp test_done "$testroot" "$ret"
1896 239f5c5a 2020-12-13 stsp return 1
1897 239f5c5a 2020-12-13 stsp fi
1898 239f5c5a 2020-12-13 stsp
1899 239f5c5a 2020-12-13 stsp if [ -e $testroot/wt/beta ]; then
1900 239f5c5a 2020-12-13 stsp echo "removed file beta still exists on disk" >&2
1901 239f5c5a 2020-12-13 stsp test_done "$testroot" "1"
1902 239f5c5a 2020-12-13 stsp return 1
1903 239f5c5a 2020-12-13 stsp fi
1904 239f5c5a 2020-12-13 stsp
1905 239f5c5a 2020-12-13 stsp echo "new file on master" > $testroot/content.expected
1906 239f5c5a 2020-12-13 stsp cat $testroot/wt/epsilon/new > $testroot/content
1907 239f5c5a 2020-12-13 stsp cmp -s $testroot/content.expected $testroot/content
1908 fc414659 2022-04-16 thomas ret=$?
1909 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1910 239f5c5a 2020-12-13 stsp diff -u $testroot/content.expected $testroot/content
1911 239f5c5a 2020-12-13 stsp test_done "$testroot" "$ret"
1912 239f5c5a 2020-12-13 stsp return 1
1913 239f5c5a 2020-12-13 stsp fi
1914 239f5c5a 2020-12-13 stsp
1915 239f5c5a 2020-12-13 stsp (cd $testroot/wt && got status > $testroot/stdout)
1916 239f5c5a 2020-12-13 stsp
1917 239f5c5a 2020-12-13 stsp echo -n > $testroot/stdout.expected
1918 239f5c5a 2020-12-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1919 fc414659 2022-04-16 thomas ret=$?
1920 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1921 239f5c5a 2020-12-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
1922 239f5c5a 2020-12-13 stsp test_done "$testroot" "$ret"
1923 239f5c5a 2020-12-13 stsp return 1
1924 239f5c5a 2020-12-13 stsp fi
1925 239f5c5a 2020-12-13 stsp
1926 239f5c5a 2020-12-13 stsp (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1927 239f5c5a 2020-12-13 stsp echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1928 239f5c5a 2020-12-13 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
1929 239f5c5a 2020-12-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
1930 fc414659 2022-04-16 thomas ret=$?
1931 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1932 239f5c5a 2020-12-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
1933 239f5c5a 2020-12-13 stsp fi
1934 239f5c5a 2020-12-13 stsp test_done "$testroot" "$ret"
1935 239f5c5a 2020-12-13 stsp }
1936 a347e6bb 2020-12-13 stsp
1937 a347e6bb 2020-12-13 stsp test_histedit_fold_only_empty_logmsg() {
1938 a347e6bb 2020-12-13 stsp local testroot=`test_init histedit_fold_only_empty_logmsg`
1939 a347e6bb 2020-12-13 stsp
1940 a347e6bb 2020-12-13 stsp local orig_commit=`git_show_head $testroot/repo`
1941 a347e6bb 2020-12-13 stsp
1942 a347e6bb 2020-12-13 stsp echo "modified alpha on master" > $testroot/repo/alpha
1943 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
1944 a347e6bb 2020-12-13 stsp echo "new file on master" > $testroot/repo/epsilon/new
1945 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
1946 a347e6bb 2020-12-13 stsp git_commit $testroot/repo -m "committing changes"
1947 a347e6bb 2020-12-13 stsp local old_commit1=`git_show_head $testroot/repo`
1948 239f5c5a 2020-12-13 stsp
1949 a347e6bb 2020-12-13 stsp echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1950 a347e6bb 2020-12-13 stsp git_commit $testroot/repo -m "committing to zeta on master"
1951 a347e6bb 2020-12-13 stsp local old_commit2=`git_show_head $testroot/repo`
1952 a347e6bb 2020-12-13 stsp
1953 a347e6bb 2020-12-13 stsp echo "modified delta on master" > $testroot/repo/gamma/delta
1954 a347e6bb 2020-12-13 stsp git_commit $testroot/repo -m "committing to delta on master"
1955 a347e6bb 2020-12-13 stsp local old_commit3=`git_show_head $testroot/repo`
1956 a347e6bb 2020-12-13 stsp
1957 a347e6bb 2020-12-13 stsp got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1958 fc414659 2022-04-16 thomas ret=$?
1959 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
1960 a347e6bb 2020-12-13 stsp test_done "$testroot" "$ret"
1961 a347e6bb 2020-12-13 stsp return 1
1962 a347e6bb 2020-12-13 stsp fi
1963 a347e6bb 2020-12-13 stsp
1964 a347e6bb 2020-12-13 stsp cat > $testroot/editor.sh <<EOF
1965 a347e6bb 2020-12-13 stsp #!/bin/sh
1966 ac3cdf31 2023-03-06 thomas ed -s "\$1" <<-EOF
1967 ac3cdf31 2023-03-06 thomas ,d
1968 ac3cdf31 2023-03-06 thomas w
1969 ac3cdf31 2023-03-06 thomas EOF
1970 a347e6bb 2020-12-13 stsp EOF
1971 a347e6bb 2020-12-13 stsp chmod +x $testroot/editor.sh
1972 a347e6bb 2020-12-13 stsp
1973 a347e6bb 2020-12-13 stsp (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1974 a347e6bb 2020-12-13 stsp VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1975 a347e6bb 2020-12-13 stsp
1976 a347e6bb 2020-12-13 stsp local new_commit1=`git_show_head $testroot/repo`
1977 a347e6bb 2020-12-13 stsp
1978 a347e6bb 2020-12-13 stsp local short_old_commit1=`trim_obj_id 28 $old_commit1`
1979 a347e6bb 2020-12-13 stsp local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1980 a347e6bb 2020-12-13 stsp local short_old_commit2=`trim_obj_id 28 $old_commit2`
1981 a347e6bb 2020-12-13 stsp local short_old_commit3=`trim_obj_id 28 $old_commit3`
1982 a347e6bb 2020-12-13 stsp local short_new_commit1=`trim_obj_id 28 $new_commit1`
1983 a347e6bb 2020-12-13 stsp local short_new_commit2=`trim_obj_id 28 $new_commit2`
1984 a347e6bb 2020-12-13 stsp
1985 a347e6bb 2020-12-13 stsp echo "G alpha" > $testroot/stdout.expected
1986 a347e6bb 2020-12-13 stsp echo "D beta" >> $testroot/stdout.expected
1987 a347e6bb 2020-12-13 stsp echo "A epsilon/new" >> $testroot/stdout.expected
1988 a347e6bb 2020-12-13 stsp echo "$short_old_commit1 -> fold commit: committing changes" \
1989 a347e6bb 2020-12-13 stsp >> $testroot/stdout.expected
1990 a347e6bb 2020-12-13 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
1991 a347e6bb 2020-12-13 stsp echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1992 a347e6bb 2020-12-13 stsp echo "fold commit: committing to zeta on master" \
1993 a347e6bb 2020-12-13 stsp >> $testroot/stdout.expected
1994 a347e6bb 2020-12-13 stsp echo "G gamma/delta" >> $testroot/stdout.expected
1995 a347e6bb 2020-12-13 stsp echo -n "$short_old_commit3 -> $short_new_commit1: " \
1996 a347e6bb 2020-12-13 stsp >> $testroot/stdout.expected
1997 a347e6bb 2020-12-13 stsp echo "# log message of folded commit $very_short_old_commit1" \
1998 a347e6bb 2020-12-13 stsp >> $testroot/stdout.expected
1999 a347e6bb 2020-12-13 stsp echo "Switching work tree to refs/heads/master" \
2000 a347e6bb 2020-12-13 stsp >> $testroot/stdout.expected
2001 a347e6bb 2020-12-13 stsp
2002 a347e6bb 2020-12-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
2003 fc414659 2022-04-16 thomas ret=$?
2004 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
2005 a347e6bb 2020-12-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
2006 a347e6bb 2020-12-13 stsp test_done "$testroot" "$ret"
2007 a347e6bb 2020-12-13 stsp return 1
2008 a347e6bb 2020-12-13 stsp fi
2009 a347e6bb 2020-12-13 stsp
2010 a347e6bb 2020-12-13 stsp echo "modified alpha on master" > $testroot/content.expected
2011 a347e6bb 2020-12-13 stsp cat $testroot/wt/alpha > $testroot/content
2012 a347e6bb 2020-12-13 stsp cmp -s $testroot/content.expected $testroot/content
2013 fc414659 2022-04-16 thomas ret=$?
2014 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
2015 a347e6bb 2020-12-13 stsp diff -u $testroot/content.expected $testroot/content
2016 a347e6bb 2020-12-13 stsp test_done "$testroot" "$ret"
2017 a347e6bb 2020-12-13 stsp return 1
2018 a347e6bb 2020-12-13 stsp fi
2019 a347e6bb 2020-12-13 stsp
2020 a347e6bb 2020-12-13 stsp if [ -e $testroot/wt/beta ]; then
2021 a347e6bb 2020-12-13 stsp echo "removed file beta still exists on disk" >&2
2022 a347e6bb 2020-12-13 stsp test_done "$testroot" "1"
2023 a347e6bb 2020-12-13 stsp return 1
2024 a347e6bb 2020-12-13 stsp fi
2025 a347e6bb 2020-12-13 stsp
2026 a347e6bb 2020-12-13 stsp echo "new file on master" > $testroot/content.expected
2027 a347e6bb 2020-12-13 stsp cat $testroot/wt/epsilon/new > $testroot/content
2028 a347e6bb 2020-12-13 stsp cmp -s $testroot/content.expected $testroot/content
2029 fc414659 2022-04-16 thomas ret=$?
2030 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
2031 a347e6bb 2020-12-13 stsp diff -u $testroot/content.expected $testroot/content
2032 a347e6bb 2020-12-13 stsp test_done "$testroot" "$ret"
2033 a347e6bb 2020-12-13 stsp return 1
2034 a347e6bb 2020-12-13 stsp fi
2035 a347e6bb 2020-12-13 stsp
2036 a347e6bb 2020-12-13 stsp (cd $testroot/wt && got status > $testroot/stdout)
2037 a347e6bb 2020-12-13 stsp
2038 a347e6bb 2020-12-13 stsp echo -n > $testroot/stdout.expected
2039 a347e6bb 2020-12-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
2040 fc414659 2022-04-16 thomas ret=$?
2041 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
2042 a347e6bb 2020-12-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
2043 a347e6bb 2020-12-13 stsp test_done "$testroot" "$ret"
2044 a347e6bb 2020-12-13 stsp return 1
2045 a347e6bb 2020-12-13 stsp fi
2046 a347e6bb 2020-12-13 stsp
2047 a347e6bb 2020-12-13 stsp (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
2048 a347e6bb 2020-12-13 stsp echo "commit $new_commit1 (master)" > $testroot/stdout.expected
2049 c50a7455 2021-10-04 thomas echo "commit $orig_commit" >> $testroot/stdout.expected
2050 c50a7455 2021-10-04 thomas cmp -s $testroot/stdout.expected $testroot/stdout
2051 fc414659 2022-04-16 thomas ret=$?
2052 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
2053 c50a7455 2021-10-04 thomas diff -u $testroot/stdout.expected $testroot/stdout
2054 c50a7455 2021-10-04 thomas fi
2055 c50a7455 2021-10-04 thomas test_done "$testroot" "$ret"
2056 c50a7455 2021-10-04 thomas }
2057 c50a7455 2021-10-04 thomas
2058 c50a7455 2021-10-04 thomas test_histedit_edit_only() {
2059 c50a7455 2021-10-04 thomas local testroot=`test_init histedit_edit_only`
2060 c50a7455 2021-10-04 thomas
2061 c50a7455 2021-10-04 thomas local orig_commit=`git_show_head $testroot/repo`
2062 c50a7455 2021-10-04 thomas
2063 c50a7455 2021-10-04 thomas echo "modified alpha on master" > $testroot/repo/alpha
2064 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
2065 c50a7455 2021-10-04 thomas echo "new file on master" > $testroot/repo/epsilon/new
2066 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
2067 c50a7455 2021-10-04 thomas git_commit $testroot/repo -m "committing changes"
2068 c50a7455 2021-10-04 thomas local old_commit1=`git_show_head $testroot/repo`
2069 c50a7455 2021-10-04 thomas
2070 c50a7455 2021-10-04 thomas echo "modified zeta on master" > $testroot/repo/epsilon/zeta
2071 c50a7455 2021-10-04 thomas git_commit $testroot/repo -m "committing to zeta on master"
2072 c50a7455 2021-10-04 thomas local old_commit2=`git_show_head $testroot/repo`
2073 c50a7455 2021-10-04 thomas
2074 c50a7455 2021-10-04 thomas got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2075 fc414659 2022-04-16 thomas ret=$?
2076 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
2077 c50a7455 2021-10-04 thomas test_done "$testroot" "$ret"
2078 c50a7455 2021-10-04 thomas return 1
2079 c50a7455 2021-10-04 thomas fi
2080 c50a7455 2021-10-04 thomas
2081 c50a7455 2021-10-04 thomas (cd $testroot/wt && got histedit -e > $testroot/stdout)
2082 c50a7455 2021-10-04 thomas
2083 c50a7455 2021-10-04 thomas local short_old_commit1=`trim_obj_id 28 $old_commit1`
2084 c50a7455 2021-10-04 thomas local short_old_commit2=`trim_obj_id 28 $old_commit2`
2085 c50a7455 2021-10-04 thomas
2086 c50a7455 2021-10-04 thomas echo "G alpha" > $testroot/stdout.expected
2087 c50a7455 2021-10-04 thomas echo "D beta" >> $testroot/stdout.expected
2088 c50a7455 2021-10-04 thomas echo "A epsilon/new" >> $testroot/stdout.expected
2089 c50a7455 2021-10-04 thomas echo "Stopping histedit for amending commit $old_commit1" \
2090 c50a7455 2021-10-04 thomas >> $testroot/stdout.expected
2091 c50a7455 2021-10-04 thomas cmp -s $testroot/stdout.expected $testroot/stdout
2092 fc414659 2022-04-16 thomas ret=$?
2093 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
2094 c50a7455 2021-10-04 thomas diff -u $testroot/stdout.expected $testroot/stdout
2095 c50a7455 2021-10-04 thomas test_done "$testroot" "$ret"
2096 c50a7455 2021-10-04 thomas return 1
2097 c50a7455 2021-10-04 thomas fi
2098 c50a7455 2021-10-04 thomas
2099 c50a7455 2021-10-04 thomas echo "edited modified alpha on master" > $testroot/wt/alpha
2100 c50a7455 2021-10-04 thomas
2101 c50a7455 2021-10-04 thomas cat > $testroot/editor.sh <<EOF
2102 c50a7455 2021-10-04 thomas #!/bin/sh
2103 ac3cdf31 2023-03-06 thomas ed -s "\$1" <<-EOF
2104 ac3cdf31 2023-03-06 thomas ,s/.*/committing edited changes 1/
2105 ac3cdf31 2023-03-06 thomas w
2106 ac3cdf31 2023-03-06 thomas EOF
2107 c50a7455 2021-10-04 thomas EOF
2108 c50a7455 2021-10-04 thomas chmod +x $testroot/editor.sh
2109 c50a7455 2021-10-04 thomas
2110 c50a7455 2021-10-04 thomas (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
2111 c50a7455 2021-10-04 thomas VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
2112 c50a7455 2021-10-04 thomas
2113 c50a7455 2021-10-04 thomas local new_commit1=$(cd $testroot/wt && got info | \
2114 c50a7455 2021-10-04 thomas grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
2115 c50a7455 2021-10-04 thomas local short_new_commit1=`trim_obj_id 28 $new_commit1`
2116 c50a7455 2021-10-04 thomas
2117 c50a7455 2021-10-04 thomas echo -n "$short_old_commit1 -> $short_new_commit1: " \
2118 c50a7455 2021-10-04 thomas > $testroot/stdout.expected
2119 c50a7455 2021-10-04 thomas echo "committing edited changes 1" >> $testroot/stdout.expected
2120 c50a7455 2021-10-04 thomas echo "G epsilon/zeta" >> $testroot/stdout.expected
2121 c50a7455 2021-10-04 thomas echo "Stopping histedit for amending commit $old_commit2" \
2122 c50a7455 2021-10-04 thomas >> $testroot/stdout.expected
2123 c50a7455 2021-10-04 thomas cmp -s $testroot/stdout.expected $testroot/stdout
2124 fc414659 2022-04-16 thomas ret=$?
2125 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
2126 c50a7455 2021-10-04 thomas diff -u $testroot/stdout.expected $testroot/stdout
2127 c50a7455 2021-10-04 thomas test_done "$testroot" "$ret"
2128 c50a7455 2021-10-04 thomas return 1
2129 c50a7455 2021-10-04 thomas fi
2130 c50a7455 2021-10-04 thomas
2131 c50a7455 2021-10-04 thomas echo "edited zeta on master" > $testroot/wt/epsilon/zeta
2132 c50a7455 2021-10-04 thomas
2133 c50a7455 2021-10-04 thomas cat > $testroot/editor.sh <<EOF
2134 c50a7455 2021-10-04 thomas #!/bin/sh
2135 ac3cdf31 2023-03-06 thomas ed -s "\$1" <<-EOF
2136 ac3cdf31 2023-03-06 thomas ,s/.*/committing edited changes 2/
2137 ac3cdf31 2023-03-06 thomas w
2138 ac3cdf31 2023-03-06 thomas EOF
2139 c50a7455 2021-10-04 thomas EOF
2140 c50a7455 2021-10-04 thomas chmod +x $testroot/editor.sh
2141 c50a7455 2021-10-04 thomas
2142 c50a7455 2021-10-04 thomas (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
2143 c50a7455 2021-10-04 thomas VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
2144 c50a7455 2021-10-04 thomas
2145 c50a7455 2021-10-04 thomas local new_commit2=`git_show_head $testroot/repo`
2146 c50a7455 2021-10-04 thomas local short_new_commit2=`trim_obj_id 28 $new_commit2`
2147 c50a7455 2021-10-04 thomas
2148 c50a7455 2021-10-04 thomas echo -n "$short_old_commit2 -> $short_new_commit2: " \
2149 c50a7455 2021-10-04 thomas > $testroot/stdout.expected
2150 c50a7455 2021-10-04 thomas echo "committing edited changes 2" >> $testroot/stdout.expected
2151 c50a7455 2021-10-04 thomas echo "Switching work tree to refs/heads/master" \
2152 c50a7455 2021-10-04 thomas >> $testroot/stdout.expected
2153 c50a7455 2021-10-04 thomas
2154 c50a7455 2021-10-04 thomas cmp -s $testroot/stdout.expected $testroot/stdout
2155 fc414659 2022-04-16 thomas ret=$?
2156 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
2157 c50a7455 2021-10-04 thomas diff -u $testroot/stdout.expected $testroot/stdout
2158 c50a7455 2021-10-04 thomas test_done "$testroot" "$ret"
2159 c50a7455 2021-10-04 thomas return 1
2160 c50a7455 2021-10-04 thomas fi
2161 c50a7455 2021-10-04 thomas
2162 c50a7455 2021-10-04 thomas echo "edited modified alpha on master" > $testroot/content.expected
2163 c50a7455 2021-10-04 thomas cat $testroot/wt/alpha > $testroot/content
2164 c50a7455 2021-10-04 thomas cmp -s $testroot/content.expected $testroot/content
2165 fc414659 2022-04-16 thomas ret=$?
2166 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
2167 c50a7455 2021-10-04 thomas diff -u $testroot/content.expected $testroot/content
2168 c50a7455 2021-10-04 thomas test_done "$testroot" "$ret"
2169 c50a7455 2021-10-04 thomas return 1
2170 c50a7455 2021-10-04 thomas fi
2171 c50a7455 2021-10-04 thomas
2172 c50a7455 2021-10-04 thomas if [ -e $testroot/wt/beta ]; then
2173 c50a7455 2021-10-04 thomas echo "removed file beta still exists on disk" >&2
2174 c50a7455 2021-10-04 thomas test_done "$testroot" "1"
2175 c50a7455 2021-10-04 thomas return 1
2176 c50a7455 2021-10-04 thomas fi
2177 c50a7455 2021-10-04 thomas
2178 c50a7455 2021-10-04 thomas echo "new file on master" > $testroot/content.expected
2179 c50a7455 2021-10-04 thomas cat $testroot/wt/epsilon/new > $testroot/content
2180 c50a7455 2021-10-04 thomas cmp -s $testroot/content.expected $testroot/content
2181 fc414659 2022-04-16 thomas ret=$?
2182 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
2183 c50a7455 2021-10-04 thomas diff -u $testroot/content.expected $testroot/content
2184 c50a7455 2021-10-04 thomas test_done "$testroot" "$ret"
2185 c50a7455 2021-10-04 thomas return 1
2186 c50a7455 2021-10-04 thomas fi
2187 c50a7455 2021-10-04 thomas
2188 c50a7455 2021-10-04 thomas (cd $testroot/wt && got status > $testroot/stdout)
2189 c50a7455 2021-10-04 thomas
2190 c50a7455 2021-10-04 thomas echo -n > $testroot/stdout.expected
2191 c50a7455 2021-10-04 thomas cmp -s $testroot/stdout.expected $testroot/stdout
2192 fc414659 2022-04-16 thomas ret=$?
2193 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
2194 c50a7455 2021-10-04 thomas diff -u $testroot/stdout.expected $testroot/stdout
2195 c50a7455 2021-10-04 thomas test_done "$testroot" "$ret"
2196 c50a7455 2021-10-04 thomas return 1
2197 c50a7455 2021-10-04 thomas fi
2198 c50a7455 2021-10-04 thomas
2199 c50a7455 2021-10-04 thomas (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
2200 c50a7455 2021-10-04 thomas echo "commit $new_commit2 (master)" > $testroot/stdout.expected
2201 c50a7455 2021-10-04 thomas echo "commit $new_commit1" >> $testroot/stdout.expected
2202 a347e6bb 2020-12-13 stsp echo "commit $orig_commit" >> $testroot/stdout.expected
2203 a347e6bb 2020-12-13 stsp cmp -s $testroot/stdout.expected $testroot/stdout
2204 fc414659 2022-04-16 thomas ret=$?
2205 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
2206 a347e6bb 2020-12-13 stsp diff -u $testroot/stdout.expected $testroot/stdout
2207 a347e6bb 2020-12-13 stsp fi
2208 a347e6bb 2020-12-13 stsp test_done "$testroot" "$ret"
2209 a347e6bb 2020-12-13 stsp }
2210 66eecf0d 2021-10-08 thomas
2211 66eecf0d 2021-10-08 thomas test_histedit_prepend_line() {
2212 66eecf0d 2021-10-08 thomas local testroot=`test_init histedit_prepend_line`
2213 66eecf0d 2021-10-08 thomas local orig_commit=`git_show_head $testroot/repo`
2214 66eecf0d 2021-10-08 thomas
2215 66eecf0d 2021-10-08 thomas got checkout $testroot/repo $testroot/wt > /dev/null
2216 66eecf0d 2021-10-08 thomas
2217 7a9950a8 2022-11-18 thomas ed -s "$testroot/wt/alpha" <<EOF
2218 e39a17e2 2021-10-15 thomas 1i
2219 66eecf0d 2021-10-08 thomas first line
2220 66eecf0d 2021-10-08 thomas .
2221 66eecf0d 2021-10-08 thomas wq
2222 66eecf0d 2021-10-08 thomas EOF
2223 66eecf0d 2021-10-08 thomas
2224 66eecf0d 2021-10-08 thomas cp $testroot/wt/alpha $testroot/content.expected
2225 a347e6bb 2020-12-13 stsp
2226 66eecf0d 2021-10-08 thomas (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
2227 66eecf0d 2021-10-08 thomas alpha > /dev/null)
2228 fc414659 2022-04-16 thomas ret=$?
2229 66eecf0d 2021-10-08 thomas if [ "$?" != 0 ]; then
2230 66eecf0d 2021-10-08 thomas echo "got commit failed unexpectedly" >&2
2231 66eecf0d 2021-10-08 thomas test_done "$testroot" "$ret"
2232 66eecf0d 2021-10-08 thomas return 1
2233 66eecf0d 2021-10-08 thomas fi
2234 66eecf0d 2021-10-08 thomas
2235 66eecf0d 2021-10-08 thomas local top_commit=`git_show_head $testroot/repo`
2236 66eecf0d 2021-10-08 thomas echo "pick $top_commit" > "$testroot/histedit-script"
2237 66eecf0d 2021-10-08 thomas
2238 66eecf0d 2021-10-08 thomas (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
2239 fc414659 2022-04-16 thomas ret=$?
2240 66eecf0d 2021-10-08 thomas if [ "$?" != 0 ]; then
2241 66eecf0d 2021-10-08 thomas echo "got update failed unexpectedly" >&2
2242 66eecf0d 2021-10-08 thomas test_done "$testroot" "$ret"
2243 66eecf0d 2021-10-08 thomas return 1
2244 66eecf0d 2021-10-08 thomas fi
2245 66eecf0d 2021-10-08 thomas
2246 66eecf0d 2021-10-08 thomas (cd $testroot/wt && got histedit -F "$testroot/histedit-script" \
2247 66eecf0d 2021-10-08 thomas > /dev/null)
2248 fc414659 2022-04-16 thomas ret=$?
2249 66eecf0d 2021-10-08 thomas if [ "$?" != 0 ]; then
2250 66eecf0d 2021-10-08 thomas echo "got histedit failed unexpectedly" >&2
2251 66eecf0d 2021-10-08 thomas test_done "$testroot" "$ret"
2252 66eecf0d 2021-10-08 thomas return 1
2253 66eecf0d 2021-10-08 thomas fi
2254 66eecf0d 2021-10-08 thomas
2255 66eecf0d 2021-10-08 thomas cp $testroot/wt/alpha $testroot/content
2256 66eecf0d 2021-10-08 thomas cmp -s $testroot/content.expected $testroot/content
2257 fc414659 2022-04-16 thomas ret=$?
2258 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
2259 66eecf0d 2021-10-08 thomas diff -u $testroot/content.expected $testroot/content
2260 66eecf0d 2021-10-08 thomas test_done "$testroot" "$ret"
2261 8ea72c47 2022-07-12 thomas return 1
2262 8ea72c47 2022-07-12 thomas fi
2263 8ea72c47 2022-07-12 thomas
2264 8ea72c47 2022-07-12 thomas test_done "$testroot" $ret
2265 150d7275 2022-07-22 thomas }
2266 150d7275 2022-07-22 thomas
2267 150d7275 2022-07-22 thomas test_histedit_resets_committer() {
2268 150d7275 2022-07-22 thomas local testroot=`test_init histedit_resets_committer`
2269 150d7275 2022-07-22 thomas local orig_commit=`git_show_head $testroot/repo`
2270 150d7275 2022-07-22 thomas local committer="Flan Luck <flan_luck@openbsd.org>"
2271 150d7275 2022-07-22 thomas
2272 150d7275 2022-07-22 thomas got checkout $testroot/repo $testroot/wt > /dev/null
2273 150d7275 2022-07-22 thomas
2274 150d7275 2022-07-22 thomas echo "modified alpha" > $testroot/wt/alpha
2275 150d7275 2022-07-22 thomas
2276 150d7275 2022-07-22 thomas (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
2277 150d7275 2022-07-22 thomas alpha > /dev/null)
2278 150d7275 2022-07-22 thomas ret=$?
2279 150d7275 2022-07-22 thomas if [ "$?" != 0 ]; then
2280 150d7275 2022-07-22 thomas echo "got commit failed unexpectedly" >&2
2281 150d7275 2022-07-22 thomas test_done "$testroot" "$ret"
2282 150d7275 2022-07-22 thomas return 1
2283 150d7275 2022-07-22 thomas fi
2284 150d7275 2022-07-22 thomas
2285 150d7275 2022-07-22 thomas local top_commit=`git_show_head $testroot/repo`
2286 150d7275 2022-07-22 thomas echo "pick $top_commit" > "$testroot/histedit-script"
2287 150d7275 2022-07-22 thomas
2288 150d7275 2022-07-22 thomas (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
2289 150d7275 2022-07-22 thomas ret=$?
2290 150d7275 2022-07-22 thomas if [ "$?" != 0 ]; then
2291 150d7275 2022-07-22 thomas echo "got update failed unexpectedly" >&2
2292 150d7275 2022-07-22 thomas test_done "$testroot" "$ret"
2293 150d7275 2022-07-22 thomas return 1
2294 150d7275 2022-07-22 thomas fi
2295 150d7275 2022-07-22 thomas
2296 150d7275 2022-07-22 thomas (cd $testroot/wt && env GOT_AUTHOR="$committer" \
2297 150d7275 2022-07-22 thomas got histedit -F "$testroot/histedit-script" > /dev/null)
2298 150d7275 2022-07-22 thomas ret=$?
2299 150d7275 2022-07-22 thomas if [ "$?" != 0 ]; then
2300 150d7275 2022-07-22 thomas echo "got histedit failed unexpectedly" >&2
2301 150d7275 2022-07-22 thomas test_done "$testroot" "$ret"
2302 150d7275 2022-07-22 thomas return 1
2303 150d7275 2022-07-22 thomas fi
2304 150d7275 2022-07-22 thomas local edited_commit=`git_show_head $testroot/repo`
2305 150d7275 2022-07-22 thomas
2306 150d7275 2022-07-22 thomas # Original commit only had one author
2307 150d7275 2022-07-22 thomas (cd $testroot/repo && got log -l1 -c $top_commit | \
2308 150d7275 2022-07-22 thomas egrep '^(from|via):' > $testroot/stdout)
2309 150d7275 2022-07-22 thomas echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2310 150d7275 2022-07-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
2311 150d7275 2022-07-22 thomas ret=$?
2312 150d7275 2022-07-22 thomas if [ $ret -ne 0 ]; then
2313 150d7275 2022-07-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
2314 150d7275 2022-07-22 thomas test_done "$testroot" "$ret"
2315 150d7275 2022-07-22 thomas return 1
2316 150d7275 2022-07-22 thomas fi
2317 150d7275 2022-07-22 thomas
2318 150d7275 2022-07-22 thomas # Edited commit should have new committer name added
2319 150d7275 2022-07-22 thomas (cd $testroot/repo && got log -l1 -c $edited_commit | \
2320 150d7275 2022-07-22 thomas egrep '^(from|via):' > $testroot/stdout)
2321 150d7275 2022-07-22 thomas echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2322 150d7275 2022-07-22 thomas echo "via: $committer" >> $testroot/stdout.expected
2323 150d7275 2022-07-22 thomas
2324 150d7275 2022-07-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
2325 150d7275 2022-07-22 thomas ret=$?
2326 150d7275 2022-07-22 thomas if [ $ret -ne 0 ]; then
2327 150d7275 2022-07-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
2328 150d7275 2022-07-22 thomas fi
2329 150d7275 2022-07-22 thomas test_done "$testroot" "$ret"
2330 8ea72c47 2022-07-12 thomas }
2331 a2c162eb 2022-10-30 thomas
2332 a2c162eb 2022-10-30 thomas test_histedit_umask() {
2333 a2c162eb 2022-10-30 thomas local testroot=`test_init histedit_umask`
2334 a2c162eb 2022-10-30 thomas local orig_commit=`git_show_head "$testroot/repo"`
2335 a2c162eb 2022-10-30 thomas
2336 a2c162eb 2022-10-30 thomas got checkout "$testroot/repo" "$testroot/wt" >/dev/null
2337 a2c162eb 2022-10-30 thomas
2338 a2c162eb 2022-10-30 thomas echo "modified alpha" > $testroot/wt/alpha
2339 a2c162eb 2022-10-30 thomas (cd "$testroot/wt" && got commit -m 'edit #1') >/dev/null
2340 a2c162eb 2022-10-30 thomas local commit1=`git_show_head "$testroot/repo"`
2341 a2c162eb 2022-10-30 thomas
2342 a2c162eb 2022-10-30 thomas echo "modified again" > $testroot/wt/alpha
2343 a2c162eb 2022-10-30 thomas (cd "$testroot/wt" && got commit -m 'edit #2') >/dev/null
2344 a2c162eb 2022-10-30 thomas local commit2=`git_show_head "$testroot/repo"`
2345 a2c162eb 2022-10-30 thomas
2346 a2c162eb 2022-10-30 thomas echo "modified again!" > $testroot/wt/alpha
2347 a2c162eb 2022-10-30 thomas echo "modify beta too!" > $testroot/wt/beta
2348 a2c162eb 2022-10-30 thomas (cd "$testroot/wt" && got commit -m 'edit #3') >/dev/null
2349 a2c162eb 2022-10-30 thomas local commit3=`git_show_head "$testroot/repo"`
2350 8ea72c47 2022-07-12 thomas
2351 a2c162eb 2022-10-30 thomas (cd "$testroot/wt" && got update -c "$orig_commit") >/dev/null
2352 a2c162eb 2022-10-30 thomas ret=$?
2353 a2c162eb 2022-10-30 thomas if [ $ret -ne 0 ]; then
2354 a2c162eb 2022-10-30 thomas echo "update to $orig_commit failed!" >&2
2355 a2c162eb 2022-10-30 thomas test_done "$testroot" 1
2356 a2c162eb 2022-10-30 thomas return 1
2357 a2c162eb 2022-10-30 thomas fi
2358 a2c162eb 2022-10-30 thomas
2359 f52e24d8 2023-10-28 thomas cat > $testroot/editor.sh <<EOF
2360 f52e24d8 2023-10-28 thomas #!/bin/sh
2361 f52e24d8 2023-10-28 thomas ed -s "\$1" <<-EOF
2362 f52e24d8 2023-10-28 thomas ,s/.*/folding changes/
2363 f52e24d8 2023-10-28 thomas w
2364 f52e24d8 2023-10-28 thomas EOF
2365 f52e24d8 2023-10-28 thomas EOF
2366 f52e24d8 2023-10-28 thomas chmod +x $testroot/editor.sh
2367 f52e24d8 2023-10-28 thomas
2368 a2c162eb 2022-10-30 thomas echo fold $commit1 >$testroot/histedit-script
2369 a2c162eb 2022-10-30 thomas echo fold $commit2 >>$testroot/histedit-script
2370 a2c162eb 2022-10-30 thomas echo pick $commit3 >>$testroot/histedit-script
2371 a2c162eb 2022-10-30 thomas
2372 a2c162eb 2022-10-30 thomas # using a subshell to avoid clobbering global umask
2373 a2c162eb 2022-10-30 thomas (umask 077 && cd "$testroot/wt" && \
2374 f52e24d8 2023-10-28 thomas env EDITOR="$testroot/editor.sh" VISUAL="$testroot/editor.sh" \
2375 a2c162eb 2022-10-30 thomas got histedit -F "$testroot/histedit-script") >/dev/null
2376 a2c162eb 2022-10-30 thomas ret=$?
2377 a2c162eb 2022-10-30 thomas
2378 a2c162eb 2022-10-30 thomas if [ $ret -ne 0 ]; then
2379 a2c162eb 2022-10-30 thomas echo "histedit operation failed" >&2
2380 a2c162eb 2022-10-30 thomas test_done "$testroot" $ret
2381 a2c162eb 2022-10-30 thomas return 1
2382 a2c162eb 2022-10-30 thomas fi
2383 a2c162eb 2022-10-30 thomas
2384 a2c162eb 2022-10-30 thomas for f in alpha beta; do
2385 a2c162eb 2022-10-30 thomas ls -l "$testroot/wt/$f" | grep -q ^-rw-------
2386 a2c162eb 2022-10-30 thomas if [ $? -ne 0 ]; then
2387 a2c162eb 2022-10-30 thomas echo "$f is not 0600 after histedi" >&2
2388 a2c162eb 2022-10-30 thomas ls -l "$testroot/wt/$f" >&2
2389 a2c162eb 2022-10-30 thomas test_done "$testroot" 1
2390 a2c162eb 2022-10-30 thomas return 1
2391 a2c162eb 2022-10-30 thomas fi
2392 a2c162eb 2022-10-30 thomas done
2393 a2c162eb 2022-10-30 thomas
2394 a2c162eb 2022-10-30 thomas test_done "$testroot" 0
2395 a2c162eb 2022-10-30 thomas }
2396 630fc61f 2023-01-29 thomas
2397 630fc61f 2023-01-29 thomas test_histedit_mesg_filemode_change() {
2398 630fc61f 2023-01-29 thomas local testroot=`test_init histedit_mode_change`
2399 630fc61f 2023-01-29 thomas
2400 630fc61f 2023-01-29 thomas local orig_commit=`git_show_head $testroot/repo`
2401 630fc61f 2023-01-29 thomas local orig_author_time=`git_show_author_time $testroot/repo`
2402 630fc61f 2023-01-29 thomas
2403 630fc61f 2023-01-29 thomas chmod +x $testroot/repo/alpha
2404 630fc61f 2023-01-29 thomas git_commit $testroot/repo -m "set x bit on alpha"
2405 630fc61f 2023-01-29 thomas local old_commit1=`git_show_head $testroot/repo`
2406 630fc61f 2023-01-29 thomas local old_author_time1=`git_show_author_time $testroot/repo`
2407 630fc61f 2023-01-29 thomas
2408 630fc61f 2023-01-29 thomas got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2409 630fc61f 2023-01-29 thomas ret=$?
2410 630fc61f 2023-01-29 thomas if [ $ret -ne 0 ]; then
2411 630fc61f 2023-01-29 thomas test_done "$testroot" "$ret"
2412 630fc61f 2023-01-29 thomas return 1
2413 630fc61f 2023-01-29 thomas fi
2414 630fc61f 2023-01-29 thomas
2415 630fc61f 2023-01-29 thomas if [ -x $testroot/wt/alpha ]; then
2416 630fc61f 2023-01-29 thomas echo "file alpha has unexpected executable bit" >&2
2417 630fc61f 2023-01-29 thomas test_done "$testroot" "1"
2418 630fc61f 2023-01-29 thomas return 1
2419 630fc61f 2023-01-29 thomas fi
2420 630fc61f 2023-01-29 thomas
2421 630fc61f 2023-01-29 thomas cat > $testroot/editor.sh <<EOF
2422 630fc61f 2023-01-29 thomas #!/bin/sh
2423 ac3cdf31 2023-03-06 thomas ed -s "\$1" <<-EOF
2424 ac3cdf31 2023-03-06 thomas ,s/ x bit / executable bit /
2425 ac3cdf31 2023-03-06 thomas w
2426 ac3cdf31 2023-03-06 thomas EOF
2427 630fc61f 2023-01-29 thomas EOF
2428 a2c162eb 2022-10-30 thomas
2429 630fc61f 2023-01-29 thomas chmod +x $testroot/editor.sh
2430 630fc61f 2023-01-29 thomas
2431 afe4b808 2023-01-29 thomas (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
2432 630fc61f 2023-01-29 thomas got histedit -m > $testroot/stdout)
2433 630fc61f 2023-01-29 thomas
2434 630fc61f 2023-01-29 thomas local new_commit1=`git_show_head $testroot/repo`
2435 630fc61f 2023-01-29 thomas local new_author_time1=`git_show_author_time $testroot/repo`
2436 630fc61f 2023-01-29 thomas
2437 630fc61f 2023-01-29 thomas local short_old_commit1=`trim_obj_id 28 $old_commit1`
2438 630fc61f 2023-01-29 thomas local short_new_commit1=`trim_obj_id 28 $new_commit1`
2439 630fc61f 2023-01-29 thomas
2440 630fc61f 2023-01-29 thomas echo "G alpha" > $testroot/stdout.expected
2441 630fc61f 2023-01-29 thomas echo "$short_old_commit1 -> $short_new_commit1: set executable bit on alpha" \
2442 630fc61f 2023-01-29 thomas >> $testroot/stdout.expected
2443 630fc61f 2023-01-29 thomas echo "Switching work tree to refs/heads/master" \
2444 630fc61f 2023-01-29 thomas >> $testroot/stdout.expected
2445 630fc61f 2023-01-29 thomas
2446 630fc61f 2023-01-29 thomas cmp -s $testroot/stdout.expected $testroot/stdout
2447 630fc61f 2023-01-29 thomas ret=$?
2448 630fc61f 2023-01-29 thomas if [ $ret -ne 0 ]; then
2449 630fc61f 2023-01-29 thomas diff -u $testroot/stdout.expected $testroot/stdout
2450 630fc61f 2023-01-29 thomas test_done "$testroot" "$ret"
2451 630fc61f 2023-01-29 thomas return 1
2452 630fc61f 2023-01-29 thomas fi
2453 630fc61f 2023-01-29 thomas
2454 630fc61f 2023-01-29 thomas echo "alpha" > $testroot/content.expected
2455 b5b4dc30 2023-01-29 thomas cmp -s $testroot/content.expected $testroot/wt/alpha
2456 630fc61f 2023-01-29 thomas ret=$?
2457 630fc61f 2023-01-29 thomas if [ $ret -ne 0 ]; then
2458 b5b4dc30 2023-01-29 thomas diff -u $testroot/content.expected $testroot/wt/alpha
2459 630fc61f 2023-01-29 thomas test_done "$testroot" "$ret"
2460 630fc61f 2023-01-29 thomas return 1
2461 630fc61f 2023-01-29 thomas fi
2462 630fc61f 2023-01-29 thomas
2463 630fc61f 2023-01-29 thomas if [ ! -x $testroot/wt/alpha ]; then
2464 630fc61f 2023-01-29 thomas echo "file alpha lost its executable bit" >&2
2465 630fc61f 2023-01-29 thomas test_done "$testroot" "1"
2466 630fc61f 2023-01-29 thomas return 1
2467 630fc61f 2023-01-29 thomas fi
2468 630fc61f 2023-01-29 thomas
2469 630fc61f 2023-01-29 thomas (cd $testroot/wt && got status > $testroot/stdout)
2470 630fc61f 2023-01-29 thomas
2471 630fc61f 2023-01-29 thomas echo -n > $testroot/stdout.expected
2472 630fc61f 2023-01-29 thomas cmp -s $testroot/stdout.expected $testroot/stdout
2473 630fc61f 2023-01-29 thomas ret=$?
2474 630fc61f 2023-01-29 thomas if [ $ret -ne 0 ]; then
2475 630fc61f 2023-01-29 thomas diff -u $testroot/stdout.expected $testroot/stdout
2476 630fc61f 2023-01-29 thomas test_done "$testroot" "$ret"
2477 630fc61f 2023-01-29 thomas return 1
2478 630fc61f 2023-01-29 thomas fi
2479 630fc61f 2023-01-29 thomas
2480 630fc61f 2023-01-29 thomas (cd $testroot/wt && got log -l1 | grep ' set executable bit on alpha' \
2481 630fc61f 2023-01-29 thomas > $testroot/stdout)
2482 630fc61f 2023-01-29 thomas
2483 630fc61f 2023-01-29 thomas echo ' set executable bit on alpha' > $testroot/stdout.expected
2484 630fc61f 2023-01-29 thomas cmp -s $testroot/stdout.expected $testroot/stdout
2485 630fc61f 2023-01-29 thomas ret=$?
2486 630fc61f 2023-01-29 thomas if [ $ret -ne 0 ]; then
2487 630fc61f 2023-01-29 thomas diff -u $testroot/stdout.expected $testroot/stdout
2488 630fc61f 2023-01-29 thomas test_done "$testroot" "$ret"
2489 630fc61f 2023-01-29 thomas return 1
2490 630fc61f 2023-01-29 thomas fi
2491 630fc61f 2023-01-29 thomas
2492 630fc61f 2023-01-29 thomas test_done "$testroot" "$ret"
2493 630fc61f 2023-01-29 thomas }
2494 070c80a5 2023-01-31 thomas
2495 070c80a5 2023-01-31 thomas test_histedit_drop_only() {
2496 070c80a5 2023-01-31 thomas local testroot=`test_init histedit_drop_only`
2497 070c80a5 2023-01-31 thomas
2498 070c80a5 2023-01-31 thomas local orig_commit=`git_show_head $testroot/repo`
2499 070c80a5 2023-01-31 thomas local drop="-> drop commit:"
2500 070c80a5 2023-01-31 thomas local dropmsg="commit changes to drop"
2501 070c80a5 2023-01-31 thomas
2502 070c80a5 2023-01-31 thomas echo "modified alpha on master" > $testroot/repo/alpha
2503 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
2504 070c80a5 2023-01-31 thomas echo "new file on master" > $testroot/repo/epsilon/new
2505 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
2506 070c80a5 2023-01-31 thomas
2507 070c80a5 2023-01-31 thomas git_commit $testroot/repo -m "$dropmsg 1"
2508 070c80a5 2023-01-31 thomas local drop_commit1=`git_show_head $testroot/repo`
2509 070c80a5 2023-01-31 thomas
2510 070c80a5 2023-01-31 thomas echo "modified zeta on master" > $testroot/repo/epsilon/zeta
2511 070c80a5 2023-01-31 thomas
2512 070c80a5 2023-01-31 thomas git_commit $testroot/repo -m "$dropmsg 2"
2513 070c80a5 2023-01-31 thomas local drop_commit2=`git_show_head $testroot/repo`
2514 070c80a5 2023-01-31 thomas
2515 070c80a5 2023-01-31 thomas echo "modified delta on master" > $testroot/repo/gamma/delta
2516 070c80a5 2023-01-31 thomas
2517 070c80a5 2023-01-31 thomas git_commit $testroot/repo -m "$dropmsg 3"
2518 070c80a5 2023-01-31 thomas local drop_commit3=`git_show_head $testroot/repo`
2519 070c80a5 2023-01-31 thomas
2520 070c80a5 2023-01-31 thomas got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2521 070c80a5 2023-01-31 thomas ret=$?
2522 070c80a5 2023-01-31 thomas if [ $ret -ne 0 ]; then
2523 070c80a5 2023-01-31 thomas test_done "$testroot" "$ret"
2524 070c80a5 2023-01-31 thomas return 1
2525 070c80a5 2023-01-31 thomas fi
2526 630fc61f 2023-01-29 thomas
2527 070c80a5 2023-01-31 thomas (cd $testroot/wt && got histedit -d > $testroot/stdout)
2528 070c80a5 2023-01-31 thomas local new_commit1=`git_show_head $testroot/repo`
2529 070c80a5 2023-01-31 thomas
2530 070c80a5 2023-01-31 thomas local short_commit1=`trim_obj_id 28 $drop_commit1`
2531 070c80a5 2023-01-31 thomas local short_commit2=`trim_obj_id 28 $drop_commit2`
2532 070c80a5 2023-01-31 thomas local short_commit3=`trim_obj_id 28 $drop_commit3`
2533 070c80a5 2023-01-31 thomas
2534 070c80a5 2023-01-31 thomas echo "$short_commit1 $drop $dropmsg 1" > $testroot/stdout.expected
2535 070c80a5 2023-01-31 thomas echo "$short_commit2 $drop $dropmsg 2" >> $testroot/stdout.expected
2536 070c80a5 2023-01-31 thomas echo "$short_commit3 $drop $dropmsg 3" >> $testroot/stdout.expected
2537 070c80a5 2023-01-31 thomas echo "Switching work tree to refs/heads/master" \
2538 070c80a5 2023-01-31 thomas >> $testroot/stdout.expected
2539 070c80a5 2023-01-31 thomas
2540 070c80a5 2023-01-31 thomas cmp -s $testroot/stdout.expected $testroot/stdout
2541 070c80a5 2023-01-31 thomas ret=$?
2542 070c80a5 2023-01-31 thomas if [ $ret -ne 0 ]; then
2543 070c80a5 2023-01-31 thomas diff -u $testroot/stdout.expected $testroot/stdout
2544 070c80a5 2023-01-31 thomas test_done "$testroot" "$ret"
2545 070c80a5 2023-01-31 thomas return 1
2546 070c80a5 2023-01-31 thomas fi
2547 070c80a5 2023-01-31 thomas
2548 070c80a5 2023-01-31 thomas echo "alpha" > $testroot/content.expected
2549 070c80a5 2023-01-31 thomas cat $testroot/wt/alpha > $testroot/content
2550 070c80a5 2023-01-31 thomas cmp -s $testroot/content.expected $testroot/content
2551 070c80a5 2023-01-31 thomas ret=$?
2552 070c80a5 2023-01-31 thomas if [ $ret -ne 0 ]; then
2553 070c80a5 2023-01-31 thomas diff -u $testroot/content.expected $testroot/content
2554 070c80a5 2023-01-31 thomas test_done "$testroot" "$ret"
2555 070c80a5 2023-01-31 thomas return 1
2556 070c80a5 2023-01-31 thomas fi
2557 070c80a5 2023-01-31 thomas
2558 070c80a5 2023-01-31 thomas echo "zeta" > $testroot/content.expected
2559 070c80a5 2023-01-31 thomas cat $testroot/wt/epsilon/zeta > $testroot/content
2560 070c80a5 2023-01-31 thomas cmp -s $testroot/content.expected $testroot/content
2561 070c80a5 2023-01-31 thomas ret=$?
2562 070c80a5 2023-01-31 thomas if [ $ret -ne 0 ]; then
2563 070c80a5 2023-01-31 thomas diff -u $testroot/content.expected $testroot/content
2564 070c80a5 2023-01-31 thomas test_done "$testroot" "$ret"
2565 070c80a5 2023-01-31 thomas return 1
2566 070c80a5 2023-01-31 thomas fi
2567 070c80a5 2023-01-31 thomas
2568 070c80a5 2023-01-31 thomas echo "delta" > $testroot/content.expected
2569 070c80a5 2023-01-31 thomas cat $testroot/wt/gamma/delta > $testroot/content
2570 070c80a5 2023-01-31 thomas cmp -s $testroot/content.expected $testroot/content
2571 070c80a5 2023-01-31 thomas ret=$?
2572 070c80a5 2023-01-31 thomas if [ $ret -ne 0 ]; then
2573 070c80a5 2023-01-31 thomas diff -u $testroot/content.expected $testroot/content
2574 070c80a5 2023-01-31 thomas test_done "$testroot" "$ret"
2575 070c80a5 2023-01-31 thomas return 1
2576 070c80a5 2023-01-31 thomas fi
2577 070c80a5 2023-01-31 thomas
2578 070c80a5 2023-01-31 thomas if [ ! -e $testroot/wt/beta ]; then
2579 070c80a5 2023-01-31 thomas echo "removed file beta should be restored" >&2
2580 070c80a5 2023-01-31 thomas test_done "$testroot" "1"
2581 070c80a5 2023-01-31 thomas return 1
2582 070c80a5 2023-01-31 thomas fi
2583 070c80a5 2023-01-31 thomas
2584 070c80a5 2023-01-31 thomas if [ -e $testroot/wt/new ]; then
2585 070c80a5 2023-01-31 thomas echo "new file should no longer exist" >&2
2586 070c80a5 2023-01-31 thomas test_done "$testroot" "$ret"
2587 070c80a5 2023-01-31 thomas return 1
2588 070c80a5 2023-01-31 thomas fi
2589 070c80a5 2023-01-31 thomas
2590 070c80a5 2023-01-31 thomas (cd $testroot/wt && got status > $testroot/stdout)
2591 070c80a5 2023-01-31 thomas
2592 070c80a5 2023-01-31 thomas echo -n > $testroot/stdout.expected
2593 070c80a5 2023-01-31 thomas cmp -s $testroot/stdout.expected $testroot/stdout
2594 070c80a5 2023-01-31 thomas ret=$?
2595 070c80a5 2023-01-31 thomas if [ $ret -ne 0 ]; then
2596 070c80a5 2023-01-31 thomas diff -u $testroot/stdout.expected $testroot/stdout
2597 070c80a5 2023-01-31 thomas test_done "$testroot" "$ret"
2598 070c80a5 2023-01-31 thomas return 1
2599 070c80a5 2023-01-31 thomas fi
2600 070c80a5 2023-01-31 thomas
2601 070c80a5 2023-01-31 thomas (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
2602 070c80a5 2023-01-31 thomas echo "commit $orig_commit (master)" > $testroot/stdout.expected
2603 070c80a5 2023-01-31 thomas cmp -s $testroot/stdout.expected $testroot/stdout
2604 070c80a5 2023-01-31 thomas ret=$?
2605 070c80a5 2023-01-31 thomas if [ $ret -ne 0 ]; then
2606 070c80a5 2023-01-31 thomas diff -u $testroot/stdout.expected $testroot/stdout
2607 070c80a5 2023-01-31 thomas fi
2608 070c80a5 2023-01-31 thomas test_done "$testroot" "$ret"
2609 070c80a5 2023-01-31 thomas }
2610 070c80a5 2023-01-31 thomas
2611 7fb414ae 2020-08-08 stsp test_parseargs "$@"
2612 0ebf8283 2019-07-24 stsp run_test test_histedit_no_op
2613 0ebf8283 2019-07-24 stsp run_test test_histedit_swap
2614 0ebf8283 2019-07-24 stsp run_test test_histedit_drop
2615 0ebf8283 2019-07-24 stsp run_test test_histedit_fold
2616 0ebf8283 2019-07-24 stsp run_test test_histedit_edit
2617 0ebf8283 2019-07-24 stsp run_test test_histedit_fold_last_commit
2618 f52e24d8 2023-10-28 thomas run_test test_histedit_missing_commit_pick
2619 f52e24d8 2023-10-28 thomas run_test test_histedit_missing_commit_mesg
2620 0ebf8283 2019-07-24 stsp run_test test_histedit_abort
2621 a4027091 2019-07-25 stsp run_test test_histedit_path_prefix_drop
2622 b2c50a0a 2019-07-25 stsp run_test test_histedit_path_prefix_edit
2623 c7d20a3f 2019-07-30 stsp run_test test_histedit_outside_refs_heads
2624 0def28b1 2019-08-17 stsp run_test test_histedit_fold_last_commit_swap
2625 de05890f 2020-03-05 stsp run_test test_histedit_split_commit
2626 5b87815e 2020-03-05 stsp run_test test_histedit_duplicate_commit_in_script
2627 ecfff807 2020-09-23 stsp run_test test_histedit_fold_add_delete
2628 4c3671a9 2023-07-26 thomas run_test test_histedit_fold_edit_delete
2629 99fe3033 2023-03-08 thomas run_test test_histedit_fold_delete_add
2630 239f5c5a 2020-12-13 stsp run_test test_histedit_fold_only
2631 a347e6bb 2020-12-13 stsp run_test test_histedit_fold_only_empty_logmsg
2632 c50a7455 2021-10-04 thomas run_test test_histedit_edit_only
2633 66eecf0d 2021-10-08 thomas run_test test_histedit_prepend_line
2634 150d7275 2022-07-22 thomas run_test test_histedit_resets_committer
2635 a2c162eb 2022-10-30 thomas run_test test_histedit_umask
2636 630fc61f 2023-01-29 thomas run_test test_histedit_mesg_filemode_change
2637 070c80a5 2023-01-31 thomas run_test test_histedit_drop_only