3 de7a51b7 2023-04-15 mark # Copyright (c) 2023 Mark Jamsek <mark@jamsek.dev>
5 de7a51b7 2023-04-15 mark # Permission to use, copy, modify, and distribute this software for any
6 de7a51b7 2023-04-15 mark # purpose with or without fee is hereby granted, provided that the above
7 de7a51b7 2023-04-15 mark # copyright notice and this permission notice appear in all copies.
9 de7a51b7 2023-04-15 mark # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 de7a51b7 2023-04-15 mark # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 de7a51b7 2023-04-15 mark # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 de7a51b7 2023-04-15 mark # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 de7a51b7 2023-04-15 mark # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 de7a51b7 2023-04-15 mark # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 de7a51b7 2023-04-15 mark # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 de7a51b7 2023-04-15 mark . ./common.sh
19 de7a51b7 2023-04-15 mark test_diff_contiguous_commits()
21 de7a51b7 2023-04-15 mark test_init diff_contiguous_commits
23 de7a51b7 2023-04-15 mark local commit_id1=`git_show_head $testroot/repo`
24 de7a51b7 2023-04-15 mark local alpha_id_old=`get_blob_id $testroot/repo "" alpha`
26 de7a51b7 2023-04-15 mark echo "modified alpha" > $testroot/repo/alpha
27 de7a51b7 2023-04-15 mark git_commit $testroot/repo -m "changed alpha"
28 de7a51b7 2023-04-15 mark local author_time=`git_show_author_time $testroot/repo`
29 de7a51b7 2023-04-15 mark local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
30 de7a51b7 2023-04-15 mark local head_id=`git_show_head $testroot/repo`
31 de7a51b7 2023-04-15 mark local head_id_truncated=`trim_obj_id 13 $head_id`
32 de7a51b7 2023-04-15 mark local alpha_id=`get_blob_id $testroot/repo "" alpha`
34 5bde4759 2023-04-15 mark cat <<EOF >$TOG_TEST_SCRIPT
38 de7a51b7 2023-04-15 mark cat <<EOF >$testroot/view.expected
39 de7a51b7 2023-04-15 mark [1/20] diff $commit_id1 $head_id_truncated
40 de7a51b7 2023-04-15 mark commit $head_id (master)
41 de7a51b7 2023-04-15 mark from: Flan Hacker <flan_hacker@openbsd.org>
44 de7a51b7 2023-04-15 mark changed alpha
46 de7a51b7 2023-04-15 mark M alpha | 1+ 1-
48 de7a51b7 2023-04-15 mark 1 file changed, 1 insertion(+), 1 deletion(-)
50 de7a51b7 2023-04-15 mark commit - $commit_id1
51 de7a51b7 2023-04-15 mark commit + $head_id
52 de7a51b7 2023-04-15 mark blob - $alpha_id_old
53 de7a51b7 2023-04-15 mark blob + $alpha_id
58 de7a51b7 2023-04-15 mark +modified alpha
65 de7a51b7 2023-04-15 mark cd $testroot/repo && tog diff $commit_id1 $head_id
66 de7a51b7 2023-04-15 mark cmp -s $testroot/view.expected $testroot/view
68 de7a51b7 2023-04-15 mark if [ $ret -ne 0 ]; then
69 de7a51b7 2023-04-15 mark diff -u $testroot/view.expected $testroot/view
70 de7a51b7 2023-04-15 mark test_done "$testroot" "$ret"
74 de7a51b7 2023-04-15 mark test_done "$testroot" "$ret"
77 de7a51b7 2023-04-15 mark test_diff_arbitrary_commits()
79 de7a51b7 2023-04-15 mark test_init diff_arbitrary_commits 80 18
81 de7a51b7 2023-04-15 mark local commit_id1=`git_show_head $testroot/repo`
82 de7a51b7 2023-04-15 mark local alpha_id_old=`get_blob_id $testroot/repo "" alpha`
84 de7a51b7 2023-04-15 mark echo "modified alpha" > $testroot/repo/alpha
85 de7a51b7 2023-04-15 mark git_commit $testroot/repo -m "changed alpha"
86 de7a51b7 2023-04-15 mark local commit_id2=`git_show_head $testroot/repo`
88 de7a51b7 2023-04-15 mark echo "modified alpha again" > $testroot/repo/alpha
89 de7a51b7 2023-04-15 mark echo "new file" > $testroot/repo/new
90 de7a51b7 2023-04-15 mark (cd $testroot/repo && git add new)
91 de7a51b7 2023-04-15 mark git_commit $testroot/repo -m "new file"
92 de7a51b7 2023-04-15 mark local head_id=`git_show_head $testroot/repo`
93 de7a51b7 2023-04-15 mark local head_id_truncated=`trim_obj_id 13 $head_id`
94 de7a51b7 2023-04-15 mark local alpha_id=`get_blob_id $testroot/repo "" alpha`
95 de7a51b7 2023-04-15 mark local new_id=`get_blob_id $testroot/repo "" new`
97 5bde4759 2023-04-15 mark cat <<EOF >$TOG_TEST_SCRIPT
101 de7a51b7 2023-04-15 mark cat <<EOF >$testroot/view.expected
102 de7a51b7 2023-04-15 mark [1/16] diff $commit_id1 $head_id_truncated
103 de7a51b7 2023-04-15 mark commit - $commit_id1
104 de7a51b7 2023-04-15 mark commit + $head_id
105 de7a51b7 2023-04-15 mark blob - $alpha_id_old
106 de7a51b7 2023-04-15 mark blob + $alpha_id
109 de7a51b7 2023-04-15 mark @@ -1 +1 @@
111 de7a51b7 2023-04-15 mark +modified alpha again
112 de7a51b7 2023-04-15 mark blob - /dev/null
113 de7a51b7 2023-04-15 mark blob + $new_id (mode 644)
114 de7a51b7 2023-04-15 mark --- /dev/null
116 de7a51b7 2023-04-15 mark @@ -0,0 +1 @@
122 de7a51b7 2023-04-15 mark cd $testroot/repo && tog diff $commit_id1 $head_id
123 de7a51b7 2023-04-15 mark cmp -s $testroot/view.expected $testroot/view
125 de7a51b7 2023-04-15 mark if [ $ret -ne 0 ]; then
126 de7a51b7 2023-04-15 mark diff -u $testroot/view.expected $testroot/view
127 de7a51b7 2023-04-15 mark test_done "$testroot" "$ret"
131 de7a51b7 2023-04-15 mark test_done "$testroot" "$ret"
134 c671dc65 2023-04-24 mark test_diff_J_keymap_on_last_loaded_commit()
136 c671dc65 2023-04-24 mark test_init diff_J_keymap_on_last_loaded_commit 94 24
140 c671dc65 2023-04-24 mark cd $testroot/repo
142 c671dc65 2023-04-24 mark while [ "$i" -lt 32 ]; do
143 c671dc65 2023-04-24 mark echo $i > alpha
144 c671dc65 2023-04-24 mark git commit -aqm $i
145 c671dc65 2023-04-24 mark if [ $i -eq 6 ]; then
146 c671dc65 2023-04-24 mark local id6=$(git_show_head .)
147 c671dc65 2023-04-24 mark local blobid6=$(get_blob_id . "" alpha)
148 c671dc65 2023-04-24 mark elif [ $i -eq 7 ]; then
149 c671dc65 2023-04-24 mark local id7=$(git_show_head .)
150 c671dc65 2023-04-24 mark local blobid7=$(get_blob_id . "" alpha)
151 c671dc65 2023-04-24 mark local author_time=$(git_show_author_time .)
153 c671dc65 2023-04-24 mark i=$(( i + 1 ))
156 c671dc65 2023-04-24 mark local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
158 c671dc65 2023-04-24 mark cat <<EOF >$TOG_TEST_SCRIPT
159 c671dc65 2023-04-24 mark KEY_ENTER open diff view of selected commit
160 c671dc65 2023-04-24 mark S toggle horizontal split
161 c671dc65 2023-04-24 mark TAB tab back to log view
162 c671dc65 2023-04-24 mark 23j move to last loaded commit
163 c671dc65 2023-04-24 mark KEY_ENTER select last loaded commit
164 c671dc65 2023-04-24 mark F toggle fullscreen
165 c671dc65 2023-04-24 mark J move down to next commit in the log
169 c671dc65 2023-04-24 mark cat <<EOF >$testroot/view.expected
170 c671dc65 2023-04-24 mark [1/20] diff $id6 $id7
171 c671dc65 2023-04-24 mark commit $id7
172 c671dc65 2023-04-24 mark from: Flan Hacker <flan_hacker@openbsd.org>
173 c671dc65 2023-04-24 mark date: $date
177 c671dc65 2023-04-24 mark M alpha | 1+ 1-
179 c671dc65 2023-04-24 mark 1 file changed, 1 insertion(+), 1 deletion(-)
181 c671dc65 2023-04-24 mark commit - $id6
182 c671dc65 2023-04-24 mark commit + $id7
183 c671dc65 2023-04-24 mark blob - $blobid6
184 c671dc65 2023-04-24 mark blob + $blobid7
187 c671dc65 2023-04-24 mark @@ -1 +1 @@
197 c671dc65 2023-04-24 mark cmp -s $testroot/view.expected $testroot/view
199 c671dc65 2023-04-24 mark if [ $ret -ne 0 ]; then
200 c671dc65 2023-04-24 mark diff -u $testroot/view.expected $testroot/view
201 c671dc65 2023-04-24 mark test_done "$testroot" "$ret"
205 c671dc65 2023-04-24 mark test_done "$testroot" "$ret"
208 c4df265e 2023-07-19 mark test_diff_commit_keywords()
210 c4df265e 2023-07-19 mark test_init diff_commit_keywords 120 24
211 c4df265e 2023-07-19 mark local repo="$testroot/repo"
212 c4df265e 2023-07-19 mark local wt="$testroot/wt"
213 c4df265e 2023-07-19 mark local id=$(git_show_head "$repo")
214 c4df265e 2023-07-19 mark local author_time=$(git_show_author_time "$repo")
215 c4df265e 2023-07-19 mark local date=$(date -u -r $author_time +"%a %b %e %X %Y UTC")
217 c4df265e 2023-07-19 mark set -A ids "$id"
218 c4df265e 2023-07-19 mark set -A alpha_ids $(get_blob_id "$repo" "" alpha)
220 c4df265e 2023-07-19 mark got checkout "$repo" "$wt" > /dev/null
222 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
223 c4df265e 2023-07-19 mark echo "got checkout failed unexpectedly"
224 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
228 c4df265e 2023-07-19 mark # move into the work tree (test is run in a subshell)
231 c4df265e 2023-07-19 mark for i in $(seq 8); do
232 c4df265e 2023-07-19 mark echo "alpha $i" > alpha
234 c4df265e 2023-07-19 mark got ci -m "commit $i" > /dev/null
236 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
237 c4df265e 2023-07-19 mark echo "commit failed unexpectedly" >&2
238 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
242 c4df265e 2023-07-19 mark id=$(git_show_head "$repo")
243 c4df265e 2023-07-19 mark set -- "$ids" "$id"
245 c4df265e 2023-07-19 mark set -- "$alpha_ids" "$(get_blob_id "$repo" "" alpha)"
246 c4df265e 2023-07-19 mark alpha_ids=$*
249 c4df265e 2023-07-19 mark cat <<-EOF >$TOG_TEST_SCRIPT
253 c4df265e 2023-07-19 mark # diff consecutive commits with keywords
254 c4df265e 2023-07-19 mark local lhs_id=$(pop_id 1 $ids)
255 c4df265e 2023-07-19 mark local rhs_id=$(pop_id 2 $ids)
257 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
258 c4df265e 2023-07-19 mark [1/20] diff $lhs_id $rhs_id
259 c4df265e 2023-07-19 mark commit $rhs_id
260 c4df265e 2023-07-19 mark from: Flan Hacker <flan_hacker@openbsd.org>
261 c4df265e 2023-07-19 mark date: $date
265 c4df265e 2023-07-19 mark M alpha | 1+ 1-
267 c4df265e 2023-07-19 mark 1 file changed, 1 insertion(+), 1 deletion(-)
269 c4df265e 2023-07-19 mark commit - $lhs_id
270 c4df265e 2023-07-19 mark commit + $rhs_id
271 c4df265e 2023-07-19 mark blob - $(pop_id 1 $alpha_ids)
272 c4df265e 2023-07-19 mark blob + $(pop_id 2 $alpha_ids)
275 c4df265e 2023-07-19 mark @@ -1 +1 @@
284 c4df265e 2023-07-19 mark tog diff :base:-99 :head:-7
285 c4df265e 2023-07-19 mark cmp -s "$testroot/view.expected" "$testroot/view"
287 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
288 c4df265e 2023-07-19 mark diff -u "$testroot/view.expected" "$testroot/view"
289 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
293 c4df265e 2023-07-19 mark # diff arbitrary commits with keywords
294 c4df265e 2023-07-19 mark lhs_id=$(pop_id 5 $ids)
295 c4df265e 2023-07-19 mark rhs_id=$(pop_id 8 $ids)
297 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
298 c4df265e 2023-07-19 mark [1/10] diff $lhs_id $rhs_id
299 c4df265e 2023-07-19 mark commit - $lhs_id
300 c4df265e 2023-07-19 mark commit + $rhs_id
301 c4df265e 2023-07-19 mark blob - $(pop_id 5 $alpha_ids)
302 c4df265e 2023-07-19 mark blob + $(pop_id 8 $alpha_ids)
305 c4df265e 2023-07-19 mark @@ -1 +1 @@
324 c4df265e 2023-07-19 mark tog diff master:-4 :head:-
325 c4df265e 2023-07-19 mark cmp -s "$testroot/view.expected" "$testroot/view"
327 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
328 c4df265e 2023-07-19 mark diff -u "$testroot/view.expected" "$testroot/view"
329 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
333 c4df265e 2023-07-19 mark # diff consecutive commits using keywords with -r repository
334 c4df265e 2023-07-19 mark lhs_id=$(pop_id 8 $ids)
335 c4df265e 2023-07-19 mark rhs_id=$(pop_id 9 $ids)
336 c4df265e 2023-07-19 mark author_time=$(git_show_author_time "$repo")
337 c4df265e 2023-07-19 mark date=$(date -u -r $author_time +"%a %b %e %X %Y UTC")
339 c4df265e 2023-07-19 mark cat <<-EOF >$testroot/view.expected
340 c4df265e 2023-07-19 mark [1/20] diff $lhs_id refs/heads/master
341 c4df265e 2023-07-19 mark commit $rhs_id (master)
342 c4df265e 2023-07-19 mark from: Flan Hacker <flan_hacker@openbsd.org>
343 c4df265e 2023-07-19 mark date: $date
347 c4df265e 2023-07-19 mark M alpha | 1+ 1-
349 c4df265e 2023-07-19 mark 1 file changed, 1 insertion(+), 1 deletion(-)
351 c4df265e 2023-07-19 mark commit - $lhs_id
352 c4df265e 2023-07-19 mark commit + $rhs_id
353 c4df265e 2023-07-19 mark blob - $(pop_id 8 $alpha_ids)
354 c4df265e 2023-07-19 mark blob + $(pop_id 9 $alpha_ids)
357 c4df265e 2023-07-19 mark @@ -1 +1 @@
366 c4df265e 2023-07-19 mark tog diff -r "$repo" :head:- master
367 c4df265e 2023-07-19 mark cmp -s "$testroot/view.expected" "$testroot/view"
369 c4df265e 2023-07-19 mark if [ $ret -ne 0 ]; then
370 c4df265e 2023-07-19 mark diff -u "$testroot/view.expected" "$testroot/view"
371 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
375 c4df265e 2023-07-19 mark test_done "$testroot" "$ret"
378 de7a51b7 2023-04-15 mark test_parseargs "$@"
379 de7a51b7 2023-04-15 mark run_test test_diff_contiguous_commits
380 de7a51b7 2023-04-15 mark run_test test_diff_arbitrary_commits
381 c671dc65 2023-04-24 mark run_test test_diff_J_keymap_on_last_loaded_commit
382 c4df265e 2023-07-19 mark run_test test_diff_commit_keywords