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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
test_description='Check content on diff page'
. ./setup.sh
test_expect_success 'generate foo/diff' 'cgit_url "foo/diff" >tmp'
test_expect_success 'find diff header' 'grep "a/file-5 b/file-5" tmp'
test_expect_success 'find blob link' 'grep "<a href=./foo/tree/file-5?id=" tmp'
test_expect_success 'find added file' 'grep "new file mode 100644" tmp'
test_expect_success 'find hunk header' '
grep "<div class=.hunk.>@@ -0,0 +1 @@</div>" tmp
'
test_expect_success 'find added line' '
grep "<div class=.add.>+5</div>" tmp
'
test_expect_success 'the unified diff table is read as layout' '
grep "<table class=.diff. role=.presentation.>" tmp
'
test_expect_success 'a tree on either side is named as the request gave it' '
tree=$(git -C repos/foo rev-parse --short HEAD^{tree}) &&
cgit_url "foo/diff/&id=$tree" >tmp &&
grep "<div class=.error.>Not a commit: $tree</div>" tmp &&
cgit_url "foo/diff/&id2=$tree" >tmp &&
grep "<div class=.error.>Not a commit: $tree</div>" tmp
'
test_expect_success 'set up a repo with single-line hunks' '
mkrepo repos/hunk1 1 &&
(
cd repos/hunk1 &&
printf "only\n" >one.txt &&
git add one.txt &&
git commit -m "add one.txt" &&
printf "ONLY\n" >one.txt &&
git commit -am "change one.txt"
) &&
cgitrc_repo hunk1rc hunk1 &&
git -C repos/hunk1 diff HEAD~1 HEAD >raw.diff &&
grep "^@@ -1 +1 @@" raw.diff
'
test_expect_success 'ssdiff numbers a comma-less hunk from its real line' '
old=$(git -C repos/hunk1 rev-parse HEAD~1) &&
new=$(git -C repos/hunk1 rev-parse HEAD) &&
cgit_ok hunk1rc "url=hunk1/diff/&dt=1" >tmp &&
grep "<a href=./hunk1/tree/one.txt?id=$old#n1.>1</a>" tmp &&
grep "<a href=./hunk1/tree/one.txt?id=$new#n1.>1</a>" tmp
'
test_expect_success 'set up a repo whose later hunk starts apart on each side' '
mkrepo repos/later 1 &&
(
cd repos/later &&
test_seq 1 20 >twenty.txt &&
git add twenty.txt &&
git commit -m "add twenty.txt" &&
test_seq 1 20 | sed -e 2d -e s/^15$/fifteen/ >twenty.txt &&
git commit -am "change twenty.txt"
) &&
cgitrc_repo laterrc later &&
git -C repos/later diff HEAD~1 HEAD >raw.diff &&
grep "^@@ -12,7 +11,7 @@" raw.diff
'
test_expect_success 'ssdiff numbers each side of a hunk from its own start' '
old=$(git -C repos/later rev-parse HEAD~1) &&
new=$(git -C repos/later rev-parse HEAD) &&
cgit_ok laterrc "url=later/diff/&dt=1" >tmp &&
grep -x "<td class=.lineno.><a href=./later/tree/twenty.txt?id=$old#n12.>12</a></td><td class=.ctx.>12</td>" tmp &&
grep -x "<td class=.lineno.><a href=./later/tree/twenty.txt?id=$new#n11.>11</a></td><td class=.ctx.>12</td></tr>" tmp &&
grep "<a href=./later/tree/twenty.txt?id=$old#n15.>15</a></td><td class=.changed.>" tmp &&
grep "<a href=./later/tree/twenty.txt?id=$new#n14.>14</a></td><td class=.changed.>" tmp
'
test_expect_success 'set up a repo with shrinking changed lines' '
mkrepo repos/lcs 1 &&
(
cd repos/lcs &&
awk "BEGIN{for(n=120;n>0;n-=3){s=\"\";
for(i=0;i<n;i++)s=s sprintf(\"%c\",97+(i*7+n)%26); print s}}" >lines.txt &&
git add lines.txt &&
git commit -m "add lines.txt" &&
awk "BEGIN{for(n=120;n>0;n-=3){s=\"\";
for(i=0;i<n;i++){c=97+(i*7+n)%26; if(i%7==0)c=97+(c-97+5)%26;
s=s sprintf(\"%c\",c)} print s}}" >lines.txt &&
git commit -am "change every line"
) &&
cgitrc_repo lcsrc lcs
'
test_expect_success 'every changed pair gets both a del and an add span' '
cgit_rc lcsrc "url=lcs/diff/&dt=1" >tmp &&
deletions=$(grep -o "<span class=.del.>" tmp | wc -l) &&
additions=$(grep -o "<span class=.add.>" tmp | wc -l) &&
test "$deletions" -gt 0 &&
test "$deletions" -eq "$additions"
'
test_expect_success 'stripping the highlight leaves every line intact' '
sed -e "s/<[^>]*>//g" tmp >plain.out &&
git -C repos/lcs show HEAD~1:lines.txt >lines &&
git -C repos/lcs show HEAD:lines.txt >>lines &&
while read -r line
do
grep -qF "$line" plain.out || {
echo "missing line: $line"
return 1
}
done <lines
'
test_expect_success 'set up a renamed file' '
mkrepo repos/moved 1 &&
(
cd repos/moved &&
test_seq 1 10 >old.txt &&
git add old.txt &&
git commit -m "add old.txt" &&
git mv old.txt new.txt &&
echo changed >file-1 &&
git commit -am "rename old.txt"
) &&
cgitrc_repo movedrc moved
'
test_expect_success 'the diff of a renamed file shows the rename alone' '
cgit_ok movedrc "url=moved/diff/new.txt" >tmp &&
grep "diff --git a/old.txt b/new.txt" tmp &&
grep "</a> (renamed from old.txt)</td>" tmp &&
grep "<div class=.diffstat-summary.>1 file changed, 0 insertions, 0 deletions</div>" tmp &&
! grep "new file mode" tmp &&
! grep "a/file-1 b/file-1" tmp
'
test_expect_success 'so does the commit page limited to the new name' '
cgit_ok movedrc "url=moved/commit/new.txt" >tmp &&
grep "diff --git a/old.txt b/new.txt" tmp &&
grep "<div class=.diffstat-summary.>1 file changed, 0 insertions, 0 deletions</div>" tmp &&
! grep "new file mode" tmp &&
! grep "a/file-1 b/file-1" tmp
'
test_expect_success 'a followed file is diffed as the rename alone' '
cgitrc_repo followrc moved enable-follow-links=1 &&
cgit_ok followrc "url=moved/diff/new.txt&follow=1" >tmp &&
grep "diff --git a/old.txt b/new.txt" tmp &&
grep "Diffstat</a> (limited to .new.txt.)</div>" tmp &&
grep "<div class=.diffstat-summary.>1 file changed, 0 insertions, 0 deletions</div>" tmp &&
! grep "a/file-1 b/file-1" tmp &&
cgit_ok followrc "url=moved/commit/new.txt&follow=1" >tmp &&
grep "diff --git a/old.txt b/new.txt" tmp &&
grep "Diffstat</a> (limited to .new.txt.)</div>" tmp &&
! grep "a/file-1 b/file-1" tmp
'
test_expect_success 'following with no path limits nothing' '
cgit_ok followrc "url=moved/commit/&follow=1" >tmp &&
grep "diff --git a/file-1 b/file-1" tmp &&
grep "<div class=.diffstat-header.><a href=[^>]*>Diffstat</a></div>" tmp
'
test_expect_success 'a file added outright still shows as new' '
added=$(git -C repos/moved rev-parse HEAD~1) &&
cgit_ok movedrc "url=moved/diff/old.txt&id=$added" >tmp &&
grep "new file mode 100644" tmp &&
grep "<div class=.add.>+10</div>" tmp
'
test_done
|