Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2020 Tracey Emery <tracey@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_tree_basic() {
20 local testroot=`test_init tree_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 echo "new file" > $testroot/wt/foo
26 (cd $testroot/wt && got add foo > /dev/null)
27 (cd $testroot/wt && got commit -m "add foo" foo > /dev/null)
29 echo 'alpha' > $testroot/stdout.expected
30 echo 'beta' >> $testroot/stdout.expected
31 echo 'epsilon/' >> $testroot/stdout.expected
32 echo 'foo' >> $testroot/stdout.expected
33 echo 'gamma/' >> $testroot/stdout.expected
35 (cd $testroot/wt && got tree > $testroot/stdout)
37 cmp -s $testroot/stdout.expected $testroot/stdout
38 ret=$?
39 if [ $ret -ne 0 ]; then
40 diff -u $testroot/stdout.expected $testroot/stdout
41 fi
43 test_done "$testroot" "$ret"
44 }
46 test_tree_branch() {
47 local testroot=`test_init tree_branch`
49 got checkout $testroot/repo $testroot/wt > /dev/null
50 ret=$?
51 if [ $ret -ne 0 ]; then
52 test_done "$testroot" "$ret"
53 return 1
54 fi
56 (cd $testroot/wt && got br foo > $testroot/stdout)
58 echo "new file" > $testroot/wt/foo
60 (cd $testroot/wt && got add foo > /dev/null)
61 (cd $testroot/wt && got commit -m "add foo" foo > /dev/null)
63 echo 'alpha' > $testroot/stdout.expected
64 echo 'beta' >> $testroot/stdout.expected
65 echo 'epsilon/' >> $testroot/stdout.expected
66 echo 'foo' >> $testroot/stdout.expected
67 echo 'gamma/' >> $testroot/stdout.expected
69 (cd $testroot/wt && got tree > $testroot/stdout)
71 cmp -s $testroot/stdout.expected $testroot/stdout
72 ret=$?
73 if [ $ret -ne 0 ]; then
74 diff -u $testroot/stdout.expected $testroot/stdout
75 fi
77 test_done "$testroot" "$ret"
78 }
80 test_tree_submodule() {
81 local testroot=`test_init tree_submodule`
83 make_single_file_repo $testroot/repo2 foo
84 (cd $testroot/repo && git submodule -q add ../repo2)
85 (cd $testroot/repo && git commit -q -m 'adding submodule')
87 local submodule_id=$(got tree -r $testroot/repo -i | \
88 grep 'repo2\$$' | cut -d ' ' -f1)
89 local objpath=`get_loose_object_path $testroot/repo $submodule_id`
91 # Currently fails in open(2)
92 got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
93 ret=$?
94 if [ $ret -eq 0 ]; then
95 echo "tree command succeeded unexpectedly" >&2
96 test_done "$testroot" "1"
97 return 1
98 fi
99 echo "got: open: $objpath: No such file or directory" \
100 > $testroot/stderr.expected
102 cmp -s $testroot/stderr.expected $testroot/stderr
103 ret=$?
104 if [ $ret -ne 0 ]; then
105 diff -u $testroot/stderr.expected $testroot/stderr
106 return 1
107 fi
108 test_done "$testroot" "$ret"
111 test_tree_submodule_of_same_repo() {
112 local testroot=`test_init tree_submodule_of_same_repo`
114 (cd $testroot && git clone -q repo repo2 >/dev/null)
115 (cd $testroot/repo && git submodule -q add ../repo2)
116 (cd $testroot/repo && git commit -q -m 'adding submodule')
118 # Currently fails with "bad object data"
119 got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
120 ret=$?
121 if [ $ret -eq 0 ]; then
122 echo "tree command succeeded unexpectedly" >&2
123 test_done "$testroot" "1"
124 return 1
125 fi
126 if [ -n "$GOT_TEST_PACK" ]; then
127 echo "got-read-pack: bad object data" \
128 > $testroot/stderr.expected
129 else
130 echo "got-read-tree: bad object data" \
131 > $testroot/stderr.expected
132 fi
133 echo "got: bad object data" >> $testroot/stderr.expected
135 cmp -s $testroot/stderr.expected $testroot/stderr
136 ret=$?
137 if [ $ret -ne 0 ]; then
138 diff -u $testroot/stderr.expected $testroot/stderr
139 return 1
140 fi
141 test_done "$testroot" "$ret"
144 test_parseargs "$@"
145 run_test test_tree_basic
146 run_test test_tree_branch
147 run_test test_tree_submodule
148 run_test test_tree_submodule_of_same_repo