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 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
53 if [ "$?" != "0" ]; then
54 diff -u $testroot/content.expected $testroot/content
55 fi
56 test_done "$testroot" "$?"
57 }
59 function test_update_adds_file {
60 local testroot=`test_init update_adds_file`
62 got checkout $testroot/repo $testroot/wt > /dev/null
63 if [ "$?" != "0" ]; then
64 test_done "$testroot" "$?"
65 return 1
66 fi
68 echo "new" > $testroot/repo/gamma/new
69 (cd $testroot/repo && git add .)
70 git_commit $testroot/repo -m "adding a new file"
72 echo "A gamma/new" > $testroot/stdout.expected
73 echo -n "Updated to commit " >> $testroot/stdout.expected
74 git_show_head $testroot/repo >> $testroot/stdout.expected
75 echo >> $testroot/stdout.expected
77 (cd $testroot/wt && got update > $testroot/stdout)
79 cmp $testroot/stdout.expected $testroot/stdout
80 if [ "$?" != "0" ]; then
81 diff -u $testroot/stdout.expected $testroot/stdout
82 test_done "$testroot" "$?"
83 return 1
84 fi
86 echo "alpha" >> $testroot/content.expected
87 echo "beta" >> $testroot/content.expected
88 echo "zeta" >> $testroot/content.expected
89 echo "delta" >> $testroot/content.expected
90 echo "new" >> $testroot/content.expected
91 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
92 $testroot/wt/gamma/delta $testroot/wt/gamma/new > $testroot/content
94 cmp $testroot/content.expected $testroot/content
95 if [ "$?" != "0" ]; then
96 diff -u $testroot/content.expected $testroot/content
97 fi
98 test_done "$testroot" "$?"
99 }
101 function test_update_deletes_file {
102 local testroot=`test_init update_deletes_file`
104 got checkout $testroot/repo $testroot/wt > /dev/null
105 if [ "$?" != "0" ]; then
106 test_done "$testroot" "$?"
107 return 1
108 fi
110 (cd $testroot/repo && git_rm $testroot/repo beta)
111 git_commit $testroot/repo -m "deleting a file"
113 echo "D beta" > $testroot/stdout.expected
114 echo -n "Updated to commit " >> $testroot/stdout.expected
115 git_show_head $testroot/repo >> $testroot/stdout.expected
116 echo >> $testroot/stdout.expected
118 (cd $testroot/wt && got update > $testroot/stdout)
120 cmp $testroot/stdout.expected $testroot/stdout
121 if [ "$?" != "0" ]; then
122 diff -u $testroot/stdout.expected $testroot/stdout
123 test_done "$testroot" "$?"
124 return 1
125 fi
127 if [ -e $testroot/wt/beta ]; then
128 echo "removed file beta still exists on disk" >&2
129 return 1
130 fi
132 echo "alpha" >> $testroot/content.expected
133 echo "zeta" >> $testroot/content.expected
134 echo "delta" >> $testroot/content.expected
135 cat $testroot/wt/alpha $testroot/wt/epsilon/zeta \
136 $testroot/wt/gamma/delta > $testroot/content
138 cmp $testroot/content.expected $testroot/content
139 if [ "$?" != "0" ]; then
140 diff -u $testroot/content.expected $testroot/content
141 fi
142 test_done "$testroot" "$?"
145 run_test test_update_basic
146 run_test test_update_adds_file
147 run_test test_update_deletes_file