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 function test_update_basic {
20 local testroot=`test_init update_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 if [ "$?" != "0" ]; then
24 test_done "$testroot" "$?"
25 return 1
26 fi
28 echo "modified alpha" > $testroot/repo/alpha
29 git_commit $testroot/repo -m "modified alpha"
31 echo "U alpha" > $testroot/stdout.expected
32 echo -n "Updated to commit " >> $testroot/stdout.expected
33 git_show_head $testroot/repo >> $testroot/stdout.expected
34 echo >> $testroot/stdout.expected
36 (cd $testroot/wt && got update > $testroot/stdout)
38 cmp $testroot/stdout.expected $testroot/stdout
39 if [ "$?" != "0" ]; then
40 diff -u $testroot/stdout.expected $testroot/stdout
41 test_done "$testroot" "$?"
42 return 1
43 fi
45 echo "modified alpha" > $testroot/content.expected
46 cat $testroot/wt/alpha > $testroot/content
48 cmp $testroot/content.expected $testroot/content
49 ret="$?"
50 if [ "$ret" != "0" ]; then
51 diff -u $testroot/content.expected $testroot/content
52 fi
53 test_done "$testroot" "$ret"
54 }
56 function test_update_adds_file {
57 local testroot=`test_init update_adds_file`
59 got checkout $testroot/repo $testroot/wt > /dev/null
60 if [ "$?" != "0" ]; then
61 test_done "$testroot" "$?"
62 return 1
63 fi
65 echo "new" > $testroot/repo/gamma/new
66 (cd $testroot/repo && git add .)
67 git_commit $testroot/repo -m "adding a new file"
69 echo "A gamma/new" > $testroot/stdout.expected
70 echo -n "Updated to commit " >> $testroot/stdout.expected
71 git_show_head $testroot/repo >> $testroot/stdout.expected
72 echo >> $testroot/stdout.expected
74 (cd $testroot/wt && got update > $testroot/stdout)
76 cmp $testroot/stdout.expected $testroot/stdout
77 if [ "$?" != "0" ]; then
78 diff -u $testroot/stdout.expected $testroot/stdout
79 test_done "$testroot" "$?"
80 return 1
81 fi
83 echo "new" >> $testroot/content.expected
84 cat $testroot/wt/gamma/new > $testroot/content
86 cmp $testroot/content.expected $testroot/content
87 ret="$?"
88 if [ "$ret" != "0" ]; then
89 diff -u $testroot/content.expected $testroot/content
90 fi
91 test_done "$testroot" "$ret"
92 }
94 function test_update_deletes_file {
95 local testroot=`test_init update_deletes_file`
97 got checkout $testroot/repo $testroot/wt > /dev/null
98 if [ "$?" != "0" ]; then
99 test_done "$testroot" "$?"
100 return 1
101 fi
103 (cd $testroot/repo && git_rm $testroot/repo beta)
104 git_commit $testroot/repo -m "deleting a file"
106 echo "D beta" > $testroot/stdout.expected
107 echo -n "Updated to commit " >> $testroot/stdout.expected
108 git_show_head $testroot/repo >> $testroot/stdout.expected
109 echo >> $testroot/stdout.expected
111 (cd $testroot/wt && got update > $testroot/stdout)
113 cmp $testroot/stdout.expected $testroot/stdout
114 if [ "$?" != "0" ]; then
115 diff -u $testroot/stdout.expected $testroot/stdout
116 test_done "$testroot" "$?"
117 return 1
118 fi
120 if [ -e $testroot/wt/beta ]; then
121 echo "removed file beta still exists on disk" >&2
122 test_done "$testroot" "1"
123 return 1
124 fi
126 test_done "$testroot" "0"
129 function test_update_deletes_dir {
130 local testroot=`test_init update_deletes_dir`
132 got checkout $testroot/repo $testroot/wt > /dev/null
133 if [ "$?" != "0" ]; then
134 test_done "$testroot" "$?"
135 return 1
136 fi
138 (cd $testroot/repo && git_rm $testroot/repo -r epsilon)
139 git_commit $testroot/repo -m "deleting a directory"
141 echo "D epsilon/zeta" > $testroot/stdout.expected
142 echo -n "Updated to commit " >> $testroot/stdout.expected
143 git_show_head $testroot/repo >> $testroot/stdout.expected
144 echo >> $testroot/stdout.expected
146 (cd $testroot/wt && got update > $testroot/stdout)
148 cmp $testroot/stdout.expected $testroot/stdout
149 if [ "$?" != "0" ]; then
150 diff -u $testroot/stdout.expected $testroot/stdout
151 test_done "$testroot" "$?"
152 return 1
153 fi
155 if [ -e $testroot/wt/epsilon ]; then
156 echo "removed dir epsilon still exists on disk" >&2
157 test_done "$testroot" "1"
158 return 1
159 fi
161 test_done "$testroot" "0"
164 function test_update_deletes_dir_with_path_prefix {
165 local testroot=`test_init update_deletes_dir_with_path_prefix`
166 local first_rev=`git_show_head $testroot/repo`
168 mkdir $testroot/repo/epsilon/psi
169 echo mu > $testroot/repo/epsilon/psi/mu
170 (cd $testroot/repo && git add .)
171 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
173 # check out the epsilon/ sub-tree
174 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
175 if [ "$?" != "0" ]; then
176 test_done "$testroot" "$?"
177 return 1
178 fi
180 # update back to first commit and expect psi/mu to be deleted
181 echo "D psi/mu" > $testroot/stdout.expected
182 echo "Updated to commit $first_rev" >> $testroot/stdout.expected
184 (cd $testroot/wt && got update -c $first_rev > $testroot/stdout)
186 cmp $testroot/stdout.expected $testroot/stdout
187 if [ "$?" != "0" ]; then
188 diff -u $testroot/stdout.expected $testroot/stdout
189 test_done "$testroot" "$?"
190 return 1
191 fi
193 if [ -e $testroot/wt/psi ]; then
194 echo "removed dir psi still exists on disk" >&2
195 test_done "$testroot" "1"
196 return 1
197 fi
199 test_done "$testroot" "0"
202 run_test test_update_basic
203 run_test test_update_adds_file
204 run_test test_update_deletes_file
205 run_test test_update_deletes_dir
206 run_test test_update_deletes_dir_with_path_prefix