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 b2b3fce1 2022-10-29 op
245 7fb414ae 2020-08-08 stsp test_parseargs "$@"
246 5ef14e63 2019-06-02 stsp run_test test_backout_basic
247 5bda3ef8 2020-02-09 stsp run_test test_backout_edits_for_file_since_deleted
248 5bda3ef8 2020-02-09 stsp run_test test_backout_next_commit
249 b2b3fce1 2022-10-29 op run_test test_backout_umask