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 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" "$?"
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" "$?"
45 echo "modified alpha" > $testroot/content.expected
46 echo "beta" >> $testroot/content.expected
47 echo "zeta" >> $testroot/content.expected
48 echo "delta" >> $testroot/content.expected
49 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
50 $testroot/wt/gamma/delta > $testroot/content
52 cmp $testroot/content.expected $testroot/content
54 if [ "$ret" != "0" ]; then
55 diff -u $testroot/content.expected $testroot/content
57 test_done "$testroot" "$ret"
60 function test_update_adds_file {
61 local testroot=`test_init update_adds_file`
63 got checkout $testroot/repo $testroot/wt > /dev/null
64 if [ "$?" != "0" ]; then
65 test_done "$testroot" "$?"
69 echo "new" > $testroot/repo/gamma/new
70 (cd $testroot/repo && git add .)
71 git_commit $testroot/repo -m "adding a new file"
73 echo "A gamma/new" > $testroot/stdout.expected
74 echo -n "Updated to commit " >> $testroot/stdout.expected
75 git_show_head $testroot/repo >> $testroot/stdout.expected
76 echo >> $testroot/stdout.expected
78 (cd $testroot/wt && got update > $testroot/stdout)
80 cmp $testroot/stdout.expected $testroot/stdout
81 if [ "$?" != "0" ]; then
82 diff -u $testroot/stdout.expected $testroot/stdout
83 test_done "$testroot" "$?"
87 echo "alpha" >> $testroot/content.expected
88 echo "beta" >> $testroot/content.expected
89 echo "zeta" >> $testroot/content.expected
90 echo "delta" >> $testroot/content.expected
91 echo "new" >> $testroot/content.expected
92 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
93 $testroot/wt/gamma/delta $testroot/wt/gamma/new > $testroot/content
95 cmp $testroot/content.expected $testroot/content
97 if [ "$ret" != "0" ]; then
98 diff -u $testroot/content.expected $testroot/content
100 test_done "$testroot" "$ret"
103 function test_update_deletes_file {
104 local testroot=`test_init update_deletes_file`
106 got checkout $testroot/repo $testroot/wt > /dev/null
107 if [ "$?" != "0" ]; then
108 test_done "$testroot" "$?"
112 (cd $testroot/repo && git_rm $testroot/repo beta)
113 git_commit $testroot/repo -m "deleting a file"
115 echo "D beta" > $testroot/stdout.expected
116 echo -n "Updated to commit " >> $testroot/stdout.expected
117 git_show_head $testroot/repo >> $testroot/stdout.expected
118 echo >> $testroot/stdout.expected
120 (cd $testroot/wt && got update > $testroot/stdout)
122 cmp $testroot/stdout.expected $testroot/stdout
123 if [ "$?" != "0" ]; then
124 diff -u $testroot/stdout.expected $testroot/stdout
125 test_done "$testroot" "$?"
129 if [ -e $testroot/wt/beta ]; then
130 echo "removed file beta still exists on disk" >&2
134 echo "alpha" >> $testroot/content.expected
135 echo "zeta" >> $testroot/content.expected
136 echo "delta" >> $testroot/content.expected
137 cat $testroot/wt/alpha $testroot/wt/epsilon/zeta \
138 $testroot/wt/gamma/delta > $testroot/content
140 cmp $testroot/content.expected $testroot/content
142 if [ "$ret" != "0" ]; then
143 diff -u $testroot/content.expected $testroot/content
145 test_done "$testroot" "$ret"
148 run_test test_update_basic
149 run_test test_update_adds_file
150 run_test test_update_deletes_file