Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_backout_basic() {
20 local testroot=`test_init backout_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret=$?
24 if [ $ret -ne 0 ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 echo "new" > $testroot/wt/new
30 (cd $testroot/wt && got add new > /dev/null)
31 echo "modified alpha" > $testroot/wt/alpha
32 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
33 (cd $testroot/wt && got commit -m "bad changes" > /dev/null)
35 local bad_commit=`git_show_head $testroot/repo`
38 (cd $testroot/wt && got update > /dev/null)
40 echo "modified beta" > $testroot/wt/beta
41 (cd $testroot/wt && got commit -m "changing beta" > /dev/null)
43 (cd $testroot/wt && got update > /dev/null)
45 (cd $testroot/wt && got backout $bad_commit > $testroot/stdout)
47 echo "G alpha" > $testroot/stdout.expected
48 echo "A epsilon/zeta" >> $testroot/stdout.expected
49 echo "D new" >> $testroot/stdout.expected
50 echo "Backed out commit $bad_commit" >> $testroot/stdout.expected
51 cmp -s $testroot/stdout.expected $testroot/stdout
52 ret=$?
53 if [ $ret -ne 0 ]; then
54 diff -u $testroot/stdout.expected $testroot/stdout
55 test_done "$testroot" "$ret"
56 return 1
57 fi
59 echo "alpha" > $testroot/content.expected
60 cat $testroot/wt/alpha > $testroot/content
61 cmp -s $testroot/content.expected $testroot/content
62 ret=$?
63 if [ $ret -ne 0 ]; then
64 diff -u $testroot/content.expected $testroot/content
65 test_done "$testroot" "$ret"
66 return 1
67 fi
69 if [ -e "$testroot/wt/new" ]; then
70 echo "file '$testroot/wt/new' still exists on disk" >&2
71 test_done "$testroot" "$ret"
72 return 1
73 fi
75 if [ ! -e "$testroot/wt/epsilon/zeta" ]; then
76 echo "file '$testroot/wt/epsilon/zeta' is missing on disk" >&2
77 test_done "$testroot" "$ret"
78 return 1
79 fi
81 echo 'M alpha' > $testroot/stdout.expected
82 echo 'A epsilon/zeta' >> $testroot/stdout.expected
83 echo 'D new' >> $testroot/stdout.expected
84 (cd $testroot/wt && got status > $testroot/stdout)
85 cmp -s $testroot/stdout.expected $testroot/stdout
86 ret=$?
87 if [ $ret -ne 0 ]; then
88 diff -u $testroot/stdout.expected $testroot/stdout
89 fi
90 test_done "$testroot" "$ret"
91 }
93 test_backout_edits_for_file_since_deleted() {
94 local testroot=`test_init backout_edits_for_file_since_deleted`
96 got checkout $testroot/repo $testroot/wt > /dev/null
97 ret=$?
98 if [ $ret -ne 0 ]; then
99 test_done "$testroot" "$ret"
100 return 1
101 fi
103 echo "modified alpha" > $testroot/wt/alpha
104 (cd $testroot/wt && got commit -m "changing alpha" > /dev/null)
106 local bad_commit=`git_show_head $testroot/repo`
109 (cd $testroot/wt && got update > /dev/null)
111 (cd $testroot/wt && got rm alpha > /dev/null)
112 (cd $testroot/wt && got commit -m "removing alpha" > /dev/null)
114 (cd $testroot/wt && got update > /dev/null)
116 (cd $testroot/wt && got backout $bad_commit > $testroot/stdout)
118 echo "! alpha" > $testroot/stdout.expected
119 echo "Backed out commit $bad_commit" >> $testroot/stdout.expected
120 echo -n "Files which had incoming changes but could not be found " \
121 >> $testroot/stdout.expected
122 echo "in the work tree: 1" >> $testroot/stdout.expected
123 cmp -s $testroot/stdout.expected $testroot/stdout
124 ret=$?
125 if [ $ret -ne 0 ]; then
126 diff -u $testroot/stdout.expected $testroot/stdout
127 test_done "$testroot" "$ret"
128 return 1
129 fi
131 if [ -e "$testroot/wt/alpha" ]; then
132 echo "file '$testroot/wt/alpha' still exists on disk" >&2
133 test_done "$testroot" "$ret"
134 return 1
135 fi
137 echo -n '' > $testroot/stdout.expected
138 (cd $testroot/wt && got status > $testroot/stdout)
139 cmp -s $testroot/stdout.expected $testroot/stdout
140 ret=$?
141 if [ $ret -ne 0 ]; then
142 diff -u $testroot/stdout.expected $testroot/stdout
143 fi
144 test_done "$testroot" "$ret"
147 test_backout_next_commit() {
148 local testroot=`test_init backout_next_commit`
149 local commit0=`git_show_head $testroot/repo`
151 got checkout $testroot/repo $testroot/wt > /dev/null
152 ret=$?
153 if [ $ret -ne 0 ]; then
154 test_done "$testroot" "$ret"
155 return 1
156 fi
158 echo "new" > $testroot/wt/new
159 (cd $testroot/wt && got add new > /dev/null)
160 echo "modified alpha" > $testroot/wt/alpha
161 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
162 (cd $testroot/wt && got commit -m "bad changes" > /dev/null)
164 local bad_commit=`git_show_head $testroot/repo`
166 (cd $testroot/wt && got update -c $commit0 > /dev/null)
168 (cd $testroot/wt && got backout $bad_commit > $testroot/stdout)
170 echo "G alpha" > $testroot/stdout.expected
171 echo "G epsilon/zeta" >> $testroot/stdout.expected
172 echo "! new" >> $testroot/stdout.expected
173 echo "Backed out commit $bad_commit" >> $testroot/stdout.expected
174 echo -n "Files which had incoming changes but could not be found " \
175 >> $testroot/stdout.expected
176 echo "in the work tree: 1" >> $testroot/stdout.expected
177 cmp -s $testroot/stdout.expected $testroot/stdout
178 ret=$?
179 if [ $ret -ne 0 ]; then
180 diff -u $testroot/stdout.expected $testroot/stdout
181 test_done "$testroot" "$ret"
182 return 1
183 fi
185 if [ -e "$testroot/wt/new" ]; then
186 echo "file '$testroot/wt/new' still exists on disk" >&2
187 test_done "$testroot" "$ret"
188 return 1
189 fi
191 echo "zeta" > $testroot/content.expected
192 cat $testroot/wt/epsilon/zeta > $testroot/content
193 cmp -s $testroot/content.expected $testroot/content
194 ret=$?
195 if [ $ret -ne 0 ]; then
196 diff -u $testroot/content.expected $testroot/content
197 test_done "$testroot" "$ret"
198 return 1
199 fi
201 echo -n '' > $testroot/stdout.expected
202 (cd $testroot/wt && got status > $testroot/stdout)
203 cmp -s $testroot/stdout.expected $testroot/stdout
204 ret=$?
205 if [ $ret -ne 0 ]; then
206 diff -u $testroot/stdout.expected $testroot/stdout
207 fi
208 test_done "$testroot" "$ret"
211 test_backout_umask() {
212 local testroot=`test_init backout_umask`
214 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
215 echo "edit alpha" >$testroot/wt/alpha
216 (cd "$testroot/wt" && got commit -m 'edit alpha') >/dev/null
217 ret=$?
218 if [ $ret -ne 0 ]; then
219 test_done "$testroot" $ret
220 return 1
221 fi
223 local commit=`git_show_head "$testroot/repo"`
225 (cd "$testroot/wt" && got update) >/dev/null
227 # using a subshell to avoid clobbering global umask
228 (umask 077 && cd "$testroot/wt" && got backout $commit) >/dev/null
229 ret=$?
230 if [ $ret -ne 0 ]; then
231 test_done "$testroot" $ret
232 return 1
233 fi
235 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
236 echo "alpha is not 0600 after backout" >&2
237 ls -l "$testroot/wt/alpha" >&2
238 test_done "$testroot" $ret
239 return 1
240 fi
242 test_done "$testroot" 0
245 test_parseargs "$@"
246 run_test test_backout_basic
247 run_test test_backout_edits_for_file_since_deleted
248 run_test test_backout_next_commit
249 run_test test_backout_umask