3 # Copyright (c) 2023 Mark Jamsek <mark@jamsek.dev>
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.
21 test_init tree_basic 48 8
23 local head_id=`git_show_head $testroot/repo`
25 cat <<EOF >$TOG_TEST_SCRIPT
29 cat <<EOF >$testroot/view.expected
40 cd $testroot/repo && tog tree
41 cmp -s $testroot/view.expected $testroot/view
43 if [ $ret -ne 0 ]; then
44 diff -u $testroot/view.expected $testroot/view
45 test_done "$testroot" "$ret"
49 test_done "$testroot" "$ret"
52 test_tree_vsplit_blame()
54 test_init tree_vsplit_blame 120 8
56 local head_id=`git_show_head $testroot/repo`
57 local head_id_truncated=`trim_obj_id 8 $head_id`
58 local head_id_short=`trim_obj_id 32 $head_id`
60 cat <<EOF >$TOG_TEST_SCRIPT
62 WAIT_FOR_UI wait for blame to finish
66 cat <<EOF >$testroot/view.expected
67 commit $head_id_truncated|commit $head_id
77 cd $testroot/repo && tog tree
78 cmp -s $testroot/view.expected $testroot/view
80 if [ $ret -ne 0 ]; then
81 diff -u $testroot/view.expected $testroot/view
82 test_done "$testroot" "$ret"
86 test_done "$testroot" "$ret"
89 test_tree_hsplit_blame()
91 test_init tree_hsplit_blame 48 24
93 local head_id=`git_show_head $testroot/repo`
94 local head_id_truncated=`trim_obj_id 8 $head_id`
95 local head_id_short=`trim_obj_id 32 $head_id`
97 cat <<EOF >$TOG_TEST_SCRIPT
100 S toggle horizontal split
101 4- 4x decrease blame split
102 WAIT_FOR_UI wait for blame to finish
106 cat <<EOF >$testroot/view.expected
117 ------------------------------------------------
133 cd $testroot/repo && tog tree
134 cmp -s $testroot/view.expected $testroot/view
136 if [ $ret -ne 0 ]; then
137 diff -u $testroot/view.expected $testroot/view
138 test_done "$testroot" "$ret"
142 test_done "$testroot" "$ret"
147 test_init tree_symlink 48 8
149 (cd $testroot/repo && ln -s alpha symlink)
150 (cd $testroot/repo && git add symlink)
151 git_commit $testroot/repo -m "symlink to alpha"
152 local head_id=`git_show_head $testroot/repo`
154 cat <<EOF >$TOG_TEST_SCRIPT
158 cat <<EOF >$testroot/view.expected
169 cd $testroot/repo && tog tree
170 cmp -s $testroot/view.expected $testroot/view
172 if [ $ret -ne 0 ]; then
173 diff -u $testroot/view.expected $testroot/view
174 test_done "$testroot" "$ret"
178 test_done "$testroot" "$ret"
181 test_tree_commit_keywords()
183 test_init tree_commit_keywords 48 11
184 local repo="$testroot/repo"
185 local wt="$testroot/wt"
186 local id=$(git_show_head "$repo")
190 got checkout "$repo" "$wt" > /dev/null
192 if [ $ret -ne 0 ]; then
193 echo "got checkout failed unexpectedly"
194 test_done "$testroot" "$ret"
198 # move into the work tree (test is run in a subshell)
201 for i in $(seq 8); do
202 if [ $(( i % 2 )) -eq 0 ]; then
203 echo "file${i}" > "file${i}"
204 got add "file${i}" > /dev/null
206 echo "alpha $i" > alpha
209 got ci -m "commit $i" > /dev/null
211 if [ $ret -ne 0 ]; then
212 echo "commit failed unexpectedly" >&2
213 test_done "$testroot" "$ret"
217 id=$(git_show_head "$repo")
222 cat <<-EOF >$TOG_TEST_SCRIPT
226 cat <<-EOF >$testroot/view.expected
227 commit $(pop_idx 8 $@)
241 cmp -s $testroot/view.expected $testroot/view
243 if [ $ret -ne 0 ]; then
244 diff -u $testroot/view.expected $testroot/view
245 test_done "$testroot" "$ret"
249 cat <<-EOF >$testroot/view.expected
250 commit $(pop_idx 6 $@)
264 cmp -s $testroot/view.expected $testroot/view
266 if [ $ret -ne 0 ]; then
267 diff -u $testroot/view.expected $testroot/view
268 test_done "$testroot" "$ret"
272 cat <<-EOF >$testroot/view.expected
273 commit $(pop_idx 9 $@)
286 got up -c:head:-99 > /dev/null
288 cmp -s $testroot/view.expected $testroot/view
290 if [ $ret -ne 0 ]; then
291 diff -u $testroot/view.expected $testroot/view
292 test_done "$testroot" "$ret"
296 cat <<-EOF >$testroot/view.expected
297 commit $(pop_idx 4 $@)
311 cmp -s $testroot/view.expected $testroot/view
313 if [ $ret -ne 0 ]; then
314 diff -u $testroot/view.expected $testroot/view
315 test_done "$testroot" "$ret"
319 cat <<-EOF >$testroot/view.expected
320 commit $(pop_idx 1 $@)
333 tog tree -r "$repo" -cmaster:-99
334 cmp -s $testroot/view.expected $testroot/view
336 if [ $ret -ne 0 ]; then
337 diff -u $testroot/view.expected $testroot/view
338 test_done "$testroot" "$ret"
341 test_done "$testroot" "$ret"
345 run_test test_tree_basic
346 run_test test_tree_vsplit_blame
347 run_test test_tree_hsplit_blame
348 run_test test_tree_symlink
349 run_test test_tree_commit_keywords