3 5ef14e63 2019-06-02 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 5ef14e63 2019-06-02 stsp # Permission to use, copy, modify, and distribute this software for any
6 5ef14e63 2019-06-02 stsp # purpose with or without fee is hereby granted, provided that the above
7 5ef14e63 2019-06-02 stsp # copyright notice and this permission notice appear in all copies.
9 5ef14e63 2019-06-02 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 5ef14e63 2019-06-02 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 5ef14e63 2019-06-02 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 5ef14e63 2019-06-02 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 5ef14e63 2019-06-02 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 5ef14e63 2019-06-02 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 5ef14e63 2019-06-02 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 5ef14e63 2019-06-02 stsp . ./common.sh
19 f6cae3ed 2020-09-13 naddy test_backout_basic() {
20 5ef14e63 2019-06-02 stsp local testroot=`test_init backout_basic`
22 5ef14e63 2019-06-02 stsp got checkout $testroot/repo $testroot/wt > /dev/null
24 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
25 5ef14e63 2019-06-02 stsp test_done "$testroot" "$ret"
29 5bda3ef8 2020-02-09 stsp echo "new" > $testroot/wt/new
30 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got add new > /dev/null)
31 5ef14e63 2019-06-02 stsp echo "modified alpha" > $testroot/wt/alpha
32 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
33 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got commit -m "bad changes" > /dev/null)
35 5ef14e63 2019-06-02 stsp local bad_commit=`git_show_head $testroot/repo`
38 5ef14e63 2019-06-02 stsp (cd $testroot/wt && got update > /dev/null)
40 5ef14e63 2019-06-02 stsp echo "modified beta" > $testroot/wt/beta
41 5ef14e63 2019-06-02 stsp (cd $testroot/wt && got commit -m "changing beta" > /dev/null)
43 5ef14e63 2019-06-02 stsp (cd $testroot/wt && got update > /dev/null)
45 5ef14e63 2019-06-02 stsp (cd $testroot/wt && got backout $bad_commit > $testroot/stdout)
47 5ef14e63 2019-06-02 stsp echo "G alpha" > $testroot/stdout.expected
48 5bda3ef8 2020-02-09 stsp echo "A epsilon/zeta" >> $testroot/stdout.expected
49 5bda3ef8 2020-02-09 stsp echo "D new" >> $testroot/stdout.expected
50 a7648d7a 2019-06-02 stsp echo "Backed out commit $bad_commit" >> $testroot/stdout.expected
51 5ef14e63 2019-06-02 stsp cmp -s $testroot/stdout.expected $testroot/stdout
53 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
54 5ef14e63 2019-06-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
55 5ef14e63 2019-06-02 stsp test_done "$testroot" "$ret"
59 5ef14e63 2019-06-02 stsp echo "alpha" > $testroot/content.expected
60 5ef14e63 2019-06-02 stsp cat $testroot/wt/alpha > $testroot/content
61 5ef14e63 2019-06-02 stsp cmp -s $testroot/content.expected $testroot/content
63 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
64 5ef14e63 2019-06-02 stsp diff -u $testroot/content.expected $testroot/content
65 5ef14e63 2019-06-02 stsp test_done "$testroot" "$ret"
69 5bda3ef8 2020-02-09 stsp if [ -e "$testroot/wt/new" ]; then
70 5bda3ef8 2020-02-09 stsp echo "file '$testroot/wt/new' still exists on disk" >&2
71 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
75 5bda3ef8 2020-02-09 stsp if [ ! -e "$testroot/wt/epsilon/zeta" ]; then
76 5bda3ef8 2020-02-09 stsp echo "file '$testroot/wt/epsilon/zeta' is missing on disk" >&2
77 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
81 5ef14e63 2019-06-02 stsp echo 'M alpha' > $testroot/stdout.expected
82 5bda3ef8 2020-02-09 stsp echo 'A epsilon/zeta' >> $testroot/stdout.expected
83 5bda3ef8 2020-02-09 stsp echo 'D new' >> $testroot/stdout.expected
84 5ef14e63 2019-06-02 stsp (cd $testroot/wt && got status > $testroot/stdout)
85 5ef14e63 2019-06-02 stsp cmp -s $testroot/stdout.expected $testroot/stdout
87 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
88 5ef14e63 2019-06-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
90 5ef14e63 2019-06-02 stsp test_done "$testroot" "$ret"
93 f6cae3ed 2020-09-13 naddy test_backout_edits_for_file_since_deleted() {
94 5bda3ef8 2020-02-09 stsp local testroot=`test_init backout_edits_for_file_since_deleted`
96 5bda3ef8 2020-02-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
98 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
99 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
103 5bda3ef8 2020-02-09 stsp echo "modified alpha" > $testroot/wt/alpha
104 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got commit -m "changing alpha" > /dev/null)
106 5bda3ef8 2020-02-09 stsp local bad_commit=`git_show_head $testroot/repo`
109 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got update > /dev/null)
111 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got rm alpha > /dev/null)
112 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got commit -m "removing alpha" > /dev/null)
114 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got update > /dev/null)
116 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got backout $bad_commit > $testroot/stdout)
118 5bda3ef8 2020-02-09 stsp echo "! alpha" > $testroot/stdout.expected
119 5bda3ef8 2020-02-09 stsp echo "Backed out commit $bad_commit" >> $testroot/stdout.expected
120 0ef68859 2021-09-28 thomas echo -n "Files which had incoming changes but could not be found " \
121 0ef68859 2021-09-28 thomas >> $testroot/stdout.expected
122 0ef68859 2021-09-28 thomas echo "in the work tree: 1" >> $testroot/stdout.expected
123 5bda3ef8 2020-02-09 stsp cmp -s $testroot/stdout.expected $testroot/stdout
125 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
126 5bda3ef8 2020-02-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
127 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
131 5bda3ef8 2020-02-09 stsp if [ -e "$testroot/wt/alpha" ]; then
132 5bda3ef8 2020-02-09 stsp echo "file '$testroot/wt/alpha' still exists on disk" >&2
133 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
137 5bda3ef8 2020-02-09 stsp echo -n '' > $testroot/stdout.expected
138 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got status > $testroot/stdout)
139 5bda3ef8 2020-02-09 stsp cmp -s $testroot/stdout.expected $testroot/stdout
141 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
142 5bda3ef8 2020-02-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
144 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
147 f6cae3ed 2020-09-13 naddy test_backout_next_commit() {
148 5bda3ef8 2020-02-09 stsp local testroot=`test_init backout_next_commit`
149 5bda3ef8 2020-02-09 stsp local commit0=`git_show_head $testroot/repo`
151 5bda3ef8 2020-02-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
153 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
154 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
158 5bda3ef8 2020-02-09 stsp echo "new" > $testroot/wt/new
159 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got add new > /dev/null)
160 5bda3ef8 2020-02-09 stsp echo "modified alpha" > $testroot/wt/alpha
161 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
162 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got commit -m "bad changes" > /dev/null)
164 5bda3ef8 2020-02-09 stsp local bad_commit=`git_show_head $testroot/repo`
166 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got update -c $commit0 > /dev/null)
168 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got backout $bad_commit > $testroot/stdout)
170 5bda3ef8 2020-02-09 stsp echo "G alpha" > $testroot/stdout.expected
171 5bda3ef8 2020-02-09 stsp echo "G epsilon/zeta" >> $testroot/stdout.expected
172 5bda3ef8 2020-02-09 stsp echo "! new" >> $testroot/stdout.expected
173 5bda3ef8 2020-02-09 stsp echo "Backed out commit $bad_commit" >> $testroot/stdout.expected
174 0ef68859 2021-09-28 thomas echo -n "Files which had incoming changes but could not be found " \
175 0ef68859 2021-09-28 thomas >> $testroot/stdout.expected
176 0ef68859 2021-09-28 thomas echo "in the work tree: 1" >> $testroot/stdout.expected
177 5bda3ef8 2020-02-09 stsp cmp -s $testroot/stdout.expected $testroot/stdout
179 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
180 5bda3ef8 2020-02-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
181 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
185 5bda3ef8 2020-02-09 stsp if [ -e "$testroot/wt/new" ]; then
186 5bda3ef8 2020-02-09 stsp echo "file '$testroot/wt/new' still exists on disk" >&2
187 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
191 5bda3ef8 2020-02-09 stsp echo "zeta" > $testroot/content.expected
192 5bda3ef8 2020-02-09 stsp cat $testroot/wt/epsilon/zeta > $testroot/content
193 5bda3ef8 2020-02-09 stsp cmp -s $testroot/content.expected $testroot/content
195 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
196 5bda3ef8 2020-02-09 stsp diff -u $testroot/content.expected $testroot/content
197 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
201 5bda3ef8 2020-02-09 stsp echo -n '' > $testroot/stdout.expected
202 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got status > $testroot/stdout)
203 5bda3ef8 2020-02-09 stsp cmp -s $testroot/stdout.expected $testroot/stdout
205 fc414659 2022-04-16 thomas if [ $ret -ne 0 ]; then
206 5bda3ef8 2020-02-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
208 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
211 a2c162eb 2022-10-30 thomas test_backout_umask() {
212 a2c162eb 2022-10-30 thomas local testroot=`test_init backout_umask`
214 a2c162eb 2022-10-30 thomas got checkout "$testroot/repo" "$testroot/wt" >/dev/null
215 a2c162eb 2022-10-30 thomas echo "edit alpha" >$testroot/wt/alpha
216 a2c162eb 2022-10-30 thomas (cd "$testroot/wt" && got commit -m 'edit alpha') >/dev/null
218 a2c162eb 2022-10-30 thomas if [ $ret -ne 0 ]; then
219 a2c162eb 2022-10-30 thomas test_done "$testroot" $ret
223 a2c162eb 2022-10-30 thomas local commit=`git_show_head "$testroot/repo"`
225 a2c162eb 2022-10-30 thomas (cd "$testroot/wt" && got update) >/dev/null
227 a2c162eb 2022-10-30 thomas # using a subshell to avoid clobbering global umask
228 a2c162eb 2022-10-30 thomas (umask 077 && cd "$testroot/wt" && got backout $commit) >/dev/null
230 a2c162eb 2022-10-30 thomas if [ $ret -ne 0 ]; then
231 a2c162eb 2022-10-30 thomas test_done "$testroot" $ret
235 a2c162eb 2022-10-30 thomas if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
236 a2c162eb 2022-10-30 thomas echo "alpha is not 0600 after backout" >&2
237 a2c162eb 2022-10-30 thomas ls -l "$testroot/wt/alpha" >&2
238 a2c162eb 2022-10-30 thomas test_done "$testroot" $ret
242 a2c162eb 2022-10-30 thomas test_done "$testroot" 0
245 7c82d1d5 2023-01-28 thomas test_backout_logmsg_ref() {
246 7c82d1d5 2023-01-28 thomas local testroot=`test_init backout_logmsg_ref`
248 7c82d1d5 2023-01-28 thomas got checkout $testroot/repo $testroot/wt > /dev/null
250 7c82d1d5 2023-01-28 thomas if [ $ret -ne 0 ]; then
251 7c82d1d5 2023-01-28 thomas test_done "$testroot" "$ret"
255 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch
257 7c82d1d5 2023-01-28 thomas echo "modified delta on branch" > $testroot/repo/gamma/delta
258 7c82d1d5 2023-01-28 thomas echo "modified alpha on branch" > $testroot/repo/alpha
259 d1e03b8c 2023-10-08 thomas git -C $testroot/repo rm -q beta
260 7c82d1d5 2023-01-28 thomas echo "new file on branch" > $testroot/repo/epsilon/new
261 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new
263 7c82d1d5 2023-01-28 thomas git_commit $testroot/repo -m "commit changes on newbranch"
264 7c82d1d5 2023-01-28 thomas local commit_time=`git_show_author_time $testroot/repo`
265 7c82d1d5 2023-01-28 thomas local branch_rev=`git_show_head $testroot/repo`
267 7c82d1d5 2023-01-28 thomas echo "modified new file on branch" > $testroot/repo/epsilon/new
269 7c82d1d5 2023-01-28 thomas git_commit $testroot/repo -m "commit modified new file on newbranch"
270 7c82d1d5 2023-01-28 thomas local commit_time2=`git_show_author_time $testroot/repo`
271 7c82d1d5 2023-01-28 thomas local branch_rev2=`git_show_head $testroot/repo`
273 7c82d1d5 2023-01-28 thomas (cd $testroot/wt && got backout $branch_rev > /dev/null)
274 7c82d1d5 2023-01-28 thomas (cd $testroot/wt && got backout $branch_rev2 > /dev/null)
276 7c82d1d5 2023-01-28 thomas # show all backout log message refs in the work tree
277 7c82d1d5 2023-01-28 thomas local sep="-----------------------------------------------"
278 7c82d1d5 2023-01-28 thomas local logmsg="commit changes on newbranch"
279 7c82d1d5 2023-01-28 thomas local changeset=" M alpha\n D beta\n A epsilon/new\n M gamma/delta"
280 7c82d1d5 2023-01-28 thomas local logmsg2="commit modified new file on newbranch"
281 7c82d1d5 2023-01-28 thomas local changeset2=" M epsilon/new"
282 7c82d1d5 2023-01-28 thomas local date=`date -u -r $commit_time +"%a %b %e %X %Y UTC"`
283 7c82d1d5 2023-01-28 thomas local date2=`date -u -r $commit_time2 +"%a %b %e %X %Y UTC"`
284 7c82d1d5 2023-01-28 thomas local ymd=`date -u -r $commit_time +"%F"`
285 7c82d1d5 2023-01-28 thomas local short_id=$(printf '%.7s' $branch_rev)
286 7c82d1d5 2023-01-28 thomas local ymd2=`date -u -r $commit_time2 +"%F"`
287 7c82d1d5 2023-01-28 thomas local short_id2="newbranch"
288 117f997e 2023-02-03 thomas local wt_sorted=$(printf "$branch_rev\n$branch_rev2" | sort)
290 117f997e 2023-02-03 thomas for r in $wt_sorted; do
291 7c82d1d5 2023-01-28 thomas echo $sep >> $testroot/stdout.expected
292 8d6e02ca 2023-03-03 thomas if [ $r = $branch_rev ]; then
293 f35e52a9 2023-01-31 thomas echo "backout $r" >> $testroot/stdout.expected
294 7c82d1d5 2023-01-28 thomas echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
295 7c82d1d5 2023-01-28 thomas echo "date: $date" >> $testroot/stdout.expected
296 7c82d1d5 2023-01-28 thomas printf " \n $logmsg\n \n" >> $testroot/stdout.expected
297 7c82d1d5 2023-01-28 thomas printf "$changeset\n\n" >> $testroot/stdout.expected
299 7c82d1d5 2023-01-28 thomas # for forthcoming wt 'backout -X' test
300 46f87436 2023-01-28 thomas echo "Deleted: $ymd $short_id $logmsg" >> \
301 7c82d1d5 2023-01-28 thomas $testroot/stdout.wt_deleted
303 f35e52a9 2023-01-31 thomas echo "backout $r (newbranch)" \
304 7c82d1d5 2023-01-28 thomas >> $testroot/stdout.expected
305 7c82d1d5 2023-01-28 thomas echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
306 7c82d1d5 2023-01-28 thomas echo "date: $date2" >> $testroot/stdout.expected
307 7c82d1d5 2023-01-28 thomas printf " \n $logmsg2\n \n" >> $testroot/stdout.expected
308 7c82d1d5 2023-01-28 thomas printf "$changeset2\n\n" >> $testroot/stdout.expected
310 7c82d1d5 2023-01-28 thomas # for forthcoming wt 'backout -X' test
311 46f87436 2023-01-28 thomas echo "Deleted: $ymd2 $short_id2 $logmsg2" >> \
312 7c82d1d5 2023-01-28 thomas $testroot/stdout.wt_deleted
316 7c82d1d5 2023-01-28 thomas (cd $testroot/wt && got backout -l > $testroot/stdout)
318 7c82d1d5 2023-01-28 thomas cmp -s $testroot/stdout.expected $testroot/stdout
320 7c82d1d5 2023-01-28 thomas if [ $ret -ne 0 ]; then
321 7c82d1d5 2023-01-28 thomas diff -u $testroot/stdout.expected $testroot/stdout
322 7c82d1d5 2023-01-28 thomas test_done "$testroot" "$ret"
326 7c82d1d5 2023-01-28 thomas # only show log message ref of the specified commit id
327 7c82d1d5 2023-01-28 thomas echo $sep > $testroot/stdout.expected
328 f35e52a9 2023-01-31 thomas echo "backout $branch_rev" >> $testroot/stdout.expected
329 7c82d1d5 2023-01-28 thomas echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
330 7c82d1d5 2023-01-28 thomas echo "date: $date" >> $testroot/stdout.expected
331 7c82d1d5 2023-01-28 thomas printf " \n $logmsg\n \n" >> $testroot/stdout.expected
332 7c82d1d5 2023-01-28 thomas printf "$changeset\n\n" >> $testroot/stdout.expected
334 7c82d1d5 2023-01-28 thomas (cd $testroot/wt && got backout -l $branch_rev > $testroot/stdout)
336 7c82d1d5 2023-01-28 thomas cmp -s $testroot/stdout.expected $testroot/stdout
338 7c82d1d5 2023-01-28 thomas if [ $ret -ne 0 ]; then
339 7c82d1d5 2023-01-28 thomas diff -u $testroot/stdout.expected $testroot/stdout
340 7c82d1d5 2023-01-28 thomas test_done "$testroot" "$ret"
344 7c82d1d5 2023-01-28 thomas # only show log message ref of the specified symref
345 7c82d1d5 2023-01-28 thomas echo $sep > $testroot/stdout.expected
346 f35e52a9 2023-01-31 thomas echo "backout $branch_rev2 (newbranch)" >> $testroot/stdout.expected
347 7c82d1d5 2023-01-28 thomas echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
348 7c82d1d5 2023-01-28 thomas echo "date: $date2" >> $testroot/stdout.expected
349 7c82d1d5 2023-01-28 thomas printf " \n $logmsg2\n \n" >> $testroot/stdout.expected
350 7c82d1d5 2023-01-28 thomas printf "$changeset2\n\n" >> $testroot/stdout.expected
352 7c82d1d5 2023-01-28 thomas (cd $testroot/wt && got backout -l "newbranch" > $testroot/stdout)
354 7c82d1d5 2023-01-28 thomas cmp -s $testroot/stdout.expected $testroot/stdout
356 7c82d1d5 2023-01-28 thomas if [ $ret -ne 0 ]; then
357 7c82d1d5 2023-01-28 thomas diff -u $testroot/stdout.expected $testroot/stdout
358 7c82d1d5 2023-01-28 thomas test_done "$testroot" "$ret"
362 7c82d1d5 2023-01-28 thomas # create a second work tree with backed-out commits and ensure
363 7c82d1d5 2023-01-28 thomas # bo -l within the new work tree only shows the refs it created
364 7c82d1d5 2023-01-28 thomas got checkout $testroot/repo $testroot/wt2 > /dev/null
366 7c82d1d5 2023-01-28 thomas if [ $ret -ne 0 ]; then
367 7c82d1d5 2023-01-28 thomas test_done "$testroot" "$ret"
371 d1e03b8c 2023-10-08 thomas git -C $testroot/repo checkout -q -b newbranch2
373 7c82d1d5 2023-01-28 thomas echo "modified delta on branch2" > $testroot/repo/gamma/delta
374 7c82d1d5 2023-01-28 thomas echo "modified alpha on branch2" > $testroot/repo/alpha
375 7c82d1d5 2023-01-28 thomas echo "new file on branch2" > $testroot/repo/epsilon/new2
376 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add epsilon/new2
378 7c82d1d5 2023-01-28 thomas git_commit $testroot/repo -m "commit changes on newbranch2"
379 7c82d1d5 2023-01-28 thomas local b2_commit_time=`git_show_author_time $testroot/repo`
380 7c82d1d5 2023-01-28 thomas local branch2_rev=`git_show_head $testroot/repo`
382 7c82d1d5 2023-01-28 thomas echo "modified file new2 on branch2" > $testroot/repo/epsilon/new2
384 7c82d1d5 2023-01-28 thomas git_commit $testroot/repo -m "commit modified file new2 on newbranch2"
385 7c82d1d5 2023-01-28 thomas local b2_commit_time2=`git_show_author_time $testroot/repo`
386 7c82d1d5 2023-01-28 thomas local branch2_rev2=`git_show_head $testroot/repo`
388 7c82d1d5 2023-01-28 thomas (cd $testroot/wt2 && got backout $branch2_rev > /dev/null)
389 7c82d1d5 2023-01-28 thomas (cd $testroot/wt2 && got backout $branch2_rev2 > /dev/null)
391 7c82d1d5 2023-01-28 thomas local b2_logmsg="commit changes on newbranch2"
392 7c82d1d5 2023-01-28 thomas local b2_changeset=" M alpha\n A epsilon/new2\n M gamma/delta"
393 7c82d1d5 2023-01-28 thomas local b2_logmsg2="commit modified file new2 on newbranch2"
394 7c82d1d5 2023-01-28 thomas local b2_changeset2=" M epsilon/new2"
395 7c82d1d5 2023-01-28 thomas date=`date -u -r $b2_commit_time +"%a %b %e %X %Y UTC"`
396 7c82d1d5 2023-01-28 thomas date2=`date -u -r $b2_commit_time2 +"%a %b %e %X %Y UTC"`
397 117f997e 2023-02-03 thomas local wt2_sorted=$(printf "$branch2_rev\n$branch2_rev2" | sort)
399 7c82d1d5 2023-01-28 thomas echo -n > $testroot/stdout.expected
400 117f997e 2023-02-03 thomas for r in $wt2_sorted; do
401 7c82d1d5 2023-01-28 thomas echo $sep >> $testroot/stdout.expected
402 8d6e02ca 2023-03-03 thomas if [ $r = $branch2_rev ]; then
403 f35e52a9 2023-01-31 thomas echo "backout $r" >> $testroot/stdout.expected
404 7c82d1d5 2023-01-28 thomas echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
405 7c82d1d5 2023-01-28 thomas echo "date: $date" >> $testroot/stdout.expected
406 7c82d1d5 2023-01-28 thomas printf " \n $b2_logmsg\n \n" >> \
407 7c82d1d5 2023-01-28 thomas $testroot/stdout.expected
408 7c82d1d5 2023-01-28 thomas printf "$b2_changeset\n\n" >> \
409 7c82d1d5 2023-01-28 thomas $testroot/stdout.expected
411 f35e52a9 2023-01-31 thomas echo "backout $r (newbranch2)" \
412 7c82d1d5 2023-01-28 thomas >> $testroot/stdout.expected
413 7c82d1d5 2023-01-28 thomas echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
414 7c82d1d5 2023-01-28 thomas echo "date: $date2" >> $testroot/stdout.expected
415 7c82d1d5 2023-01-28 thomas printf " \n $b2_logmsg2\n \n" >> \
416 7c82d1d5 2023-01-28 thomas $testroot/stdout.expected
417 7c82d1d5 2023-01-28 thomas printf "$b2_changeset2\n\n" >> \
418 7c82d1d5 2023-01-28 thomas $testroot/stdout.expected
422 7c82d1d5 2023-01-28 thomas (cd $testroot/wt2 && got backout -l > $testroot/stdout)
424 7c82d1d5 2023-01-28 thomas cmp -s $testroot/stdout.expected $testroot/stdout
426 7c82d1d5 2023-01-28 thomas if [ $ret -ne 0 ]; then
427 7c82d1d5 2023-01-28 thomas diff -u $testroot/stdout.expected $testroot/stdout
428 7c82d1d5 2023-01-28 thomas test_done "$testroot" "$ret"
432 117f997e 2023-02-03 thomas # ensure both wt and wt2 logmsg refs can be retrieved and the
433 117f997e 2023-02-03 thomas # work tree UUID is displayed when listing refs from the repo
434 117f997e 2023-02-03 thomas local wt_uuid=$(cat $testroot/wt/.got/uuid)
435 117f997e 2023-02-03 thomas local wt2_uuid=$(cat $testroot/wt2/.got/uuid)
436 117f997e 2023-02-03 thomas local wt_first=`printf "$wt_uuid\n$wt2_uuid" | sort | head -1`
438 117f997e 2023-02-03 thomas for r in $wt_sorted; do
439 117f997e 2023-02-03 thomas echo -n "backout $r" >> $testroot/wt.list
440 8d6e02ca 2023-03-03 thomas if [ $r = $branch_rev2 ]; then
441 117f997e 2023-02-03 thomas echo -n " (newbranch)" >> $testroot/wt.list
443 117f997e 2023-02-03 thomas echo >> $testroot/wt.list
444 117f997e 2023-02-03 thomas echo "work tree: $wt_uuid" >> $testroot/wt.list
447 117f997e 2023-02-03 thomas for r in $wt2_sorted; do
448 117f997e 2023-02-03 thomas echo -n "backout $r" >> $testroot/wt2.list
449 8d6e02ca 2023-03-03 thomas if [ $r = $branch2_rev2 ]; then
450 117f997e 2023-02-03 thomas echo -n " (newbranch2)" >> $testroot/wt2.list
452 117f997e 2023-02-03 thomas echo >> $testroot/wt2.list
453 117f997e 2023-02-03 thomas echo "work tree: $wt2_uuid" >> $testroot/wt2.list
456 8d6e02ca 2023-03-03 thomas if [ $wt_uuid = $wt_first ]; then
457 117f997e 2023-02-03 thomas mv $testroot/wt.list $testroot/stdout.expected
458 117f997e 2023-02-03 thomas cat $testroot/wt2.list >> $testroot/stdout.expected
460 117f997e 2023-02-03 thomas mv $testroot/wt2.list $testroot/stdout.expected
461 117f997e 2023-02-03 thomas cat $testroot/wt.list >> $testroot/stdout.expected
464 117f997e 2023-02-03 thomas (cd $testroot/repo && got backout -l | egrep "^(backout|work)" \
465 117f997e 2023-02-03 thomas > $testroot/stdout)
467 7c82d1d5 2023-01-28 thomas cmp -s $testroot/stdout.expected $testroot/stdout
469 7c82d1d5 2023-01-28 thomas if [ $ret -ne 0 ]; then
470 7c82d1d5 2023-01-28 thomas diff -u $testroot/stdout.expected $testroot/stdout
471 7c82d1d5 2023-01-28 thomas test_done "$testroot" "$ret"
475 7c82d1d5 2023-01-28 thomas # delete logmsg ref of the specified commit in work tree 2
476 7c82d1d5 2023-01-28 thomas ymd=`date -u -r $b2_commit_time +"%F"`
477 7c82d1d5 2023-01-28 thomas short_id=$(printf '%.7s' $branch2_rev)
479 46f87436 2023-01-28 thomas echo "Deleted: $ymd $short_id $b2_logmsg" > $testroot/stdout.expected
480 7c82d1d5 2023-01-28 thomas (cd $testroot/wt2 && got backout -X $branch2_rev > $testroot/stdout)
482 7c82d1d5 2023-01-28 thomas cmp -s $testroot/stdout.expected $testroot/stdout
484 7c82d1d5 2023-01-28 thomas if [ $ret -ne 0 ]; then
485 7c82d1d5 2023-01-28 thomas diff -u $testroot/stdout.expected $testroot/stdout
486 7c82d1d5 2023-01-28 thomas test_done "$testroot" "$ret"
490 7c82d1d5 2023-01-28 thomas # delete all logmsg refs in work tree 1
491 7c82d1d5 2023-01-28 thomas (cd $testroot && mv stdout.wt_deleted stdout.expected)
492 7c82d1d5 2023-01-28 thomas (cd $testroot/wt && got backout -X > $testroot/stdout)
494 7c82d1d5 2023-01-28 thomas cmp -s $testroot/stdout.expected $testroot/stdout
496 7c82d1d5 2023-01-28 thomas if [ $ret -ne 0 ]; then
497 7c82d1d5 2023-01-28 thomas diff -u $testroot/stdout.expected $testroot/stdout
498 7c82d1d5 2023-01-28 thomas test_done "$testroot" "$ret"
502 7c82d1d5 2023-01-28 thomas # confirm all work tree 1 refs were deleted
503 7c82d1d5 2023-01-28 thomas echo -n > $testroot/stdout.expected
504 7c82d1d5 2023-01-28 thomas (cd $testroot/wt && got backout -l > $testroot/stdout)
506 7c82d1d5 2023-01-28 thomas cmp -s $testroot/stdout.expected $testroot/stdout
508 7c82d1d5 2023-01-28 thomas if [ $ret -ne 0 ]; then
509 7c82d1d5 2023-01-28 thomas diff -u $testroot/stdout.expected $testroot/stdout
510 7c82d1d5 2023-01-28 thomas test_done "$testroot" "$ret"
514 7c82d1d5 2023-01-28 thomas # make sure the remaining ref in work tree 2 was not also deleted
515 7c82d1d5 2023-01-28 thomas echo $sep > $testroot/stdout.expected
516 f35e52a9 2023-01-31 thomas echo "backout $branch2_rev2 (newbranch2)" >> $testroot/stdout.expected
517 7c82d1d5 2023-01-28 thomas echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
518 7c82d1d5 2023-01-28 thomas echo "date: $date2" >> $testroot/stdout.expected
519 7c82d1d5 2023-01-28 thomas printf " \n $b2_logmsg2\n \n" >> $testroot/stdout.expected
520 7c82d1d5 2023-01-28 thomas printf "$b2_changeset2\n\n" >> $testroot/stdout.expected
522 7c82d1d5 2023-01-28 thomas (cd $testroot/wt2 && got backout -l > $testroot/stdout)
524 7c82d1d5 2023-01-28 thomas cmp -s $testroot/stdout.expected $testroot/stdout
526 7c82d1d5 2023-01-28 thomas if [ $ret -ne 0 ]; then
527 7c82d1d5 2023-01-28 thomas diff -u $testroot/stdout.expected $testroot/stdout
528 7c82d1d5 2023-01-28 thomas test_done "$testroot" "$ret"
532 7c82d1d5 2023-01-28 thomas # ensure we can delete work tree refs from the repository dir
533 7c82d1d5 2023-01-28 thomas ymd=`date -u -r $b2_commit_time2 +"%F"`
534 46f87436 2023-01-28 thomas echo "Deleted: $ymd newbranch2 $b2_logmsg2" > $testroot/stdout.expected
535 7c82d1d5 2023-01-28 thomas (cd $testroot/repo && got backout -X > $testroot/stdout)
537 fb885120 2023-07-19 thomas cmp -s $testroot/stdout.expected $testroot/stdout
539 fb885120 2023-07-19 thomas if [ $ret -ne 0 ]; then
540 fb885120 2023-07-19 thomas diff -u $testroot/stdout.expected $testroot/stdout
543 fb885120 2023-07-19 thomas test_done "$testroot" "$ret"
546 fb885120 2023-07-19 thomas test_backout_commit_keywords() {
547 fb885120 2023-07-19 thomas local testroot=$(test_init backout_commit_keywords)
549 fb885120 2023-07-19 thomas got checkout $testroot/repo $testroot/wt > /dev/null
551 fb885120 2023-07-19 thomas if [ $ret -ne 0 ]; then
552 fb885120 2023-07-19 thomas test_done "$testroot" "$ret"
556 fb885120 2023-07-19 thomas echo "new" > $testroot/wt/new
557 fb885120 2023-07-19 thomas (cd $testroot/wt && got add new > /dev/null)
558 fb885120 2023-07-19 thomas echo "modified alpha" > $testroot/wt/alpha
559 fb885120 2023-07-19 thomas (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
560 fb885120 2023-07-19 thomas (cd $testroot/wt && got commit -m "bad changes" > /dev/null)
562 fb885120 2023-07-19 thomas local bad_commit=`git_show_head $testroot/repo`
564 fb885120 2023-07-19 thomas (cd $testroot/wt && got update > /dev/null)
566 fb885120 2023-07-19 thomas echo "modified beta" > $testroot/wt/beta
567 fb885120 2023-07-19 thomas (cd $testroot/wt && got commit -m "changing beta" > /dev/null)
568 fb885120 2023-07-19 thomas echo "modified beta again" > $testroot/wt/beta
569 fb885120 2023-07-19 thomas (cd $testroot/wt && got commit -m "changing beta again" > /dev/null)
571 fb885120 2023-07-19 thomas (cd $testroot/wt && got update > /dev/null)
573 fb885120 2023-07-19 thomas (cd $testroot/wt && got bo :head:-2 > $testroot/stdout)
575 fb885120 2023-07-19 thomas echo "G alpha" > $testroot/stdout.expected
576 fb885120 2023-07-19 thomas echo "A epsilon/zeta" >> $testroot/stdout.expected
577 fb885120 2023-07-19 thomas echo "D new" >> $testroot/stdout.expected
578 fb885120 2023-07-19 thomas echo "Backed out commit $bad_commit" >> $testroot/stdout.expected
580 fb885120 2023-07-19 thomas cmp -s $testroot/stdout.expected $testroot/stdout
582 fb885120 2023-07-19 thomas if [ $ret -ne 0 ]; then
583 fb885120 2023-07-19 thomas diff -u $testroot/stdout.expected $testroot/stdout
584 fb885120 2023-07-19 thomas test_done "$testroot" "$ret"
588 fb885120 2023-07-19 thomas echo "alpha" > $testroot/content.expected
589 fb885120 2023-07-19 thomas cat $testroot/wt/alpha > $testroot/content
590 fb885120 2023-07-19 thomas cmp -s $testroot/content.expected $testroot/content
592 fb885120 2023-07-19 thomas if [ $ret -ne 0 ]; then
593 fb885120 2023-07-19 thomas diff -u $testroot/content.expected $testroot/content
594 fb885120 2023-07-19 thomas test_done "$testroot" "$ret"
598 fb885120 2023-07-19 thomas if [ -e "$testroot/wt/new" ]; then
599 fb885120 2023-07-19 thomas echo "file '$testroot/wt/new' still exists on disk" >&2
600 fb885120 2023-07-19 thomas test_done "$testroot" "$ret"
604 fb885120 2023-07-19 thomas if [ ! -e "$testroot/wt/epsilon/zeta" ]; then
605 fb885120 2023-07-19 thomas echo "file '$testroot/wt/epsilon/zeta' is missing on disk" >&2
606 fb885120 2023-07-19 thomas test_done "$testroot" "$ret"
610 fb885120 2023-07-19 thomas echo 'M alpha' > $testroot/stdout.expected
611 fb885120 2023-07-19 thomas echo 'A epsilon/zeta' >> $testroot/stdout.expected
612 fb885120 2023-07-19 thomas echo 'D new' >> $testroot/stdout.expected
613 fb885120 2023-07-19 thomas (cd $testroot/wt && got status > $testroot/stdout)
615 7c82d1d5 2023-01-28 thomas cmp -s $testroot/stdout.expected $testroot/stdout
617 7c82d1d5 2023-01-28 thomas if [ $ret -ne 0 ]; then
618 7c82d1d5 2023-01-28 thomas diff -u $testroot/stdout.expected $testroot/stdout
619 fb885120 2023-07-19 thomas test_done "$testroot" "$ret"
623 fb885120 2023-07-19 thomas local next_backout=`git_show_head $testroot/repo`
625 fb885120 2023-07-19 thomas (cd "$testroot/wt" && got ci -m "backed-out bad commit" > /dev/null)
626 fb885120 2023-07-19 thomas (cd "$testroot/wt" && got up > /dev/null)
628 fb885120 2023-07-19 thomas echo "G beta" > $testroot/stdout.expected
629 fb885120 2023-07-19 thomas echo "Backed out commit $next_backout" >> $testroot/stdout.expected
630 fb885120 2023-07-19 thomas (cd "$testroot/wt" && got bo :base:- > $testroot/stdout)
632 fb885120 2023-07-19 thomas cmp -s $testroot/stdout.expected $testroot/stdout
634 fb885120 2023-07-19 thomas if [ $ret -ne 0 ]; then
635 fb885120 2023-07-19 thomas diff -u $testroot/stdout.expected $testroot/stdout
638 7c82d1d5 2023-01-28 thomas test_done "$testroot" "$ret"
641 7fb414ae 2020-08-08 stsp test_parseargs "$@"
642 5ef14e63 2019-06-02 stsp run_test test_backout_basic
643 5bda3ef8 2020-02-09 stsp run_test test_backout_edits_for_file_since_deleted
644 5bda3ef8 2020-02-09 stsp run_test test_backout_next_commit
645 a2c162eb 2022-10-30 thomas run_test test_backout_umask
646 7c82d1d5 2023-01-28 thomas run_test test_backout_logmsg_ref
647 fb885120 2023-07-19 thomas run_test test_backout_commit_keywords