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 blame_basic 80 8
23 local commit_id1=`git_show_head $testroot/repo`
25 got checkout $testroot/repo $testroot/wt > /dev/null
27 if [ $ret -ne 0 ]; then
28 test_done "$testroot" "$ret"
32 echo aaaa >> $testroot/wt/alpha
33 (cd $testroot/wt && got commit -m "a change" > /dev/null)
34 local commit_id2=`git_show_head $testroot/repo`
36 echo bbbb >> $testroot/wt/alpha
37 (cd $testroot/wt && got commit -m "b change" > /dev/null)
38 local commit_id3=`git_show_head $testroot/repo`
40 echo cccc >> $testroot/wt/alpha
41 (cd $testroot/wt && got commit -m "c change" > /dev/null)
42 local commit_id4=`git_show_head $testroot/repo`
43 local author_time=`git_show_author_time $testroot/repo`
44 local ymd=`date -u -r $author_time +"%F"`
46 cat <<EOF >$TOG_TEST_SCRIPT
47 WAIT_FOR_UI wait for blame to finish
51 local commit_id1_short=`trim_obj_id 32 $commit_id1`
52 local commit_id2_short=`trim_obj_id 32 $commit_id2`
53 local commit_id3_short=`trim_obj_id 32 $commit_id3`
54 local commit_id4_short=`trim_obj_id 32 $commit_id4`
56 cat <<EOF >$testroot/view.expected
59 $commit_id1_short alpha
60 $commit_id2_short aaaa
61 $commit_id3_short bbbb
62 $commit_id4_short cccc
67 cd $testroot/wt && tog blame alpha
68 cmp -s $testroot/view.expected $testroot/view
70 if [ $ret -ne 0 ]; then
71 diff -u $testroot/view.expected $testroot/view
72 test_done "$testroot" "$ret"
76 test_done "$testroot" "$ret"
79 test_blame_commit_keywords()
81 test_init blame_commit_keywords 80 10
82 local repo="$testroot/repo"
83 local wt="$testroot/wt"
84 local id=$(git_show_head "$repo")
85 local author_time=$(git_show_author_time "$repo")
86 local ymd=$(date -u -r $author_time +"%F")
90 cat <<-EOF >$TOG_TEST_SCRIPT
91 WAIT_FOR_UI wait for blame to finish
95 # :base requires work tree
96 echo "tog: '-c :base' requires work tree" > "$testroot/stderr.expected"
97 tog blame -r "$repo" -c:base alpha 2> "$testroot/stderr"
99 if [ $ret -eq 0 ]; then
100 echo "blame command succeeded unexpectedly" >&2
101 test_done "$testroot" "1"
105 cmp -s "$testroot/stderr.expected" "$testroot/stderr"
107 if [ $ret -ne 0 ]; then
108 diff -u "$testroot/stderr.expected" "$testroot/stderr"
109 test_done "$testroot" "$ret"
113 # :head keyword in repo
114 cat <<-EOF >$testroot/view.expected
117 $(trim_obj_id 32 $(pop_idx 1 $@)) alpha
127 tog blame -r "$repo" -c:head alpha
129 if [ $ret -ne 0 ]; then
130 echo "blame command failed unexpectedly" >&2
131 test_done "$testroot" "1"
135 cmp -s $testroot/view.expected $testroot/view
137 if [ $ret -ne 0 ]; then
138 diff -u $testroot/view.expected $testroot/view
139 test_done "$testroot" "$ret"
143 got checkout "$repo" "$wt" > /dev/null
145 if [ $ret -ne 0 ]; then
146 echo "got checkout failed unexpectedly"
147 test_done "$testroot" "$ret"
151 # move into the work tree (test is run in a subshell)
155 for i in $(seq 8); do
156 echo "alpha $i" >> alpha
158 got ci -m "commit $i" > /dev/null
160 if [ $ret -ne 0 ]; then
161 echo "commit failed unexpectedly" >&2
162 test_done "$testroot" "$ret"
166 id=$(git_show_head "$repo")
170 author_time=$(git_show_author_time "$repo")
171 ymd=$(date -u -r $author_time +"%F")
173 # :base:- keyword in work tree
174 cat <<-EOF >$testroot/view.expected
175 commit $(pop_idx 8 $@)
177 $(trim_obj_id 32 $(pop_idx 2 $@)) alpha 1
178 $(trim_obj_id 32 $(pop_idx 3 $@)) alpha 2
179 $(trim_obj_id 32 $(pop_idx 4 $@)) alpha 3
180 $(trim_obj_id 32 $(pop_idx 5 $@)) alpha 4
181 $(trim_obj_id 32 $(pop_idx 6 $@)) alpha 5
182 $(trim_obj_id 32 $(pop_idx 7 $@)) alpha 6
183 $(trim_obj_id 32 $(pop_idx 8 $@)) alpha 7
187 tog blame -c:base:- alpha
189 if [ $ret -ne 0 ]; then
190 echo "blame command failed unexpectedly" >&2
191 test_done "$testroot" "1"
195 cmp -s $testroot/view.expected $testroot/view
197 if [ $ret -ne 0 ]; then
198 diff -u $testroot/view.expected $testroot/view
199 test_done "$testroot" "$ret"
203 # :head:-4 keyword in work tree
204 cat <<-EOF >$testroot/view.expected
205 commit $(pop_idx 5 $@)
207 $(trim_obj_id 32 $(pop_idx 2 $@)) alpha 1
208 $(trim_obj_id 32 $(pop_idx 3 $@)) alpha 2
209 $(trim_obj_id 32 $(pop_idx 4 $@)) alpha 3
210 $(trim_obj_id 32 $(pop_idx 5 $@)) alpha 4
217 tog blame -c:head:-4 alpha
219 if [ $ret -ne 0 ]; then
220 echo "blame command failed unexpectedly" >&2
221 test_done "$testroot" "1"
225 cmp -s $testroot/view.expected $testroot/view
227 if [ $ret -ne 0 ]; then
228 diff -u $testroot/view.expected $testroot/view
229 test_done "$testroot" "$ret"
233 # :base:+2 keyword in work tree
234 cat <<-EOF >$testroot/view.expected
235 commit $(pop_idx 5 $@)
237 $(trim_obj_id 32 $(pop_idx 2 $@)) alpha 1
238 $(trim_obj_id 32 $(pop_idx 3 $@)) alpha 2
239 $(trim_obj_id 32 $(pop_idx 4 $@)) alpha 3
240 $(trim_obj_id 32 $(pop_idx 5 $@)) alpha 4
247 got up -c:head:-6 > /dev/null
248 if [ $ret -ne 0 ]; then
249 echo "update command failed unexpectedly" >&2
250 test_done "$testroot" "1"
254 tog blame -c:base:+2 alpha
256 if [ $ret -ne 0 ]; then
257 echo "blame command failed unexpectedly" >&2
258 test_done "$testroot" "1"
262 cmp -s $testroot/view.expected $testroot/view
264 if [ $ret -ne 0 ]; then
265 diff -u $testroot/view.expected $testroot/view
266 test_done "$testroot" "$ret"
270 # master:-99 keyword in work tree
271 cat <<-EOF >$testroot/view.expected
272 commit $(pop_idx 1 $@)
274 $(trim_obj_id 32 $(pop_idx 1 $@)) alpha
284 tog blame -cmaster:-99 alpha
286 if [ $ret -ne 0 ]; then
287 echo "blame command failed unexpectedly" >&2
288 test_done "$testroot" "1"
292 cmp -s $testroot/view.expected $testroot/view
294 if [ $ret -ne 0 ]; then
295 diff -u $testroot/view.expected $testroot/view
296 test_done "$testroot" "$ret"
300 test_done "$testroot" "$ret"
304 run_test test_blame_basic
305 run_test test_blame_commit_keywords