From c9f91124f9462d8eeb0a9d2ddeff586807413fc0 Mon Sep 17 00:00:00 2001 From: Baptiste Jonglez Date: Fri, 27 Feb 2026 16:51:11 +0100 Subject: cgit: Fix guessing default branch Even when HEAD is set to "main" in a repository, cgit still uses the "master" branch to detect the age of the last commit. Example: $ cat repositories/openwrt/openwrt.git/HEAD ref: refs/heads/main $ stat repositories/openwrt/openwrt.git/refs/heads/master Modify: 2024-02-22 23:00:01.285731731 +0000 $ stat repositories/openwrt/openwrt.git/refs/heads/main Modify: 2026-02-27 15:33:49.506017172 +0000 In this situation, cgit displays "25 months" for this repository on the index page. I guess the internal format for HEAD has changed at some point, so it needs to be taken into account when parsing it in cgit. Signed-off-by: Baptiste Jonglez --- cgit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgit.c b/cgit.c index 3dc55c3..2efbb2c 100644 --- a/cgit.c +++ b/cgit.c @@ -496,7 +496,7 @@ static char *guess_defbranch(void) ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", 0, &oid, NULL); - if (!ref || !skip_prefix(ref, "refs/heads/", &refname)) + if (!ref || !skip_prefix(ref, "ref: refs/heads/", &refname)) return "master"; return xstrdup(refname); } -- cgit v1.2.3