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" != "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" != "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" != "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" != "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" != "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 cmp -s $testroot/stdout.expected $testroot/stdout
121 ret="$?"
122 if [ "$ret" != "0" ]; then
123 diff -u $testroot/stdout.expected $testroot/stdout
124 test_done "$testroot" "$ret"
125 return 1
126 fi
128 if [ -e "$testroot/wt/alpha" ]; then
129 echo "file '$testroot/wt/alpha' still exists on disk" >&2
130 test_done "$testroot" "$ret"
131 return 1
132 fi
134 echo -n '' > $testroot/stdout.expected
135 (cd $testroot/wt && got status > $testroot/stdout)
136 cmp -s $testroot/stdout.expected $testroot/stdout
137 ret="$?"
138 if [ "$ret" != "0" ]; then
139 diff -u $testroot/stdout.expected $testroot/stdout
140 fi
141 test_done "$testroot" "$ret"
144 test_backout_next_commit() {
145 local testroot=`test_init backout_next_commit`
146 local commit0=`git_show_head $testroot/repo`
148 got checkout $testroot/repo $testroot/wt > /dev/null
149 ret="$?"
150 if [ "$ret" != "0" ]; then
151 test_done "$testroot" "$ret"
152 return 1
153 fi
155 echo "new" > $testroot/wt/new
156 (cd $testroot/wt && got add new > /dev/null)
157 echo "modified alpha" > $testroot/wt/alpha
158 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
159 (cd $testroot/wt && got commit -m "bad changes" > /dev/null)
161 local bad_commit=`git_show_head $testroot/repo`
163 (cd $testroot/wt && got update -c $commit0 > /dev/null)
165 (cd $testroot/wt && got backout $bad_commit > $testroot/stdout)
167 echo "G alpha" > $testroot/stdout.expected
168 echo "G epsilon/zeta" >> $testroot/stdout.expected
169 echo "! new" >> $testroot/stdout.expected
170 echo "Backed out commit $bad_commit" >> $testroot/stdout.expected
171 cmp -s $testroot/stdout.expected $testroot/stdout
172 ret="$?"
173 if [ "$ret" != "0" ]; then
174 diff -u $testroot/stdout.expected $testroot/stdout
175 test_done "$testroot" "$ret"
176 return 1
177 fi
179 if [ -e "$testroot/wt/new" ]; then
180 echo "file '$testroot/wt/new' still exists on disk" >&2
181 test_done "$testroot" "$ret"
182 return 1
183 fi
185 echo "zeta" > $testroot/content.expected
186 cat $testroot/wt/epsilon/zeta > $testroot/content
187 cmp -s $testroot/content.expected $testroot/content
188 ret="$?"
189 if [ "$ret" != "0" ]; then
190 diff -u $testroot/content.expected $testroot/content
191 test_done "$testroot" "$ret"
192 return 1
193 fi
195 echo -n '' > $testroot/stdout.expected
196 (cd $testroot/wt && got status > $testroot/stdout)
197 cmp -s $testroot/stdout.expected $testroot/stdout
198 ret="$?"
199 if [ "$ret" != "0" ]; then
200 diff -u $testroot/stdout.expected $testroot/stdout
201 fi
202 test_done "$testroot" "$ret"
205 test_parseargs "$@"
206 run_test test_backout_basic
207 run_test test_backout_edits_for_file_since_deleted
208 run_test test_backout_next_commit