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
|
test_description='Check submodule links derived from .gitmodules'
. ./setup.sh
test_expect_success 'set up a parent repo with submodules' '
mkrepo repos/subtarget 1 &&
mkrepo repos/subparent 1 &&
(
cd repos/subparent &&
sub=$(git rev-parse HEAD) &&
git update-index --add --cacheinfo 160000,$sub,local-ssh &&
git update-index --add --cacheinfo 160000,$sub,sibling &&
git update-index --add --cacheinfo 160000,$sub,forge-https &&
git update-index --add --cacheinfo 160000,$sub,forge-ssh &&
git update-index --add --cacheinfo 160000,$sub,opaque &&
git update-index --add --cacheinfo 160000,$sub,cgit-host &&
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
EOF
git add .gitmodules &&
git commit -m submodules
) &&
{
echo "virtual-root=/" &&
echo "cache-size=0" &&
echo "enable-gitmodules-links=1" &&
echo "repo.url=subparent" &&
echo "repo.path=$PWD/repos/subparent/.git" &&
echo "repo.url=subtarget" &&
echo "repo.path=$PWD/repos/subtarget/.git"
} >subrc
'
test_expect_success 'generate subparent/tree' '
CGIT_CONFIG="$PWD/subrc" QUERY_STRING="url=subparent/tree/" cgit >tmp
'
test_expect_success 'an ssh url served here links to the local repo' '
sub=$(git -C repos/subparent rev-parse HEAD~1) &&
grep "href=./subtarget/tree/?id=$sub.>local-ssh</a>" tmp
'
test_expect_success 'its hash links to the local commit page' '
sub=$(git -C repos/subparent rev-parse HEAD~1) &&
grep "href=./subtarget/commit/?id=$sub." tmp
'
test_expect_success 'a relative url resolves against this repository' '
sub=$(git -C repos/subparent rev-parse HEAD~1) &&
grep "href=./subtarget/tree/?id=$sub.>sibling</a>" tmp
'
test_expect_success 'a web url is linked as it is' '
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/subparent rev-parse HEAD~1) &&
grep "href=.https://github.com/example/project/commit/$sub." tmp
'
test_expect_success 'an ssh url to a known forge is rewritten' '
sub=$(git -C repos/subparent rev-parse HEAD~1) &&
grep "href=.https://github.com/example/other.>forge-ssh</a>" tmp &&
grep "href=.https://github.com/example/other/commit/$sub." tmp
'
test_expect_success 'a cgit host keeps its .git suffix in the commit link' '
sub=$(git -C repos/subparent rev-parse HEAD~1) &&
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' '
grep "class=.ls-mod. title=.git@private.example.com:closed/thing.git.>opaque</span>" tmp
'
test_expect_success 'the links stay off without the flag' '
sed "/enable-gitmodules-links/d" subrc >subrcoff &&
CGIT_CONFIG="$PWD/subrcoff" QUERY_STRING="url=subparent/tree/" cgit >tmp &&
! grep "subtarget/tree" tmp &&
grep "class=.ls-mod.>local-ssh</span>" tmp
'
test_done
|