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
|
test_description='Check submodule links derived from .gitmodules'
. ./setup.sh
test_expect_success 'set up a parent repo with submodules' '
mkrepo repos/subtarget 2 &&
mkrepo repos/subparent 1 &&
sub=$(git -C repos/subtarget rev-parse HEAD) &&
(
cd repos/subparent &&
for path in local-ssh sibling forge-https forge-ssh opaque cgit-host \
http-url git-url ssh-url file-url near-miss gitlab bitbucket deps/lib
do
git update-index --add --cacheinfo 160000,$sub,$path || return 1
done &&
cat >.gitmodules <<-\EOF &&
[submodule "local-ssh"]
path = local-ssh
url = git@example.com:mirrors/subtarget.git
[submodule "sibling"]
path = sibling
url = ../subtarget.git
[submodule "forge-https"]
path = forge-https
url = https://github.com/example/project.git
[submodule "forge-ssh"]
path = forge-ssh
url = git@github.com:example/other.git
[submodule "opaque"]
path = opaque
url = git@private.example.com:closed/thing.git
[submodule "cgit-host"]
path = cgit-host
url = https://git.kernel.org/pub/scm/git/git.git
[submodule "http-url"]
path = http-url
url = http://example.com/mirrors/subtarget.git
[submodule "git-url"]
path = git-url
url = git://example.com/subtarget.git
[submodule "ssh-url"]
path = ssh-url
url = ssh://git@example.com/srv/subtarget.git
[submodule "file-url"]
path = file-url
url = file:///srv/git/subtarget.git
[submodule "near-miss"]
path = near-miss
url = https://example.com/xsubtarget.git
[submodule "gitlab"]
path = gitlab
url = https://gitlab.com/group/project.git
[submodule "bitbucket"]
path = bitbucket
url = git@bitbucket.org:team/repo.git
[submodule "deps/lib"]
path = deps/lib
url = ../subtarget.git
EOF
git add .gitmodules &&
git commit -m submodules &&
sed "s|git@example.com:mirrors/subtarget.git|https://example.org/moved.git|" .gitmodules >moved &&
mv moved .gitmodules &&
git add .gitmodules &&
git commit -m "move local-ssh"
) &&
cgitrc_repo subrc subparent enable-gitmodules-links=1 &&
echo "repo.url=subtarget" >>subrc &&
echo "repo.path=$PWD/repos/subtarget/.git" >>subrc
'
test_expect_success 'an ssh url served here links to the local repo and commit' '
sub=$(git -C repos/subtarget rev-parse HEAD) &&
old=$(git -C repos/subparent rev-parse HEAD~1) &&
cgit_ok subrc "url=subparent/tree/&id=$old" >tmp &&
grep "<a class=.ls-mod. href=./subtarget/tree/?id=$sub.>local-ssh</a> @ <a class=.ls-mod-hash. href=./subtarget/commit/?id=$sub. title=.$sub.>" tmp
'
test_expect_success 'the links follow the .gitmodules of the shown revision' '
sub=$(git -C repos/subtarget rev-parse HEAD) &&
cgit_ok subrc "url=subparent/tree/" >tmp &&
grep "<a class=.ls-mod. href=.https://example.org/moved.git.>local-ssh</a> @ <span class=.ls-mod-hash. title=.$sub.>" tmp
'
test_expect_success 'a relative url resolves against this repository' '
sub=$(git -C repos/subtarget rev-parse HEAD) &&
cgit_ok subrc "url=subparent/tree/" >tmp &&
grep "<a class=.ls-mod. href=./subtarget/tree/?id=$sub.>sibling</a>" tmp
'
test_expect_success 'every scheme that names a repository served here links to it' '
sub=$(git -C repos/subtarget rev-parse HEAD) &&
cgit_ok subrc "url=subparent/tree/" >tmp &&
for name in http-url git-url ssh-url file-url
do
grep "<a class=.ls-mod. href=./subtarget/tree/?id=$sub.>$name</a> @ <a class=.ls-mod-hash. href=./subtarget/commit/?id=$sub." tmp ||
return 1
done
'
test_expect_success 'a url only ending in a served name is not taken for it' '
sub=$(git -C repos/subtarget rev-parse HEAD) &&
cgit_ok subrc "url=subparent/tree/" >tmp &&
grep "<a class=.ls-mod. href=.https://example.com/xsubtarget.git.>near-miss</a> @ <span class=.ls-mod-hash. title=.$sub.>" tmp
'
test_expect_success 'a web url is linked as it is' '
cgit_ok subrc "url=subparent/tree/" >tmp &&
grep "href=.https://github.com/example/project.git.>forge-https</a>" tmp
'
test_expect_success 'a known forge hash links to its commit page' '
sub=$(git -C repos/subtarget rev-parse HEAD) &&
cgit_ok subrc "url=subparent/tree/" >tmp &&
grep "href=.https://github.com/example/project/commit/$sub." tmp &&
grep "href=.https://gitlab.com/group/project/-/commit/$sub." tmp
'
test_expect_success 'an ssh url to a known forge is rewritten' '
sub=$(git -C repos/subtarget rev-parse HEAD) &&
cgit_ok subrc "url=subparent/tree/" >tmp &&
grep "href=.https://github.com/example/other.>forge-ssh</a>" tmp &&
grep "href=.https://github.com/example/other/commit/$sub." tmp &&
grep "href=.https://bitbucket.org/team/repo.>bitbucket</a> @ <a class=.ls-mod-hash. href=.https://bitbucket.org/team/repo/commits/$sub." tmp
'
test_expect_success 'a cgit host keeps its .git suffix in the commit link' '
sub=$(git -C repos/subtarget rev-parse HEAD) &&
cgit_ok subrc "url=subparent/tree/" >tmp &&
grep "<a class=.ls-mod. href=.https://git.kernel.org/pub/scm/git/git.git.>cgit-host</a>" tmp &&
grep "href=.https://git.kernel.org/pub/scm/git/git.git/commit/?id=$sub." tmp
'
test_expect_success 'an unresolvable url stays unlinked with a tooltip' '
sub=$(git -C repos/subtarget rev-parse HEAD) &&
cgit_ok subrc "url=subparent/tree/" >tmp &&
grep "<span class=.ls-mod. title=.git@private.example.com:closed/thing.git.>opaque</span> @ <span class=.ls-mod-hash. title=.$sub.>" tmp
'
test_expect_success 'a submodule below the top level is found by its path' '
sub=$(git -C repos/subtarget rev-parse HEAD) &&
cgit_ok subrc "url=subparent/tree/deps" >tmp &&
grep "<a class=.ls-mod. href=./subtarget/tree/?id=$sub.>lib</a>" tmp
'
test_expect_success 'a submodule path is answered with its link' '
sub=$(git -C repos/subtarget rev-parse HEAD) &&
cgit_rc subrc "url=subparent/tree/sibling" >tmp &&
grep "^Status: 404" tmp &&
grep "<div class=.error.>This path is a submodule: <a class=.ls-mod. href=./subtarget/tree/?id=$sub.>sibling</a>" tmp
'
test_expect_success 'the module-link templates win over .gitmodules' '
sub=$(git -C repos/subtarget rev-parse HEAD) &&
cgitrc_repo modrc subparent enable-gitmodules-links=1 "module-link=/mods/%s/%s" \
"repo.module-link.sibling=/pinned/%s" &&
cgit_ok modrc "url=subparent/tree/" >tmp &&
grep "<a class=.ls-mod. href=./mods/local-ssh/$sub.>local-ssh</a>" tmp &&
grep "<a class=.ls-mod. href=./pinned/$sub.>sibling</a>" tmp &&
! grep "subtarget/tree" tmp
'
test_expect_success 'the links stay off without the flag' '
cgitrc_repo suboffrc subparent &&
cgit_ok suboffrc "url=subparent/tree/" >tmp &&
! grep "subtarget/tree" tmp &&
grep "class=.ls-mod.>local-ssh</span>" tmp
'
test_done
|