3 c84d8c75 2019-01-02 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 c84d8c75 2019-01-02 stsp # Permission to use, copy, modify, and distribute this software for any
6 c84d8c75 2019-01-02 stsp # purpose with or without fee is hereby granted, provided that the above
7 c84d8c75 2019-01-02 stsp # copyright notice and this permission notice appear in all copies.
9 c84d8c75 2019-01-02 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 c84d8c75 2019-01-02 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 c84d8c75 2019-01-02 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 c84d8c75 2019-01-02 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 c84d8c75 2019-01-02 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 c84d8c75 2019-01-02 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 c84d8c75 2019-01-02 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 c84d8c75 2019-01-02 stsp . ./common.sh
19 c84d8c75 2019-01-02 stsp function test_update_basic {
20 0fbd721f 2019-01-02 stsp local testroot=`test_init update_basic`
22 3c90ba67 2019-01-02 stsp got checkout $testroot/repo $testroot/wt > /dev/null
23 c84d8c75 2019-01-02 stsp if [ "$?" != "0" ]; then
24 c84d8c75 2019-01-02 stsp test_done "$testroot" "$?"
28 c84d8c75 2019-01-02 stsp echo "modified alpha" > $testroot/repo/alpha
29 c84d8c75 2019-01-02 stsp git_commit $testroot/repo -m "modified alpha"
31 c84d8c75 2019-01-02 stsp echo "U alpha" > $testroot/stdout.expected
32 9c4b8182 2019-01-02 stsp echo -n "Updated to commit " >> $testroot/stdout.expected
33 9c4b8182 2019-01-02 stsp git_show_head $testroot/repo >> $testroot/stdout.expected
34 9c4b8182 2019-01-02 stsp echo >> $testroot/stdout.expected
36 c84d8c75 2019-01-02 stsp (cd $testroot/wt && got update > $testroot/stdout)
38 c84d8c75 2019-01-02 stsp cmp $testroot/stdout.expected $testroot/stdout
39 c84d8c75 2019-01-02 stsp if [ "$?" != "0" ]; then
40 c84d8c75 2019-01-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
41 c84d8c75 2019-01-02 stsp test_done "$testroot" "$?"
45 c84d8c75 2019-01-02 stsp echo "modified alpha" > $testroot/content.expected
46 52a3df9b 2019-01-06 stsp cat $testroot/wt/alpha > $testroot/content
48 c84d8c75 2019-01-02 stsp cmp $testroot/content.expected $testroot/content
50 693719bc 2019-01-03 stsp if [ "$ret" != "0" ]; then
51 c84d8c75 2019-01-02 stsp diff -u $testroot/content.expected $testroot/content
53 693719bc 2019-01-03 stsp test_done "$testroot" "$ret"
56 3b4d3732 2019-01-02 stsp function test_update_adds_file {
57 3b4d3732 2019-01-02 stsp local testroot=`test_init update_adds_file`
59 3b4d3732 2019-01-02 stsp got checkout $testroot/repo $testroot/wt > /dev/null
60 3b4d3732 2019-01-02 stsp if [ "$?" != "0" ]; then
61 3b4d3732 2019-01-02 stsp test_done "$testroot" "$?"
65 3b4d3732 2019-01-02 stsp echo "new" > $testroot/repo/gamma/new
66 3b4d3732 2019-01-02 stsp (cd $testroot/repo && git add .)
67 3b4d3732 2019-01-02 stsp git_commit $testroot/repo -m "adding a new file"
69 3b4d3732 2019-01-02 stsp echo "A gamma/new" > $testroot/stdout.expected
70 3b4d3732 2019-01-02 stsp echo -n "Updated to commit " >> $testroot/stdout.expected
71 3b4d3732 2019-01-02 stsp git_show_head $testroot/repo >> $testroot/stdout.expected
72 3b4d3732 2019-01-02 stsp echo >> $testroot/stdout.expected
74 3b4d3732 2019-01-02 stsp (cd $testroot/wt && got update > $testroot/stdout)
76 3b4d3732 2019-01-02 stsp cmp $testroot/stdout.expected $testroot/stdout
77 3b4d3732 2019-01-02 stsp if [ "$?" != "0" ]; then
78 3b4d3732 2019-01-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
79 3b4d3732 2019-01-02 stsp test_done "$testroot" "$?"
83 3b4d3732 2019-01-02 stsp echo "new" >> $testroot/content.expected
84 52a3df9b 2019-01-06 stsp cat $testroot/wt/gamma/new > $testroot/content
86 3b4d3732 2019-01-02 stsp cmp $testroot/content.expected $testroot/content
88 693719bc 2019-01-03 stsp if [ "$ret" != "0" ]; then
89 3b4d3732 2019-01-02 stsp diff -u $testroot/content.expected $testroot/content
91 693719bc 2019-01-03 stsp test_done "$testroot" "$ret"
94 512f0d0e 2019-01-02 stsp function test_update_deletes_file {
95 512f0d0e 2019-01-02 stsp local testroot=`test_init update_deletes_file`
97 512f0d0e 2019-01-02 stsp got checkout $testroot/repo $testroot/wt > /dev/null
98 512f0d0e 2019-01-02 stsp if [ "$?" != "0" ]; then
99 512f0d0e 2019-01-02 stsp test_done "$testroot" "$?"
103 512f0d0e 2019-01-02 stsp (cd $testroot/repo && git_rm $testroot/repo beta)
104 512f0d0e 2019-01-02 stsp git_commit $testroot/repo -m "deleting a file"
106 512f0d0e 2019-01-02 stsp echo "D beta" > $testroot/stdout.expected
107 512f0d0e 2019-01-02 stsp echo -n "Updated to commit " >> $testroot/stdout.expected
108 512f0d0e 2019-01-02 stsp git_show_head $testroot/repo >> $testroot/stdout.expected
109 512f0d0e 2019-01-02 stsp echo >> $testroot/stdout.expected
111 512f0d0e 2019-01-02 stsp (cd $testroot/wt && got update > $testroot/stdout)
113 512f0d0e 2019-01-02 stsp cmp $testroot/stdout.expected $testroot/stdout
114 512f0d0e 2019-01-02 stsp if [ "$?" != "0" ]; then
115 512f0d0e 2019-01-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
116 512f0d0e 2019-01-02 stsp test_done "$testroot" "$?"
120 512f0d0e 2019-01-02 stsp if [ -e $testroot/wt/beta ]; then
121 512f0d0e 2019-01-02 stsp echo "removed file beta still exists on disk" >&2
122 52a3df9b 2019-01-06 stsp test_done "$testroot" "1"
126 52a3df9b 2019-01-06 stsp test_done "$testroot" "0"
129 f5c49f82 2019-01-06 stsp function test_update_deletes_dir {
130 f5c49f82 2019-01-06 stsp local testroot=`test_init update_deletes_dir`
132 f5c49f82 2019-01-06 stsp got checkout $testroot/repo $testroot/wt > /dev/null
133 f5c49f82 2019-01-06 stsp if [ "$?" != "0" ]; then
134 f5c49f82 2019-01-06 stsp test_done "$testroot" "$?"
138 f5c49f82 2019-01-06 stsp (cd $testroot/repo && git_rm $testroot/repo -r epsilon)
139 f5c49f82 2019-01-06 stsp git_commit $testroot/repo -m "deleting a directory"
141 f5c49f82 2019-01-06 stsp echo "D epsilon/zeta" > $testroot/stdout.expected
142 f5c49f82 2019-01-06 stsp echo -n "Updated to commit " >> $testroot/stdout.expected
143 f5c49f82 2019-01-06 stsp git_show_head $testroot/repo >> $testroot/stdout.expected
144 f5c49f82 2019-01-06 stsp echo >> $testroot/stdout.expected
146 f5c49f82 2019-01-06 stsp (cd $testroot/wt && got update > $testroot/stdout)
148 f5c49f82 2019-01-06 stsp cmp $testroot/stdout.expected $testroot/stdout
149 f5c49f82 2019-01-06 stsp if [ "$?" != "0" ]; then
150 f5c49f82 2019-01-06 stsp diff -u $testroot/stdout.expected $testroot/stdout
151 f5c49f82 2019-01-06 stsp test_done "$testroot" "$?"
155 f5c49f82 2019-01-06 stsp if [ -e $testroot/wt/epsilon ]; then
156 f5c49f82 2019-01-06 stsp echo "removed dir epsilon still exists on disk" >&2
157 52a3df9b 2019-01-06 stsp test_done "$testroot" "1"
161 52a3df9b 2019-01-06 stsp test_done "$testroot" "0"
164 5cc266ba 2019-01-06 stsp function test_update_deletes_dir_with_path_prefix {
165 5cc266ba 2019-01-06 stsp local testroot=`test_init update_deletes_dir_with_path_prefix`
166 5cc266ba 2019-01-06 stsp local first_rev=`git_show_head $testroot/repo`
168 5cc266ba 2019-01-06 stsp mkdir $testroot/repo/epsilon/psi
169 5cc266ba 2019-01-06 stsp echo mu > $testroot/repo/epsilon/psi/mu
170 5cc266ba 2019-01-06 stsp (cd $testroot/repo && git add .)
171 5cc266ba 2019-01-06 stsp git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
173 5cc266ba 2019-01-06 stsp # check out the epsilon/ sub-tree
174 5cc266ba 2019-01-06 stsp got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
175 5cc266ba 2019-01-06 stsp if [ "$?" != "0" ]; then
176 5cc266ba 2019-01-06 stsp test_done "$testroot" "$?"
180 5cc266ba 2019-01-06 stsp # update back to first commit and expect psi/mu to be deleted
181 5cc266ba 2019-01-06 stsp echo "D psi/mu" > $testroot/stdout.expected
182 5cc266ba 2019-01-06 stsp echo "Updated to commit $first_rev" >> $testroot/stdout.expected
184 5cc266ba 2019-01-06 stsp (cd $testroot/wt && got update -c $first_rev > $testroot/stdout)
186 5cc266ba 2019-01-06 stsp cmp $testroot/stdout.expected $testroot/stdout
187 5cc266ba 2019-01-06 stsp if [ "$?" != "0" ]; then
188 5cc266ba 2019-01-06 stsp diff -u $testroot/stdout.expected $testroot/stdout
189 5cc266ba 2019-01-06 stsp test_done "$testroot" "$?"
193 5cc266ba 2019-01-06 stsp if [ -e $testroot/wt/psi ]; then
194 5cc266ba 2019-01-06 stsp echo "removed dir psi still exists on disk" >&2
195 5cc266ba 2019-01-06 stsp test_done "$testroot" "1"
199 52a3df9b 2019-01-06 stsp test_done "$testroot" "0"
202 c84d8c75 2019-01-02 stsp run_test test_update_basic
203 3b4d3732 2019-01-02 stsp run_test test_update_adds_file
204 512f0d0e 2019-01-02 stsp run_test test_update_deletes_file
205 f5c49f82 2019-01-06 stsp run_test test_update_deletes_dir
206 5cc266ba 2019-01-06 stsp run_test test_update_deletes_dir_with_path_prefix