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
|
test_description='Check content on patch page'
. ./setup.sh
check_cgit_signature() {
tail -n 2 tmp | head -n 1 | grep -x -F "cgit${1:+ $1}"
}
test_expect_success 'a commit is patched as git format-patch writes it' '
cgit_ok_url "foo/patch" >tmp &&
git -C repos/foo format-patch --subject-prefix="" \
--signature="cgit" --stdout HEAD^ >expect &&
strip_headers <tmp >actual &&
test_cmp expect actual
'
test_expect_success 'the patch is plain text named after the commit' '
id=$(git -C repos/foo rev-parse HEAD) &&
parent=$(git -C repos/foo rev-parse HEAD~1) &&
cgit_ok_url "foo/patch" >tmp &&
sed "/^$/q" tmp >headers &&
grep "^Content-Type: text/plain" headers &&
grep "^Content-Disposition: inline; filename=\"$parent..$id.patch\"$" headers
'
test_expect_success 'the root commit is patched whole' '
root=$(git -C repos/foo rev-list --max-parents=0 HEAD) &&
cgit_ok_url "foo/patch&id=$root" >tmp &&
git -C repos/foo format-patch --root -1 --subject-prefix="" \
--signature="cgit" --stdout "$root" >expect &&
strip_headers <tmp >actual &&
test_cmp expect actual &&
sed "/^$/q" tmp >headers &&
grep "^Content-Disposition: inline; filename=\"$root.patch\"$" headers
'
test_expect_success 'a range matches git format-patch and names the range' '
id=$(git -C repos/foo rev-parse HEAD) &&
id2=$(git -C repos/foo rev-parse HEAD~3) &&
cgit_ok_url "foo/patch&id=$id&id2=$id2" >tmp &&
git -C repos/foo format-patch --subject-prefix="" \
-N --signature="cgit" --stdout HEAD~3..HEAD >expect &&
strip_headers <tmp >actual &&
test_cmp expect actual &&
sed "/^$/q" tmp >headers &&
grep "^Content-Disposition: inline; filename=\"$id2..$id.patch\"$" headers
'
test_expect_success 'max-patch-count keeps the newest commits of a range' '
root=$(git -C repos/foo rev-list --max-parents=0 HEAD) &&
cgitrc_repo patchcountrc foo max-patch-count=2 &&
cgit_ok patchcountrc "url=foo/patch&id2=$root" >tmp &&
grep "^Subject: " tmp >actual &&
test_write_lines "Subject: commit 4" "Subject: commit 5" >expect &&
test_cmp expect actual
'
test_expect_success 'max-patch-count defaults to 50 and 0 lifts it' '
mkrepo repos/many 52 >/dev/null &&
root=$(git -C repos/many rev-list --max-parents=0 HEAD) &&
cgitrc_repo manyrc many &&
cgit_ok manyrc "url=many/patch&id2=$root" >tmp &&
test $(grep -c "^From [0-9a-f]* Mon Sep 17 00:00:00 2001$" tmp) -eq 50 &&
cgitrc_repo manyrc many max-patch-count=0 &&
cgit_ok manyrc "url=many/patch&id2=$root" >tmp &&
test $(grep -c "^From [0-9a-f]* Mon Sep 17 00:00:00 2001$" tmp) -eq 51
'
test_expect_success 'a path limits a range to the commits touching it' '
id2=$(git -C repos/foo rev-parse HEAD~3) &&
cgit_ok_url "foo/patch/file-4&id2=$id2" >tmp &&
grep "^Subject: " tmp >actual &&
test_write_lines "Subject: commit 4" >expect &&
test_cmp expect actual &&
grep "^(limited to .file-4.)$" tmp &&
! grep "file-5" tmp
'
test_expect_success 'a merge drops out of a range' '
mkrepo repos/merged 1 &&
(
cd repos/merged &&
git checkout -b side &&
echo side >side.txt &&
git add side.txt &&
git commit -m side &&
git checkout - &&
echo main >main.txt &&
git add main.txt &&
git commit -m main &&
git merge --no-ff -m merge side
) &&
root=$(git -C repos/merged rev-list --max-parents=0 HEAD) &&
cgitrc_repo mergedrc merged &&
cgit_ok mergedrc "url=merged/patch&id2=$root" >tmp &&
git -C repos/merged format-patch --subject-prefix="" \
-N --signature="cgit" --stdout "$root..HEAD" >expect &&
strip_headers <tmp >actual &&
test_cmp expect actual &&
grep "^Subject: side$" actual &&
grep "^Subject: main$" actual
'
test_expect_success 'the signature names the version when asked to' '
version=$(sed -n "s/^CGIT_VERSION = v\{0,1\}//p" "$TEST_OUTPUT_DIRECTORY/../build/VERSION") &&
test -n "$version" &&
cgitrc_copy versionrc enable-version-info=1 &&
cgit_ok versionrc "url=foo/patch" >tmp &&
check_cgit_signature "$version"
'
test_expect_success 'enable-plain-email=0 leaves the address off the patch' '
cgitrc_copy plainrc enable-plain-email=0 &&
cgit_ok plainrc "url=foo/patch" >tmp &&
grep "^From: A U Thor$" tmp &&
grep "^Subject: commit 5$" tmp &&
! grep "author@example.com" tmp
'
test_expect_success 'a renamed file is patched as the rename' '
mkrepo_renamed repos/moved &&
cgitrc_repo movedrc moved &&
cgit_ok movedrc "url=moved/patch/new.txt" >tmp &&
git -C repos/moved format-patch -1 -M --subject-prefix="" \
--signature="cgit" --stdout HEAD -- new.txt old.txt >expect &&
strip_headers <tmp >body &&
sed "/^(limited to .new.txt.)$/,/^$/d" body >actual &&
test_cmp expect actual &&
grep "^similarity index 100%$" actual &&
grep "^rename from old.txt$" actual
'
test_done
|