Blame


1 5ef14e63 2019-06-02 stsp #!/bin/sh
2 5ef14e63 2019-06-02 stsp #
3 5ef14e63 2019-06-02 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 5ef14e63 2019-06-02 stsp #
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.
8 5ef14e63 2019-06-02 stsp #
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.
16 5ef14e63 2019-06-02 stsp
17 5ef14e63 2019-06-02 stsp . ./common.sh
18 5ef14e63 2019-06-02 stsp
19 f6cae3ed 2020-09-13 naddy test_backout_basic() {
20 5ef14e63 2019-06-02 stsp local testroot=`test_init backout_basic`
21 5ef14e63 2019-06-02 stsp
22 5ef14e63 2019-06-02 stsp got checkout $testroot/repo $testroot/wt > /dev/null
23 49c543a6 2022-03-31 naddy ret=$?
24 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
25 5ef14e63 2019-06-02 stsp test_done "$testroot" "$ret"
26 5ef14e63 2019-06-02 stsp return 1
27 5ef14e63 2019-06-02 stsp fi
28 5ef14e63 2019-06-02 stsp
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)
34 5ef14e63 2019-06-02 stsp
35 5ef14e63 2019-06-02 stsp local bad_commit=`git_show_head $testroot/repo`
36 5ef14e63 2019-06-02 stsp
37 5ef14e63 2019-06-02 stsp
38 5ef14e63 2019-06-02 stsp (cd $testroot/wt && got update > /dev/null)
39 5ef14e63 2019-06-02 stsp
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)
42 5ef14e63 2019-06-02 stsp
43 5ef14e63 2019-06-02 stsp (cd $testroot/wt && got update > /dev/null)
44 5ef14e63 2019-06-02 stsp
45 5ef14e63 2019-06-02 stsp (cd $testroot/wt && got backout $bad_commit > $testroot/stdout)
46 5ef14e63 2019-06-02 stsp
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
52 49c543a6 2022-03-31 naddy ret=$?
53 49c543a6 2022-03-31 naddy 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"
56 5ef14e63 2019-06-02 stsp return 1
57 5ef14e63 2019-06-02 stsp fi
58 5ef14e63 2019-06-02 stsp
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
62 49c543a6 2022-03-31 naddy ret=$?
63 49c543a6 2022-03-31 naddy 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"
66 5ef14e63 2019-06-02 stsp return 1
67 5ef14e63 2019-06-02 stsp fi
68 5ef14e63 2019-06-02 stsp
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"
72 5bda3ef8 2020-02-09 stsp return 1
73 5bda3ef8 2020-02-09 stsp fi
74 5bda3ef8 2020-02-09 stsp
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"
78 5bda3ef8 2020-02-09 stsp return 1
79 5bda3ef8 2020-02-09 stsp fi
80 5bda3ef8 2020-02-09 stsp
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
86 49c543a6 2022-03-31 naddy ret=$?
87 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
88 5ef14e63 2019-06-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
89 5ef14e63 2019-06-02 stsp fi
90 5ef14e63 2019-06-02 stsp test_done "$testroot" "$ret"
91 5ef14e63 2019-06-02 stsp }
92 5ef14e63 2019-06-02 stsp
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`
95 5bda3ef8 2020-02-09 stsp
96 5bda3ef8 2020-02-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
97 49c543a6 2022-03-31 naddy ret=$?
98 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
99 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
100 5bda3ef8 2020-02-09 stsp return 1
101 5bda3ef8 2020-02-09 stsp fi
102 5bda3ef8 2020-02-09 stsp
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)
105 5bda3ef8 2020-02-09 stsp
106 5bda3ef8 2020-02-09 stsp local bad_commit=`git_show_head $testroot/repo`
107 5bda3ef8 2020-02-09 stsp
108 5bda3ef8 2020-02-09 stsp
109 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got update > /dev/null)
110 5bda3ef8 2020-02-09 stsp
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)
113 5bda3ef8 2020-02-09 stsp
114 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got update > /dev/null)
115 5bda3ef8 2020-02-09 stsp
116 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got backout $bad_commit > $testroot/stdout)
117 5bda3ef8 2020-02-09 stsp
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 35ca1db7 2021-09-28 stsp echo -n "Files which had incoming changes but could not be found " \
121 35ca1db7 2021-09-28 stsp >> $testroot/stdout.expected
122 35ca1db7 2021-09-28 stsp echo "in the work tree: 1" >> $testroot/stdout.expected
123 5bda3ef8 2020-02-09 stsp cmp -s $testroot/stdout.expected $testroot/stdout
124 49c543a6 2022-03-31 naddy ret=$?
125 49c543a6 2022-03-31 naddy 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"
128 5bda3ef8 2020-02-09 stsp return 1
129 5bda3ef8 2020-02-09 stsp fi
130 5bda3ef8 2020-02-09 stsp
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"
134 5bda3ef8 2020-02-09 stsp return 1
135 5bda3ef8 2020-02-09 stsp fi
136 5bda3ef8 2020-02-09 stsp
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
140 49c543a6 2022-03-31 naddy ret=$?
141 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
142 5bda3ef8 2020-02-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
143 5bda3ef8 2020-02-09 stsp fi
144 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
145 5bda3ef8 2020-02-09 stsp }
146 5bda3ef8 2020-02-09 stsp
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`
150 5bda3ef8 2020-02-09 stsp
151 5bda3ef8 2020-02-09 stsp got checkout $testroot/repo $testroot/wt > /dev/null
152 49c543a6 2022-03-31 naddy ret=$?
153 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
154 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
155 5bda3ef8 2020-02-09 stsp return 1
156 5bda3ef8 2020-02-09 stsp fi
157 5bda3ef8 2020-02-09 stsp
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)
163 5bda3ef8 2020-02-09 stsp
164 5bda3ef8 2020-02-09 stsp local bad_commit=`git_show_head $testroot/repo`
165 5bda3ef8 2020-02-09 stsp
166 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got update -c $commit0 > /dev/null)
167 5bda3ef8 2020-02-09 stsp
168 5bda3ef8 2020-02-09 stsp (cd $testroot/wt && got backout $bad_commit > $testroot/stdout)
169 5bda3ef8 2020-02-09 stsp
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 35ca1db7 2021-09-28 stsp echo -n "Files which had incoming changes but could not be found " \
175 35ca1db7 2021-09-28 stsp >> $testroot/stdout.expected
176 35ca1db7 2021-09-28 stsp echo "in the work tree: 1" >> $testroot/stdout.expected
177 5bda3ef8 2020-02-09 stsp cmp -s $testroot/stdout.expected $testroot/stdout
178 49c543a6 2022-03-31 naddy ret=$?
179 49c543a6 2022-03-31 naddy 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"
182 5bda3ef8 2020-02-09 stsp return 1
183 5bda3ef8 2020-02-09 stsp fi
184 5bda3ef8 2020-02-09 stsp
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"
188 5bda3ef8 2020-02-09 stsp return 1
189 5bda3ef8 2020-02-09 stsp fi
190 5bda3ef8 2020-02-09 stsp
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
194 49c543a6 2022-03-31 naddy ret=$?
195 49c543a6 2022-03-31 naddy 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"
198 5bda3ef8 2020-02-09 stsp return 1
199 5bda3ef8 2020-02-09 stsp fi
200 5bda3ef8 2020-02-09 stsp
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
204 49c543a6 2022-03-31 naddy ret=$?
205 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
206 5bda3ef8 2020-02-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
207 5bda3ef8 2020-02-09 stsp fi
208 5bda3ef8 2020-02-09 stsp test_done "$testroot" "$ret"
209 5bda3ef8 2020-02-09 stsp }
210 5bda3ef8 2020-02-09 stsp
211 b2b3fce1 2022-10-29 op test_backout_umask() {
212 b2b3fce1 2022-10-29 op local testroot=`test_init backout_umask`
213 b2b3fce1 2022-10-29 op
214 b2b3fce1 2022-10-29 op got checkout "$testroot/repo" "$testroot/wt" >/dev/null
215 b2b3fce1 2022-10-29 op echo "edit alpha" >$testroot/wt/alpha
216 b2b3fce1 2022-10-29 op (cd "$testroot/wt" && got commit -m 'edit alpha') >/dev/null
217 b2b3fce1 2022-10-29 op ret=$?
218 b2b3fce1 2022-10-29 op if [ $ret -ne 0 ]; then
219 b2b3fce1 2022-10-29 op test_done "$testroot" $ret
220 b2b3fce1 2022-10-29 op return 1
221 b2b3fce1 2022-10-29 op fi
222 b2b3fce1 2022-10-29 op
223 b2b3fce1 2022-10-29 op local commit=`git_show_head "$testroot/repo"`
224 b2b3fce1 2022-10-29 op
225 b2b3fce1 2022-10-29 op (cd "$testroot/wt" && got update) >/dev/null
226 b2b3fce1 2022-10-29 op
227 b2b3fce1 2022-10-29 op # using a subshell to avoid clobbering global umask
228 b2b3fce1 2022-10-29 op (umask 077 && cd "$testroot/wt" && got backout $commit) >/dev/null
229 b2b3fce1 2022-10-29 op ret=$?
230 b2b3fce1 2022-10-29 op if [ $ret -ne 0 ]; then
231 b2b3fce1 2022-10-29 op test_done "$testroot" $ret
232 b2b3fce1 2022-10-29 op return 1
233 b2b3fce1 2022-10-29 op fi
234 b2b3fce1 2022-10-29 op
235 b2b3fce1 2022-10-29 op if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
236 b2b3fce1 2022-10-29 op echo "alpha is not 0600 after backout" >&2
237 b2b3fce1 2022-10-29 op ls -l "$testroot/wt/alpha" >&2
238 b2b3fce1 2022-10-29 op test_done "$testroot" $ret
239 b2b3fce1 2022-10-29 op return 1
240 b2b3fce1 2022-10-29 op fi
241 b2b3fce1 2022-10-29 op
242 b2b3fce1 2022-10-29 op test_done "$testroot" 0
243 b2b3fce1 2022-10-29 op }
244 22d6be81 2023-01-28 mark
245 22d6be81 2023-01-28 mark test_backout_logmsg_ref() {
246 22d6be81 2023-01-28 mark local testroot=`test_init backout_logmsg_ref`
247 22d6be81 2023-01-28 mark
248 22d6be81 2023-01-28 mark got checkout $testroot/repo $testroot/wt > /dev/null
249 22d6be81 2023-01-28 mark ret=$?
250 22d6be81 2023-01-28 mark if [ $ret -ne 0 ]; then
251 22d6be81 2023-01-28 mark test_done "$testroot" "$ret"
252 22d6be81 2023-01-28 mark return 1
253 22d6be81 2023-01-28 mark fi
254 22d6be81 2023-01-28 mark
255 22d6be81 2023-01-28 mark (cd $testroot/repo && git checkout -q -b newbranch)
256 22d6be81 2023-01-28 mark
257 22d6be81 2023-01-28 mark echo "modified delta on branch" > $testroot/repo/gamma/delta
258 22d6be81 2023-01-28 mark echo "modified alpha on branch" > $testroot/repo/alpha
259 22d6be81 2023-01-28 mark (cd $testroot/repo && git rm -q beta)
260 22d6be81 2023-01-28 mark echo "new file on branch" > $testroot/repo/epsilon/new
261 22d6be81 2023-01-28 mark (cd $testroot/repo && git add epsilon/new)
262 b2b3fce1 2022-10-29 op
263 22d6be81 2023-01-28 mark git_commit $testroot/repo -m "commit changes on newbranch"
264 22d6be81 2023-01-28 mark local commit_time=`git_show_author_time $testroot/repo`
265 22d6be81 2023-01-28 mark local branch_rev=`git_show_head $testroot/repo`
266 22d6be81 2023-01-28 mark
267 22d6be81 2023-01-28 mark echo "modified new file on branch" > $testroot/repo/epsilon/new
268 22d6be81 2023-01-28 mark
269 22d6be81 2023-01-28 mark git_commit $testroot/repo -m "commit modified new file on newbranch"
270 22d6be81 2023-01-28 mark local commit_time2=`git_show_author_time $testroot/repo`
271 22d6be81 2023-01-28 mark local branch_rev2=`git_show_head $testroot/repo`
272 22d6be81 2023-01-28 mark
273 22d6be81 2023-01-28 mark (cd $testroot/wt && got backout $branch_rev > /dev/null)
274 22d6be81 2023-01-28 mark (cd $testroot/wt && got backout $branch_rev2 > /dev/null)
275 22d6be81 2023-01-28 mark
276 22d6be81 2023-01-28 mark # show all backout log message refs in the work tree
277 22d6be81 2023-01-28 mark local sep="-----------------------------------------------"
278 22d6be81 2023-01-28 mark local logmsg="commit changes on newbranch"
279 22d6be81 2023-01-28 mark local changeset=" M alpha\n D beta\n A epsilon/new\n M gamma/delta"
280 22d6be81 2023-01-28 mark local logmsg2="commit modified new file on newbranch"
281 22d6be81 2023-01-28 mark local changeset2=" M epsilon/new"
282 22d6be81 2023-01-28 mark local date=`date -u -r $commit_time +"%a %b %e %X %Y UTC"`
283 22d6be81 2023-01-28 mark local date2=`date -u -r $commit_time2 +"%a %b %e %X %Y UTC"`
284 22d6be81 2023-01-28 mark local ymd=`date -u -r $commit_time +"%F"`
285 22d6be81 2023-01-28 mark local short_id=$(printf '%.7s' $branch_rev)
286 22d6be81 2023-01-28 mark local ymd2=`date -u -r $commit_time2 +"%F"`
287 22d6be81 2023-01-28 mark local short_id2="newbranch"
288 466be138 2023-02-01 mark local wt_sorted=$(printf "$branch_rev\n$branch_rev2" | sort)
289 22d6be81 2023-01-28 mark
290 466be138 2023-02-01 mark for r in $wt_sorted; do
291 22d6be81 2023-01-28 mark echo $sep >> $testroot/stdout.expected
292 1a4be250 2023-03-03 thomas if [ $r = $branch_rev ]; then
293 b584caa3 2023-01-30 mark echo "backout $r" >> $testroot/stdout.expected
294 22d6be81 2023-01-28 mark echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
295 22d6be81 2023-01-28 mark echo "date: $date" >> $testroot/stdout.expected
296 22d6be81 2023-01-28 mark printf " \n $logmsg\n \n" >> $testroot/stdout.expected
297 22d6be81 2023-01-28 mark printf "$changeset\n\n" >> $testroot/stdout.expected
298 22d6be81 2023-01-28 mark
299 22d6be81 2023-01-28 mark # for forthcoming wt 'backout -X' test
300 378a2540 2023-01-28 stsp echo "Deleted: $ymd $short_id $logmsg" >> \
301 22d6be81 2023-01-28 mark $testroot/stdout.wt_deleted
302 22d6be81 2023-01-28 mark else
303 b584caa3 2023-01-30 mark echo "backout $r (newbranch)" \
304 22d6be81 2023-01-28 mark >> $testroot/stdout.expected
305 22d6be81 2023-01-28 mark echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
306 22d6be81 2023-01-28 mark echo "date: $date2" >> $testroot/stdout.expected
307 22d6be81 2023-01-28 mark printf " \n $logmsg2\n \n" >> $testroot/stdout.expected
308 22d6be81 2023-01-28 mark printf "$changeset2\n\n" >> $testroot/stdout.expected
309 22d6be81 2023-01-28 mark
310 22d6be81 2023-01-28 mark # for forthcoming wt 'backout -X' test
311 378a2540 2023-01-28 stsp echo "Deleted: $ymd2 $short_id2 $logmsg2" >> \
312 22d6be81 2023-01-28 mark $testroot/stdout.wt_deleted
313 22d6be81 2023-01-28 mark fi
314 22d6be81 2023-01-28 mark done
315 22d6be81 2023-01-28 mark
316 22d6be81 2023-01-28 mark (cd $testroot/wt && got backout -l > $testroot/stdout)
317 22d6be81 2023-01-28 mark
318 22d6be81 2023-01-28 mark cmp -s $testroot/stdout.expected $testroot/stdout
319 22d6be81 2023-01-28 mark ret=$?
320 22d6be81 2023-01-28 mark if [ $ret -ne 0 ]; then
321 22d6be81 2023-01-28 mark diff -u $testroot/stdout.expected $testroot/stdout
322 22d6be81 2023-01-28 mark test_done "$testroot" "$ret"
323 22d6be81 2023-01-28 mark return 1
324 22d6be81 2023-01-28 mark fi
325 22d6be81 2023-01-28 mark
326 22d6be81 2023-01-28 mark # only show log message ref of the specified commit id
327 22d6be81 2023-01-28 mark echo $sep > $testroot/stdout.expected
328 b584caa3 2023-01-30 mark echo "backout $branch_rev" >> $testroot/stdout.expected
329 22d6be81 2023-01-28 mark echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
330 22d6be81 2023-01-28 mark echo "date: $date" >> $testroot/stdout.expected
331 22d6be81 2023-01-28 mark printf " \n $logmsg\n \n" >> $testroot/stdout.expected
332 22d6be81 2023-01-28 mark printf "$changeset\n\n" >> $testroot/stdout.expected
333 22d6be81 2023-01-28 mark
334 22d6be81 2023-01-28 mark (cd $testroot/wt && got backout -l $branch_rev > $testroot/stdout)
335 22d6be81 2023-01-28 mark
336 22d6be81 2023-01-28 mark cmp -s $testroot/stdout.expected $testroot/stdout
337 22d6be81 2023-01-28 mark ret=$?
338 22d6be81 2023-01-28 mark if [ $ret -ne 0 ]; then
339 22d6be81 2023-01-28 mark diff -u $testroot/stdout.expected $testroot/stdout
340 22d6be81 2023-01-28 mark test_done "$testroot" "$ret"
341 22d6be81 2023-01-28 mark return 1
342 22d6be81 2023-01-28 mark fi
343 22d6be81 2023-01-28 mark
344 22d6be81 2023-01-28 mark # only show log message ref of the specified symref
345 22d6be81 2023-01-28 mark echo $sep > $testroot/stdout.expected
346 b584caa3 2023-01-30 mark echo "backout $branch_rev2 (newbranch)" >> $testroot/stdout.expected
347 22d6be81 2023-01-28 mark echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
348 22d6be81 2023-01-28 mark echo "date: $date2" >> $testroot/stdout.expected
349 22d6be81 2023-01-28 mark printf " \n $logmsg2\n \n" >> $testroot/stdout.expected
350 22d6be81 2023-01-28 mark printf "$changeset2\n\n" >> $testroot/stdout.expected
351 22d6be81 2023-01-28 mark
352 22d6be81 2023-01-28 mark (cd $testroot/wt && got backout -l "newbranch" > $testroot/stdout)
353 22d6be81 2023-01-28 mark
354 22d6be81 2023-01-28 mark cmp -s $testroot/stdout.expected $testroot/stdout
355 22d6be81 2023-01-28 mark ret=$?
356 22d6be81 2023-01-28 mark if [ $ret -ne 0 ]; then
357 22d6be81 2023-01-28 mark diff -u $testroot/stdout.expected $testroot/stdout
358 22d6be81 2023-01-28 mark test_done "$testroot" "$ret"
359 22d6be81 2023-01-28 mark return 1
360 22d6be81 2023-01-28 mark fi
361 22d6be81 2023-01-28 mark
362 22d6be81 2023-01-28 mark # create a second work tree with backed-out commits and ensure
363 22d6be81 2023-01-28 mark # bo -l within the new work tree only shows the refs it created
364 22d6be81 2023-01-28 mark got checkout $testroot/repo $testroot/wt2 > /dev/null
365 22d6be81 2023-01-28 mark ret=$?
366 22d6be81 2023-01-28 mark if [ $ret -ne 0 ]; then
367 22d6be81 2023-01-28 mark test_done "$testroot" "$ret"
368 22d6be81 2023-01-28 mark return 1
369 22d6be81 2023-01-28 mark fi
370 22d6be81 2023-01-28 mark
371 22d6be81 2023-01-28 mark (cd $testroot/repo && git checkout -q -b newbranch2)
372 22d6be81 2023-01-28 mark
373 22d6be81 2023-01-28 mark echo "modified delta on branch2" > $testroot/repo/gamma/delta
374 22d6be81 2023-01-28 mark echo "modified alpha on branch2" > $testroot/repo/alpha
375 22d6be81 2023-01-28 mark echo "new file on branch2" > $testroot/repo/epsilon/new2
376 22d6be81 2023-01-28 mark (cd $testroot/repo && git add epsilon/new2)
377 22d6be81 2023-01-28 mark
378 22d6be81 2023-01-28 mark git_commit $testroot/repo -m "commit changes on newbranch2"
379 22d6be81 2023-01-28 mark local b2_commit_time=`git_show_author_time $testroot/repo`
380 22d6be81 2023-01-28 mark local branch2_rev=`git_show_head $testroot/repo`
381 22d6be81 2023-01-28 mark
382 22d6be81 2023-01-28 mark echo "modified file new2 on branch2" > $testroot/repo/epsilon/new2
383 22d6be81 2023-01-28 mark
384 22d6be81 2023-01-28 mark git_commit $testroot/repo -m "commit modified file new2 on newbranch2"
385 22d6be81 2023-01-28 mark local b2_commit_time2=`git_show_author_time $testroot/repo`
386 22d6be81 2023-01-28 mark local branch2_rev2=`git_show_head $testroot/repo`
387 22d6be81 2023-01-28 mark
388 22d6be81 2023-01-28 mark (cd $testroot/wt2 && got backout $branch2_rev > /dev/null)
389 22d6be81 2023-01-28 mark (cd $testroot/wt2 && got backout $branch2_rev2 > /dev/null)
390 22d6be81 2023-01-28 mark
391 22d6be81 2023-01-28 mark local b2_logmsg="commit changes on newbranch2"
392 22d6be81 2023-01-28 mark local b2_changeset=" M alpha\n A epsilon/new2\n M gamma/delta"
393 22d6be81 2023-01-28 mark local b2_logmsg2="commit modified file new2 on newbranch2"
394 22d6be81 2023-01-28 mark local b2_changeset2=" M epsilon/new2"
395 22d6be81 2023-01-28 mark date=`date -u -r $b2_commit_time +"%a %b %e %X %Y UTC"`
396 22d6be81 2023-01-28 mark date2=`date -u -r $b2_commit_time2 +"%a %b %e %X %Y UTC"`
397 466be138 2023-02-01 mark local wt2_sorted=$(printf "$branch2_rev\n$branch2_rev2" | sort)
398 22d6be81 2023-01-28 mark
399 22d6be81 2023-01-28 mark echo -n > $testroot/stdout.expected
400 466be138 2023-02-01 mark for r in $wt2_sorted; do
401 22d6be81 2023-01-28 mark echo $sep >> $testroot/stdout.expected
402 1a4be250 2023-03-03 thomas if [ $r = $branch2_rev ]; then
403 b584caa3 2023-01-30 mark echo "backout $r" >> $testroot/stdout.expected
404 22d6be81 2023-01-28 mark echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
405 22d6be81 2023-01-28 mark echo "date: $date" >> $testroot/stdout.expected
406 22d6be81 2023-01-28 mark printf " \n $b2_logmsg\n \n" >> \
407 22d6be81 2023-01-28 mark $testroot/stdout.expected
408 22d6be81 2023-01-28 mark printf "$b2_changeset\n\n" >> \
409 22d6be81 2023-01-28 mark $testroot/stdout.expected
410 22d6be81 2023-01-28 mark else
411 b584caa3 2023-01-30 mark echo "backout $r (newbranch2)" \
412 22d6be81 2023-01-28 mark >> $testroot/stdout.expected
413 22d6be81 2023-01-28 mark echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
414 22d6be81 2023-01-28 mark echo "date: $date2" >> $testroot/stdout.expected
415 22d6be81 2023-01-28 mark printf " \n $b2_logmsg2\n \n" >> \
416 22d6be81 2023-01-28 mark $testroot/stdout.expected
417 22d6be81 2023-01-28 mark printf "$b2_changeset2\n\n" >> \
418 22d6be81 2023-01-28 mark $testroot/stdout.expected
419 22d6be81 2023-01-28 mark fi
420 22d6be81 2023-01-28 mark done
421 22d6be81 2023-01-28 mark
422 22d6be81 2023-01-28 mark (cd $testroot/wt2 && got backout -l > $testroot/stdout)
423 22d6be81 2023-01-28 mark
424 22d6be81 2023-01-28 mark cmp -s $testroot/stdout.expected $testroot/stdout
425 22d6be81 2023-01-28 mark ret=$?
426 22d6be81 2023-01-28 mark if [ $ret -ne 0 ]; then
427 22d6be81 2023-01-28 mark diff -u $testroot/stdout.expected $testroot/stdout
428 22d6be81 2023-01-28 mark test_done "$testroot" "$ret"
429 22d6be81 2023-01-28 mark return 1
430 22d6be81 2023-01-28 mark fi
431 22d6be81 2023-01-28 mark
432 466be138 2023-02-01 mark # ensure both wt and wt2 logmsg refs can be retrieved and the
433 466be138 2023-02-01 mark # work tree UUID is displayed when listing refs from the repo
434 466be138 2023-02-01 mark local wt_uuid=$(cat $testroot/wt/.got/uuid)
435 466be138 2023-02-01 mark local wt2_uuid=$(cat $testroot/wt2/.got/uuid)
436 466be138 2023-02-01 mark local wt_first=`printf "$wt_uuid\n$wt2_uuid" | sort | head -1`
437 22d6be81 2023-01-28 mark
438 466be138 2023-02-01 mark for r in $wt_sorted; do
439 466be138 2023-02-01 mark echo -n "backout $r" >> $testroot/wt.list
440 1a4be250 2023-03-03 thomas if [ $r = $branch_rev2 ]; then
441 466be138 2023-02-01 mark echo -n " (newbranch)" >> $testroot/wt.list
442 466be138 2023-02-01 mark fi
443 466be138 2023-02-01 mark echo >> $testroot/wt.list
444 466be138 2023-02-01 mark echo "work tree: $wt_uuid" >> $testroot/wt.list
445 22d6be81 2023-01-28 mark done
446 22d6be81 2023-01-28 mark
447 466be138 2023-02-01 mark for r in $wt2_sorted; do
448 466be138 2023-02-01 mark echo -n "backout $r" >> $testroot/wt2.list
449 1a4be250 2023-03-03 thomas if [ $r = $branch2_rev2 ]; then
450 466be138 2023-02-01 mark echo -n " (newbranch2)" >> $testroot/wt2.list
451 466be138 2023-02-01 mark fi
452 466be138 2023-02-01 mark echo >> $testroot/wt2.list
453 466be138 2023-02-01 mark echo "work tree: $wt2_uuid" >> $testroot/wt2.list
454 466be138 2023-02-01 mark done
455 22d6be81 2023-01-28 mark
456 1a4be250 2023-03-03 thomas if [ $wt_uuid = $wt_first ]; then
457 466be138 2023-02-01 mark mv $testroot/wt.list $testroot/stdout.expected
458 466be138 2023-02-01 mark cat $testroot/wt2.list >> $testroot/stdout.expected
459 466be138 2023-02-01 mark else
460 466be138 2023-02-01 mark mv $testroot/wt2.list $testroot/stdout.expected
461 466be138 2023-02-01 mark cat $testroot/wt.list >> $testroot/stdout.expected
462 466be138 2023-02-01 mark fi
463 466be138 2023-02-01 mark
464 466be138 2023-02-01 mark (cd $testroot/repo && got backout -l | egrep "^(backout|work)" \
465 466be138 2023-02-01 mark > $testroot/stdout)
466 466be138 2023-02-01 mark
467 22d6be81 2023-01-28 mark cmp -s $testroot/stdout.expected $testroot/stdout
468 22d6be81 2023-01-28 mark ret=$?
469 22d6be81 2023-01-28 mark if [ $ret -ne 0 ]; then
470 22d6be81 2023-01-28 mark diff -u $testroot/stdout.expected $testroot/stdout
471 22d6be81 2023-01-28 mark test_done "$testroot" "$ret"
472 22d6be81 2023-01-28 mark return 1
473 22d6be81 2023-01-28 mark fi
474 22d6be81 2023-01-28 mark
475 22d6be81 2023-01-28 mark # delete logmsg ref of the specified commit in work tree 2
476 22d6be81 2023-01-28 mark ymd=`date -u -r $b2_commit_time +"%F"`
477 22d6be81 2023-01-28 mark short_id=$(printf '%.7s' $branch2_rev)
478 22d6be81 2023-01-28 mark
479 378a2540 2023-01-28 stsp echo "Deleted: $ymd $short_id $b2_logmsg" > $testroot/stdout.expected
480 22d6be81 2023-01-28 mark (cd $testroot/wt2 && got backout -X $branch2_rev > $testroot/stdout)
481 22d6be81 2023-01-28 mark
482 22d6be81 2023-01-28 mark cmp -s $testroot/stdout.expected $testroot/stdout
483 22d6be81 2023-01-28 mark ret=$?
484 22d6be81 2023-01-28 mark if [ $ret -ne 0 ]; then
485 22d6be81 2023-01-28 mark diff -u $testroot/stdout.expected $testroot/stdout
486 22d6be81 2023-01-28 mark test_done "$testroot" "$ret"
487 22d6be81 2023-01-28 mark return 1
488 22d6be81 2023-01-28 mark fi
489 22d6be81 2023-01-28 mark
490 22d6be81 2023-01-28 mark # delete all logmsg refs in work tree 1
491 22d6be81 2023-01-28 mark (cd $testroot && mv stdout.wt_deleted stdout.expected)
492 22d6be81 2023-01-28 mark (cd $testroot/wt && got backout -X > $testroot/stdout)
493 22d6be81 2023-01-28 mark
494 22d6be81 2023-01-28 mark cmp -s $testroot/stdout.expected $testroot/stdout
495 22d6be81 2023-01-28 mark ret=$?
496 22d6be81 2023-01-28 mark if [ $ret -ne 0 ]; then
497 22d6be81 2023-01-28 mark diff -u $testroot/stdout.expected $testroot/stdout
498 22d6be81 2023-01-28 mark test_done "$testroot" "$ret"
499 22d6be81 2023-01-28 mark return 1
500 22d6be81 2023-01-28 mark fi
501 22d6be81 2023-01-28 mark
502 22d6be81 2023-01-28 mark # confirm all work tree 1 refs were deleted
503 22d6be81 2023-01-28 mark echo -n > $testroot/stdout.expected
504 22d6be81 2023-01-28 mark (cd $testroot/wt && got backout -l > $testroot/stdout)
505 22d6be81 2023-01-28 mark
506 22d6be81 2023-01-28 mark cmp -s $testroot/stdout.expected $testroot/stdout
507 22d6be81 2023-01-28 mark ret=$?
508 22d6be81 2023-01-28 mark if [ $ret -ne 0 ]; then
509 22d6be81 2023-01-28 mark diff -u $testroot/stdout.expected $testroot/stdout
510 22d6be81 2023-01-28 mark test_done "$testroot" "$ret"
511 22d6be81 2023-01-28 mark return 1
512 22d6be81 2023-01-28 mark fi
513 22d6be81 2023-01-28 mark
514 22d6be81 2023-01-28 mark # make sure the remaining ref in work tree 2 was not also deleted
515 22d6be81 2023-01-28 mark echo $sep > $testroot/stdout.expected
516 b584caa3 2023-01-30 mark echo "backout $branch2_rev2 (newbranch2)" >> $testroot/stdout.expected
517 22d6be81 2023-01-28 mark echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected
518 22d6be81 2023-01-28 mark echo "date: $date2" >> $testroot/stdout.expected
519 22d6be81 2023-01-28 mark printf " \n $b2_logmsg2\n \n" >> $testroot/stdout.expected
520 22d6be81 2023-01-28 mark printf "$b2_changeset2\n\n" >> $testroot/stdout.expected
521 22d6be81 2023-01-28 mark
522 22d6be81 2023-01-28 mark (cd $testroot/wt2 && got backout -l > $testroot/stdout)
523 22d6be81 2023-01-28 mark
524 22d6be81 2023-01-28 mark cmp -s $testroot/stdout.expected $testroot/stdout
525 22d6be81 2023-01-28 mark ret=$?
526 22d6be81 2023-01-28 mark if [ $ret -ne 0 ]; then
527 22d6be81 2023-01-28 mark diff -u $testroot/stdout.expected $testroot/stdout
528 22d6be81 2023-01-28 mark test_done "$testroot" "$ret"
529 22d6be81 2023-01-28 mark return 1
530 22d6be81 2023-01-28 mark fi
531 22d6be81 2023-01-28 mark
532 22d6be81 2023-01-28 mark # ensure we can delete work tree refs from the repository dir
533 22d6be81 2023-01-28 mark ymd=`date -u -r $b2_commit_time2 +"%F"`
534 378a2540 2023-01-28 stsp echo "Deleted: $ymd newbranch2 $b2_logmsg2" > $testroot/stdout.expected
535 22d6be81 2023-01-28 mark (cd $testroot/repo && got backout -X > $testroot/stdout)
536 22d6be81 2023-01-28 mark
537 22d6be81 2023-01-28 mark cmp -s $testroot/stdout.expected $testroot/stdout
538 22d6be81 2023-01-28 mark ret=$?
539 22d6be81 2023-01-28 mark if [ $ret -ne 0 ]; then
540 22d6be81 2023-01-28 mark diff -u $testroot/stdout.expected $testroot/stdout
541 22d6be81 2023-01-28 mark fi
542 22d6be81 2023-01-28 mark
543 22d6be81 2023-01-28 mark test_done "$testroot" "$ret"
544 22d6be81 2023-01-28 mark }
545 22d6be81 2023-01-28 mark
546 7fb414ae 2020-08-08 stsp test_parseargs "$@"
547 5ef14e63 2019-06-02 stsp run_test test_backout_basic
548 5bda3ef8 2020-02-09 stsp run_test test_backout_edits_for_file_since_deleted
549 5bda3ef8 2020-02-09 stsp run_test test_backout_next_commit
550 b2b3fce1 2022-10-29 op run_test test_backout_umask
551 22d6be81 2023-01-28 mark run_test test_backout_logmsg_ref