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.
19 test_diff_contiguous_commits()
21 test_init diff_contiguous_commits
23 local commit_id1=`git_show_head $testroot/repo`
24 local alpha_id_old=`get_blob_id $testroot/repo "" alpha`
26 echo "modified alpha" > $testroot/repo/alpha
27 git_commit $testroot/repo -m "changed alpha"
28 local author_time=`git_show_author_time $testroot/repo`
29 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
30 local head_id=`git_show_head $testroot/repo`
31 local head_id_truncated=`trim_obj_id 13 $head_id`
32 local alpha_id=`get_blob_id $testroot/repo "" alpha`
34 cat <<EOF >$TOG_TEST_SCRIPT
38 cat <<EOF >$testroot/view.expected
39 [1/20] diff $commit_id1 $head_id_truncated
40 commit $head_id (master)
41 from: Flan Hacker <flan_hacker@openbsd.org>
48 1 file changed, 1 insertion(+), 1 deletion(-)
65 cd $testroot/repo && tog diff $commit_id1 $head_id
66 cmp -s $testroot/view.expected $testroot/view
68 if [ $ret -ne 0 ]; then
69 diff -u $testroot/view.expected $testroot/view
70 test_done "$testroot" "$ret"
74 test_done "$testroot" "$ret"
77 test_diff_arbitrary_commits()
79 test_init diff_arbitrary_commits 80 18
81 local commit_id1=`git_show_head $testroot/repo`
82 local alpha_id_old=`get_blob_id $testroot/repo "" alpha`
84 echo "modified alpha" > $testroot/repo/alpha
85 git_commit $testroot/repo -m "changed alpha"
86 local commit_id2=`git_show_head $testroot/repo`
88 echo "modified alpha again" > $testroot/repo/alpha
89 echo "new file" > $testroot/repo/new
90 (cd $testroot/repo && git add new)
91 git_commit $testroot/repo -m "new file"
92 local head_id=`git_show_head $testroot/repo`
93 local head_id_truncated=`trim_obj_id 13 $head_id`
94 local alpha_id=`get_blob_id $testroot/repo "" alpha`
95 local new_id=`get_blob_id $testroot/repo "" new`
97 cat <<EOF >$TOG_TEST_SCRIPT
101 cat <<EOF >$testroot/view.expected
102 [1/16] diff $commit_id1 $head_id_truncated
111 +modified alpha again
113 blob + $new_id (mode 644)
122 cd $testroot/repo && tog diff $commit_id1 $head_id
123 cmp -s $testroot/view.expected $testroot/view
125 if [ $ret -ne 0 ]; then
126 diff -u $testroot/view.expected $testroot/view
127 test_done "$testroot" "$ret"
131 test_done "$testroot" "$ret"
134 test_diff_J_keymap_on_last_loaded_commit()
136 test_init diff_J_keymap_on_last_loaded_commit 94 24
142 while [ "$i" -lt 32 ]; do
145 if [ $i -eq 6 ]; then
146 local id6=$(git_show_head .)
147 local blobid6=$(get_blob_id . "" alpha)
148 elif [ $i -eq 7 ]; then
149 local id7=$(git_show_head .)
150 local blobid7=$(get_blob_id . "" alpha)
151 local author_time=$(git_show_author_time .)
156 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
158 cat <<EOF >$TOG_TEST_SCRIPT
159 KEY_ENTER open diff view of selected commit
160 S toggle horizontal split
161 TAB tab back to log view
162 23j move to last loaded commit
163 KEY_ENTER select last loaded commit
165 J move down to next commit in the log
169 cat <<EOF >$testroot/view.expected
170 [1/20] diff $id6 $id7
172 from: Flan Hacker <flan_hacker@openbsd.org>
179 1 file changed, 1 insertion(+), 1 deletion(-)
197 cmp -s $testroot/view.expected $testroot/view
199 if [ $ret -ne 0 ]; then
200 diff -u $testroot/view.expected $testroot/view
201 test_done "$testroot" "$ret"
205 test_done "$testroot" "$ret"
208 test_diff_commit_keywords()
210 test_init diff_commit_keywords 120 24
211 local repo="$testroot/repo"
212 local wt="$testroot/wt"
213 local id=$(git_show_head "$repo")
214 local author_time=$(git_show_author_time "$repo")
216 local alpha_ids="$(get_blob_id "$repo" "" alpha)"
218 set -- "$author_time"
220 got checkout "$repo" "$wt" > /dev/null
222 if [ $ret -ne 0 ]; then
223 echo "got checkout failed unexpectedly"
224 test_done "$testroot" "$ret"
228 # move into the work tree (test is run in a subshell)
231 for i in $(seq 8); do
232 echo "alpha $i" > alpha
234 got ci -m "commit $i" > /dev/null
236 if [ $ret -ne 0 ]; then
237 echo "commit failed unexpectedly" >&2
238 test_done "$testroot" "$ret"
242 id=$(git_show_head "$repo")
244 alpha_ids="$alpha_ids $(get_blob_id "$repo" "" alpha)"
245 set -- "$@" $(git_show_author_time "$repo")
248 cat <<-EOF >$TOG_TEST_SCRIPT
252 # diff consecutive commits with keywords
253 local lhs_id=$(pop_idx 1 $ids)
254 local rhs_id=$(pop_idx 2 $ids)
255 local date=$(date -u -r $(pop_idx 2 $@) +"%a %b %e %X %Y UTC")
257 cat <<-EOF >$testroot/view.expected
258 [1/20] diff $lhs_id $rhs_id
260 from: Flan Hacker <flan_hacker@openbsd.org>
267 1 file changed, 1 insertion(+), 1 deletion(-)
271 blob - $(pop_idx 1 $alpha_ids)
272 blob + $(pop_idx 2 $alpha_ids)
284 tog diff :base:-99 :head:-7
285 cmp -s "$testroot/view.expected" "$testroot/view"
287 if [ $ret -ne 0 ]; then
288 diff -u "$testroot/view.expected" "$testroot/view"
289 test_done "$testroot" "$ret"
293 # diff arbitrary commits with keywords
294 lhs_id=$(pop_idx 5 $ids)
295 rhs_id=$(pop_idx 8 $ids)
297 cat <<-EOF >$testroot/view.expected
298 [1/10] diff $lhs_id $rhs_id
301 blob - $(pop_idx 5 $alpha_ids)
302 blob + $(pop_idx 8 $alpha_ids)
324 tog diff master:-4 :head:-
325 cmp -s "$testroot/view.expected" "$testroot/view"
327 if [ $ret -ne 0 ]; then
328 diff -u "$testroot/view.expected" "$testroot/view"
329 test_done "$testroot" "$ret"
333 # diff consecutive commits using keywords with -r repository
334 lhs_id=$(pop_idx 8 $ids)
335 rhs_id=$(pop_idx 9 $ids)
336 date=$(date -u -r $(pop_idx 9 $@) +"%a %b %e %X %Y UTC")
338 cat <<-EOF >$testroot/view.expected
339 [1/20] diff $lhs_id refs/heads/master
340 commit $rhs_id (master)
341 from: Flan Hacker <flan_hacker@openbsd.org>
348 1 file changed, 1 insertion(+), 1 deletion(-)
352 blob - $(pop_idx 8 $alpha_ids)
353 blob + $(pop_idx 9 $alpha_ids)
365 tog diff -r "$repo" :head:- master
366 cmp -s "$testroot/view.expected" "$testroot/view"
368 if [ $ret -ne 0 ]; then
369 diff -u "$testroot/view.expected" "$testroot/view"
370 test_done "$testroot" "$ret"
374 test_done "$testroot" "$ret"
378 run_test test_diff_contiguous_commits
379 run_test test_diff_arbitrary_commits
380 run_test test_diff_J_keymap_on_last_loaded_commit
381 run_test test_diff_commit_keywords