3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
19 test_backout_basic
() {
20 local testroot
=`test_init backout_basic`
22 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
24 if [ "$ret" != "0" ]; then
25 test_done
"$testroot" "$ret"
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
53 if [ "$ret" != "0" ]; then
54 diff -u $testroot/stdout.expected
$testroot/stdout
55 test_done
"$testroot" "$ret"
59 echo "alpha" > $testroot/content.expected
60 cat $testroot/wt
/alpha
> $testroot/content
61 cmp -s $testroot/content.expected
$testroot/content
63 if [ "$ret" != "0" ]; then
64 diff -u $testroot/content.expected
$testroot/content
65 test_done
"$testroot" "$ret"
69 if [ -e "$testroot/wt/new" ]; then
70 echo "file '$testroot/wt/new' still exists on disk" >&2
71 test_done
"$testroot" "$ret"
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"
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
87 if [ "$ret" != "0" ]; then
88 diff -u $testroot/stdout.expected
$testroot/stdout
90 test_done
"$testroot" "$ret"
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
98 if [ "$ret" != "0" ]; then
99 test_done
"$testroot" "$ret"
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
125 if [ "$ret" != "0" ]; then
126 diff -u $testroot/stdout.expected
$testroot/stdout
127 test_done
"$testroot" "$ret"
131 if [ -e "$testroot/wt/alpha" ]; then
132 echo "file '$testroot/wt/alpha' still exists on disk" >&2
133 test_done
"$testroot" "$ret"
137 echo -n '' > $testroot/stdout.expected
138 (cd $testroot/wt
&& got status
> $testroot/stdout
)
139 cmp -s $testroot/stdout.expected
$testroot/stdout
141 if [ "$ret" != "0" ]; then
142 diff -u $testroot/stdout.expected
$testroot/stdout
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
153 if [ "$ret" != "0" ]; then
154 test_done
"$testroot" "$ret"
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
179 if [ "$ret" != "0" ]; then
180 diff -u $testroot/stdout.expected
$testroot/stdout
181 test_done
"$testroot" "$ret"
185 if [ -e "$testroot/wt/new" ]; then
186 echo "file '$testroot/wt/new' still exists on disk" >&2
187 test_done
"$testroot" "$ret"
191 echo "zeta" > $testroot/content.expected
192 cat $testroot/wt
/epsilon
/zeta
> $testroot/content
193 cmp -s $testroot/content.expected
$testroot/content
195 if [ "$ret" != "0" ]; then
196 diff -u $testroot/content.expected
$testroot/content
197 test_done
"$testroot" "$ret"
201 echo -n '' > $testroot/stdout.expected
202 (cd $testroot/wt
&& got status
> $testroot/stdout
)
203 cmp -s $testroot/stdout.expected
$testroot/stdout
205 if [ "$ret" != "0" ]; then
206 diff -u $testroot/stdout.expected
$testroot/stdout
208 test_done
"$testroot" "$ret"
212 run_test test_backout_basic
213 run_test test_backout_edits_for_file_since_deleted
214 run_test test_backout_next_commit