Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2023 Mark Jamsek <mark@jamsek.dev>
4 #
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.
8 #
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.
17 . ./common.sh
19 test_diff_contiguous_commits()
20 {
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
35 SCREENDUMP
36 EOF
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>
42 date: $date
44 changed alpha
46 M alpha | 1+ 1-
48 1 file changed, 1 insertion(+), 1 deletion(-)
50 commit - $commit_id1
51 commit + $head_id
52 blob - $alpha_id_old
53 blob + $alpha_id
54 --- alpha
55 +++ alpha
56 @@ -1 +1 @@
57 -alpha
58 +modified alpha
62 (END)
63 EOF
65 cd $testroot/repo && tog diff $commit_id1 $head_id
66 cmp -s $testroot/view.expected $testroot/view
67 ret=$?
68 if [ $ret -ne 0 ]; then
69 diff -u $testroot/view.expected $testroot/view
70 test_done "$testroot" "$ret"
71 return 1
72 fi
74 test_done "$testroot" "$ret"
75 }
77 test_diff_arbitrary_commits()
78 {
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
98 SCREENDUMP
99 EOF
101 cat <<EOF >$testroot/view.expected
102 [1/16] diff $commit_id1 $head_id_truncated
103 commit - $commit_id1
104 commit + $head_id
105 blob - $alpha_id_old
106 blob + $alpha_id
107 --- alpha
108 +++ alpha
109 @@ -1 +1 @@
110 -alpha
111 +modified alpha again
112 blob - /dev/null
113 blob + $new_id (mode 644)
114 --- /dev/null
115 +++ new
116 @@ -0,0 +1 @@
117 +new file
119 (END)
120 EOF
122 cd $testroot/repo && tog diff $commit_id1 $head_id
123 cmp -s $testroot/view.expected $testroot/view
124 ret=$?
125 if [ $ret -ne 0 ]; then
126 diff -u $testroot/view.expected $testroot/view
127 test_done "$testroot" "$ret"
128 return 1
129 fi
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
138 local i=0
140 cd $testroot/repo
142 while [ "$i" -lt 32 ]; do
143 echo $i > alpha
144 git commit -aqm $i
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 .)
152 fi
153 i=$(( i + 1 ))
154 done
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
164 F toggle fullscreen
165 J move down to next commit in the log
166 SCREENDUMP
167 EOF
169 cat <<EOF >$testroot/view.expected
170 [1/20] diff $id6 $id7
171 commit $id7
172 from: Flan Hacker <flan_hacker@openbsd.org>
173 date: $date
177 M alpha | 1+ 1-
179 1 file changed, 1 insertion(+), 1 deletion(-)
181 commit - $id6
182 commit + $id7
183 blob - $blobid6
184 blob + $blobid7
185 --- alpha
186 +++ alpha
187 @@ -1 +1 @@
188 -6
189 +7
193 (END)
194 EOF
196 tog log
197 cmp -s $testroot/view.expected $testroot/view
198 ret=$?
199 if [ $ret -ne 0 ]; then
200 diff -u $testroot/view.expected $testroot/view
201 test_done "$testroot" "$ret"
202 return 1
203 fi
205 test_done "$testroot" "$ret"
208 test_parseargs "$@"
209 run_test test_diff_contiguous_commits
210 run_test test_diff_arbitrary_commits
211 run_test test_diff_J_keymap_on_last_loaded_commit