From 78d36a62c8488328615113262d89ec93512634c8 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 13:46:53 -1000 Subject: Check submodule links by revision, path and url Every request viewed HEAD and every gitlink sat at the top level, so a link read from the wrong revision's .gitmodules, or looked up by the shown name rather than the full path, passed. The other url schemes, the whole-component rule, the other forges, the templates that take precedence and the submodule page had no test, and the gitlinks pointed at the parent's own commit rather than one of subtarget's. --- tests/t0202-submodule-links.sh | 150 ++++++++++++++++++++++++++++++++--------- 1 file changed, 118 insertions(+), 32 deletions(-) diff --git a/tests/t0202-submodule-links.sh b/tests/t0202-submodule-links.sh index a5810a0..ffe10de 100755 --- a/tests/t0202-submodule-links.sh +++ b/tests/t0202-submodule-links.sh @@ -3,23 +3,27 @@ # Submodule rows derive their links from the .gitmodules entry at the shown # revision once enable-gitmodules-links is set, landing on an internal page, # a plain or rewritten web url, or an unlinked tooltip depending on the url. -# Each of those outcomes is checked against a fixture .gitmodules. +# Each of those outcomes is checked against a fixture .gitmodules, along with +# an older revision whose .gitmodules said otherwise, a submodule below the +# top level and the module-link templates that take precedence. test_description='Check submodule links derived from .gitmodules' . ./setup.sh +# Every gitlink points at the tip of subtarget, which a link served here leads +# to. The first commit has local-ssh at a url served here, and the second moves +# it elsewhere. test_expect_success 'set up a parent repo with submodules' ' - mkrepo repos/subtarget 1 && + mkrepo repos/subtarget 2 && mkrepo repos/subparent 1 && - sub=$(git -C repos/subparent rev-parse HEAD) && + sub=$(git -C repos/subtarget rev-parse HEAD) && ( cd repos/subparent && - 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 && + 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 @@ -39,61 +43,143 @@ test_expect_success 'set up a parent repo with submodules' ' [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 + 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" ) && - { - 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 + 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 "local-ssh @ " tmp ' -test_expect_success 'generate subparent/tree' ' - cgit_rc subrc "url=subparent/tree/" >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 "local-ssh @ " tmp ' -test_expect_success 'an ssh url served here links to the local repo' ' - grep "href=./subtarget/tree/?id=$sub.>local-ssh" 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 "sibling" tmp ' -test_expect_success 'its hash links to the local commit page' ' - grep "href=./subtarget/commit/?id=$sub." 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 "$name @ sibling" tmp +# Only whole trailing components count, so xsubtarget is no url for +# subtarget, and an https url is then linked as it is. +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 "near-miss @ " 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" tmp ' test_expect_success 'a known forge hash links to its commit page' ' - grep "href=.https://github.com/example/project/commit/$sub." tmp + 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" tmp && - grep "href=.https://github.com/example/other/commit/$sub." tmp + grep "href=.https://github.com/example/other/commit/$sub." tmp && + grep "href=.https://bitbucket.org/team/repo.>bitbucket @ tmp && + grep "cgit-host" 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' ' - grep "class=.ls-mod. title=.git@private.example.com:closed/thing.git.>opaque" tmp + sub=$(git -C repos/subtarget rev-parse HEAD) && + cgit_ok subrc "url=subparent/tree/" >tmp && + grep "opaque @ " tmp +' + +# The row names the entry alone, while .gitmodules is looked up by the full +# path. +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 "lib" 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 "
This path is a submodule: sibling" tmp +' + +# A template is the site saying where its submodules live, so it wins over +# what .gitmodules would give, and a template for one path wins over both. +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 "local-ssh" tmp && + grep "sibling" tmp && + ! grep "subtarget/tree" tmp ' test_expect_success 'the links stay off without the flag' ' - sed "/enable-gitmodules-links/d" subrc >subrcoff && - cgit_rc subrcoff "url=subparent/tree/" >tmp && + cgitrc_repo suboffrc subparent && + cgit_ok suboffrc "url=subparent/tree/" >tmp && ! grep "subtarget/tree" tmp && grep "class=.ls-mod.>local-ssh" tmp ' -- cgit 2.12.1