From 717c9a822db8e081c2001b79d63eaa1663277b95 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 17 Oct 2026 12:53:18 -1000 Subject: Show an absolute link target as text A symlink to /etc/passwd was resolved against the tree and linked to etc/passwd inside it, a different file or none at all. --- source/ui-tree.c | 7 ++++--- tests/t0104-tree.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/source/ui-tree.c b/source/ui-tree.c index c030134..51ab9ff 100644 --- a/source/ui-tree.c +++ b/source/ui-tree.c @@ -336,9 +336,10 @@ static void print_ls_row(const struct object_id *oid, const char *pathname, } else { strbuf_addbuf(&linkpath, &fullpath); strbuf_addf(&linkpath, "/../%s", buf); - // A target climbing above the tree root has nothing to - // link to. - if (strbuf_normalize_path(&linkpath)) + // A target climbing above the tree root, or one given + // from the root of the filesystem, has nothing in the + // tree to link to. + if (buf[0] == '/' || strbuf_normalize_path(&linkpath)) html_txt(buf); else cgit_tree_link(buf, NULL, class.buf, ctx.qry.head, walk->rev, diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh index 48c8406..a2ec3c2 100755 --- a/tests/t0104-tree.sh +++ b/tests/t0104-tree.sh @@ -82,4 +82,30 @@ test_expect_success 'a file row still offers blame' ' grep ">blame" tmp ' +# A link target inside the tree becomes a link, while an absolute one names a +# file on whatever machine checks the tree out, not a path in the tree. +test_expect_success 'only a link target inside the tree is linked' ' + test_create_repo repos/links && + ( + cd repos/links && + echo hi >target.txt && + git add target.txt && + rel=$(printf target.txt | git hash-object -w --stdin) && + abs=$(printf /etc/passwd | git hash-object -w --stdin) && + git update-index --add --cacheinfo 120000,$rel,rel && + git update-index --add --cacheinfo 120000,$abs,abs && + git commit -m links + ) && + { + echo "virtual-root=/" && + echo "cache-size=0" && + echo "repo.url=links" && + echo "repo.path=$PWD/repos/links/.git" + } >linksrc && + CGIT_CONFIG="$PWD/linksrc" QUERY_STRING="url=links/tree/" cgit >tmp && + grep " -> target.txt" tmp && + grep " -> /etc/passwd" tmp && + ! grep "href=./links/tree/etc/passwd" tmp +' + test_done -- cgit