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 -c protocol.file.allow=always \
85 submodule -q add ../repo2)
86 (cd $testroot/repo && git commit -q -m 'adding submodule')
88 local submodule_id=$(got tree -r $testroot/repo -i | \
89 grep 'repo2\$$' | cut -d ' ' -f1)
90 local objpath=`get_loose_object_path $testroot/repo $submodule_id`
92 # Currently fails in open(2)
93 got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
94 ret=$?
95 if [ $ret -eq 0 ]; then
96 echo "tree command succeeded unexpectedly" >&2
97 test_done "$testroot" "1"
98 return 1
99 fi
100 echo "got: open: $objpath: No such file or directory" \
101 > $testroot/stderr.expected
103 cmp -s $testroot/stderr.expected $testroot/stderr
104 ret=$?
105 if [ $ret -ne 0 ]; then
106 diff -u $testroot/stderr.expected $testroot/stderr
107 return 1
108 fi
109 test_done "$testroot" "$ret"
112 test_tree_submodule_of_same_repo() {
113 local testroot=`test_init tree_submodule_of_same_repo`
115 (cd $testroot && git clone -q repo repo2 >/dev/null)
116 (cd $testroot/repo && git -c protocol.file.allow=always \
117 submodule -q add ../repo2)
118 (cd $testroot/repo && git commit -q -m 'adding submodule')
120 # Currently fails with "bad object data"
121 got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
122 ret=$?
123 if [ $ret -eq 0 ]; then
124 echo "tree command succeeded unexpectedly" >&2
125 test_done "$testroot" "1"
126 return 1
127 fi
128 if [ -n "$GOT_TEST_PACK" ]; then
129 echo "got-read-pack: bad object data" \
130 > $testroot/stderr.expected
131 else
132 echo "got-read-tree: bad object data" \
133 > $testroot/stderr.expected
134 fi
135 echo "got: bad object data" >> $testroot/stderr.expected
137 cmp -s $testroot/stderr.expected $testroot/stderr
138 ret=$?
139 if [ $ret -ne 0 ]; then
140 diff -u $testroot/stderr.expected $testroot/stderr
141 return 1
142 fi
143 test_done "$testroot" "$ret"
146 test_parseargs "$@"
147 run_test test_tree_basic
148 run_test test_tree_branch
149 run_test test_tree_submodule
150 run_test test_tree_submodule_of_same_repo