1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
test_description='Check content on commit page'
. ./setup.sh
test_expect_success 'generate foo/commit' 'cgit_ok_url "foo/commit" >tmp'
test_expect_success 'find tree link' '
tree=$(git -C repos/foo rev-parse master^{tree}) &&
test_grep "<th scope=.row.>tree</th><td colspan=.2. class=.oid.><div class=.spanning.><a href=./foo/tree/.>$tree</a>" tmp
'
test_expect_success 'find parent link' '
parent=$(git -C repos/foo rev-parse master~1) &&
test_grep "<th scope=.row.>parent</th><td colspan=.2. class=.oid.><div class=.spanning.><a href=./foo/commit/?id=$parent.>$parent</a>" tmp
'
test_expect_success 'subject links name a parent by its subject' '
cgitrc_copy subjectrc enable-subject-links=1 &&
parent=$(git -C repos/foo rev-parse master~1) &&
cgit_ok subjectrc "url=foo/commit" >tmp &&
test_grep "<th scope=.row.>parent</th><td colspan=.2. class=.oid.><div class=.spanning.><a href=./foo/commit/?id=$parent.>commit 4</a>" tmp
'
test_expect_success 'find commit subject' '
grep "<div class=.commit-subject.>commit 5<" tmp
'
test_expect_success 'find commit msg' 'grep "<div class=.commit-msg.></div>" tmp'
test_expect_success 'find diffstat' 'grep "<table class=.diffstat.>" tmp'
test_expect_success 'find diff summary' '
grep "1 file changed, 1 insertion, 0 deletions" tmp
'
test_expect_success 'the diffstat bar is an SVG sized by its attributes' '
grep "<td class=.graph.><svg viewBox=.0 0 1000 1. preserveAspectRatio=.none. aria-hidden=.true.><rect class=.add. width=.1000. height=.1./></svg></td>" tmp
'
test_expect_success 'a commit that changes no files draws no diffstat table' '
(
cd repos/foo &&
git update-ref refs/heads/empty $(git commit-tree HEAD^{tree} -p HEAD -m empty)
) &&
cgit_ok_url "foo/commit/&h=empty" >tmp &&
grep "0 files changed, 0 insertions, 0 deletions" tmp &&
test_grep ! "<table class=.diffstat.>" tmp
'
test_expect_success 'a root commit diffs against the empty tree' '
root=$(git -C repos/foo rev-list --max-parents=0 HEAD) &&
cgit_ok_url "foo/commit&id=$root" >tmp &&
test_grep "<a href=./foo/diff/file-1.id=$root.>file-1</a>" tmp &&
test_grep ">diff --git a/file-1 b/file-1<" tmp &&
test_grep "<div class=.add.>+1</div>" tmp
'
test_expect_success 'a message that is not UTF-8 has its stray bytes replaced' '
(
cd repos/foo &&
tree=$(git rev-parse HEAD^{tree}) &&
printf "tree %s\nauthor A U Thor <author@example.com> 1735689600 +0000\n" "$tree" >raw &&
printf "committer A U Thor <author@example.com> 1735689600 +0000\n" >>raw &&
printf "encoding no-such-charset\n\ncaf\351 subject\n\nbody \377 end\n" >>raw &&
cid=$(git hash-object --literally -t commit -w raw) &&
git update-ref refs/heads/latin "$cid" &&
printf "tree %s\nauthor A U Thor <author@example.com> 1735689600 +0000\n" "$tree" >raw &&
printf "committer A U Thor <author@example.com> 1735689600 +0000\n" >>raw &&
printf "\nbare caf\351 subject\n" >>raw &&
cid=$(git hash-object --literally -t commit -w raw) &&
git update-ref refs/heads/bare "$cid"
) &&
cgit_ok_url "foo/commit&h=latin" >tmp &&
grep "<div class=.commit-subject.>caf? subject<" tmp &&
grep "body ? end" tmp &&
test_grep ! "caf$(printf "\351")" tmp &&
cgit_ok_url "foo/commit&h=bare" >tmp &&
test_grep "<div class=.commit-subject.>bare caf? subject<" tmp &&
test_grep ! "caf$(printf "\351")" tmp
'
test_expect_success 'an octopus merge draws no diff and offers no diff options' '
(
cd repos/foo &&
tree=$(git rev-parse HEAD~1^{tree}) &&
cid=$(git commit-tree -p HEAD -p HEAD~1 -p HEAD~2 -m octopus $tree) &&
git update-ref refs/heads/octopus "$cid" &&
cid=$(git commit-tree -p HEAD -p HEAD~2 -m twofold $tree) &&
git update-ref refs/heads/twofold "$cid"
) &&
cgit_ok_url "foo/commit&h=octopus" >tmp &&
test_grep "<div class=.commit-subject.>octopus<" tmp &&
test $(grep -c "<th scope=.row.>parent</th>" tmp) = 3 &&
test_grep ! "cgit-panel" tmp &&
test_grep ! "<table class=.diffstat.>" tmp &&
cgit_ok_url "foo/commit&h=twofold" >tmp &&
test $(grep -c "<th scope=.row.>parent</th>" tmp) = 2 &&
test_grep "cgit-panel" tmp &&
test_grep "<table class=.diffstat.>" tmp
'
test_expect_success 'the commit page offers a download per snapshot format' '
cgit_ok_url "foo/commit" >tmp &&
test_grep "<th scope=.row.>download</th><td colspan=.2. class=.oid.><div class=.spanning.><span class=.snapshot.><a href=./foo/snapshot/foo-master.tar.>foo-master.tar</a></span><br>" tmp &&
test_grep "<a href=./foo/snapshot/foo-master.zip.>foo-master.zip</a>" tmp &&
cgitrc_repo nosnaprc foo &&
cgit_ok nosnaprc "url=foo/commit" >tmp &&
test_grep "<th scope=.row.>tree</th>" tmp &&
test_grep ! ">download</th>" tmp
'
test_expect_success 'a note is shown below the message' '
git -C repos/foo notes add -m "a note on five" master &&
test_when_finished "git -C repos/foo notes remove master" &&
cgit_ok_url "foo/commit" >tmp &&
test_grep "<div class=.notes-header.>Notes</div>" tmp &&
test_grep "<div class=.notes.>a note on five$" tmp
'
test_done
|