3 # Copyright (c) 2020 Tracey Emery <tracey@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.
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
39 if [ "$ret" != "0" ]; then
40 diff -u $testroot/stdout.expected
$testroot/stdout
43 test_done
"$testroot" "$ret"
47 local testroot
=`test_init tree_branch`
49 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
51 if [ "$ret" != "0" ]; then
52 test_done
"$testroot" "$ret"
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
73 if [ "$ret" != "0" ]; then
74 diff -u $testroot/stdout.expected
$testroot/stdout
77 test_done
"$testroot" "$ret"
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
94 if [ "$ret" = "0" ]; then
95 echo "tree command succeeded unexpectedly" >&2
96 test_done
"$testroot" "1"
99 echo "got: open: $objpath: No such file or directory" \
100 > $testroot/stderr.expected
102 cmp -s $testroot/stderr.expected
$testroot/stderr
104 if [ "$ret" != "0" ]; then
105 diff -u $testroot/stderr.expected
$testroot/stderr
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
121 if [ "$ret" = "0" ]; then
122 echo "tree command succeeded unexpectedly" >&2
123 test_done
"$testroot" "1"
126 if [ -n "$GOT_TEST_PACK" ]; then
127 echo "got-read-pack: bad object data" \
128 > $testroot/stderr.expected
130 echo "got-read-tree: bad object data" \
131 > $testroot/stderr.expected
133 echo "got: bad object data" >> $testroot/stderr.expected
135 cmp -s $testroot/stderr.expected
$testroot/stderr
137 if [ "$ret" != "0" ]; then
138 diff -u $testroot/stderr.expected
$testroot/stderr
141 test_done
"$testroot" "$ret"
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