From waelhalbawi at gmail.com Thu Nov 5 23:46:09 2026 From: waelhalbawi at gmail.com (Wael Halbawi) Date: Thu, 5 Nov 2026 15:46:09 -0800 Subject: [PATCH] scan-tree: restore stripping of /.git from non-bare repository path Message-ID: <20261105234609.23030-1-waelhalbawi@gmail.com> Always remove the terminal /.git metadata directory component from a non-bare repository's relative path. Reserve the suffix removal code for handling a .git suffix in the repository directory's own name. Commit fb3655d added a trailing slash before the existing /.git comparison, preventing it from matching, so match /.git/ instead. Leaving the metadata component in the relative path also causes section-from-path=-1 to select the repository itself as its section. Removing it first makes section generation consistent between bare and non-bare repositories. Before patch: +-----------------------+-------------------+-------------------+ | repo type | repo name | remove_suffix = 0 | remove_suffix = 1 | +-----------------------+-------------------+-------------------+ | bare | repo | repo | repo | | bare | repo.git | repo.git | repo | | non-bare | repo | repo/.git | repo | | non-bare | repo.git | repo.git/.git | repo.git | +-----------+-----------+-------------------+-------------------+ After patch: +-----------------------+-------------------+-------------------+ | repo type | repo name | remove_suffix = 0 | remove_suffix = 1 | +-----------------------+-------------------+-------------------+ | bare | repo | repo | repo | | bare | repo.git | repo.git | repo | | non-bare | repo | repo | repo | | non-bare | repo.git | repo.git | repo | +-----------+-----------+-------------------+-------------------+ --- scan-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scan-tree.c b/scan-tree.c index c120efe..8ca2f0a 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -115,8 +115,8 @@ static void add_repo(const char *base, struct strbuf *path) else strbuf_addstr(&rel, path->buf + strlen(base) + 1); - if (!strcmp(rel.buf + rel.len - 5, "/.git")) - strbuf_setlen(&rel, rel.len - 5); + if (rel.len >= 6 && !strcmp(rel.buf + rel.len - 6, "/.git/")) + strbuf_setlen(&rel, rel.len - 6); else if (rel.len && rel.buf[rel.len - 1] == '/') strbuf_setlen(&rel, rel.len - 1); -- 2.56.0 From waelhalbawi at gmail.com Wed Nov 11 00:48:52 2026 From: waelhalbawi at gmail.com (Wael Halbawi) Date: Tue, 10 Nov 2026 16:48:52 -0800 Subject: [PATCH v2] scan-tree: restore stripping of /.git from non-bare repository path Message-ID: <20261111004915.65587-1-waelhalbawi@gmail.com> Always remove the terminal /.git metadata directory component from a non-bare repository's relative path. Reserve the suffix removal code for handling a .git suffix in the repository directory's own name. Commit fb3655d added a trailing slash before the existing /.git comparison, preventing it from matching, so match /.git/ instead. Leaving the metadata component in the relative path also causes section-from-path=-1 to select the repository itself as its section. Removing it first makes section generation consistent between bare and non-bare repositories. Before patch: +-----------------------+-------------------+-------------------+ | repo type | repo name | remove_suffix = 0 | remove_suffix = 1 | +-----------------------+-------------------+-------------------+ | bare | repo | repo | repo | | bare | repo.git | repo.git | repo | | non-bare | repo | repo/.git | repo | | non-bare | repo.git | repo.git/.git | repo.git | +-----------+-----------+-------------------+-------------------+ After patch: +-----------------------+-------------------+-------------------+ | repo type | repo name | remove_suffix = 0 | remove_suffix = 1 | +-----------------------+-------------------+-------------------+ | bare | repo | repo | repo | | bare | repo.git | repo.git | repo | | non-bare | repo | repo | repo | | non-bare | repo.git | repo.git | repo | +-----------+-----------+-------------------+-------------------+ Signed-off-by: Wael Halbawi --- v2: Add Signed-off-by trailer to commit message v1: https://lists.zx2c4.com/pipermail/cgit/2026-November/005061.html scan-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scan-tree.c b/scan-tree.c index c120efe..8ca2f0a 100644 --- a/scan-tree.c +++ b/scan-tree.c @@ -115,8 +115,8 @@ static void add_repo(const char *base, struct strbuf *path) else strbuf_addstr(&rel, path->buf + strlen(base) + 1); - if (!strcmp(rel.buf + rel.len - 5, "/.git")) - strbuf_setlen(&rel, rel.len - 5); + if (rel.len >= 6 && !strcmp(rel.buf + rel.len - 6, "/.git/")) + strbuf_setlen(&rel, rel.len - 6); else if (rel.len && rel.buf[rel.len - 1] == '/') strbuf_setlen(&rel, rel.len - 1); -- 2.56.0