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")
217 set -A alpha_ids $(get_blob_id "$repo" "" alpha)
218 set -A dates "$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")
245 set -- "$alpha_ids" "$(get_blob_id "$repo" "" alpha)"
247 set -- "$dates" $(git_show_author_time "$repo")
251 cat <<-EOF >$TOG_TEST_SCRIPT
255 # diff consecutive commits with keywords
256 local lhs_id=$(pop_id 1 $ids)
257 local rhs_id=$(pop_id 2 $ids)
258 local date=$(date -u -r $(pop_id 2 $dates) +"%a %b %e %X %Y UTC")
260 cat <<-EOF >$testroot/view.expected
261 [1/20] diff $lhs_id $rhs_id
263 from: Flan Hacker <flan_hacker@openbsd.org>
270 1 file changed, 1 insertion(+), 1 deletion(-)
274 blob - $(pop_id 1 $alpha_ids)
275 blob + $(pop_id 2 $alpha_ids)
287 tog diff :base:-99 :head:-7
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 # diff arbitrary commits with keywords
297 lhs_id=$(pop_id 5 $ids)
298 rhs_id=$(pop_id 8 $ids)
300 cat <<-EOF >$testroot/view.expected
301 [1/10] diff $lhs_id $rhs_id
304 blob - $(pop_id 5 $alpha_ids)
305 blob + $(pop_id 8 $alpha_ids)
327 tog diff master:-4 :head:-
328 cmp -s "$testroot/view.expected" "$testroot/view"
330 if [ $ret -ne 0 ]; then
331 diff -u "$testroot/view.expected" "$testroot/view"
332 test_done "$testroot" "$ret"
336 # diff consecutive commits using keywords with -r repository
337 lhs_id=$(pop_id 8 $ids)
338 rhs_id=$(pop_id 9 $ids)
339 date=$(date -u -r $(pop_id 9 $dates) +"%a %b %e %X %Y UTC")
341 cat <<-EOF >$testroot/view.expected
342 [1/20] diff $lhs_id refs/heads/master
343 commit $rhs_id (master)
344 from: Flan Hacker <flan_hacker@openbsd.org>
351 1 file changed, 1 insertion(+), 1 deletion(-)
355 blob - $(pop_id 8 $alpha_ids)
356 blob + $(pop_id 9 $alpha_ids)
368 tog diff -r "$repo" :head:- master
369 cmp -s "$testroot/view.expected" "$testroot/view"
371 if [ $ret -ne 0 ]; then
372 diff -u "$testroot/view.expected" "$testroot/view"
373 test_done "$testroot" "$ret"
377 test_done "$testroot" "$ret"
381 run_test test_diff_contiguous_commits
382 run_test test_diff_arbitrary_commits
383 run_test test_diff_J_keymap_on_last_loaded_commit
384 run_test test_diff_commit_keywords