diff options
context:
space:
mode:
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Strip the trailing slash before matching `/.git`
Diffstat (limited to 'source')
-rw-r--r--source/scan-tree.c7
1 file changed, 5 insertions, 2 deletions
diff --git a/source/scan-tree.c b/source/scan-tree.c
index e568cf7..82f2cc0 100644
--- a/source/scan-tree.c
+++ b/source/scan-tree.c
@@ -115,10 +115,13 @@ static void add_repo(const char *base, struct strbuf *path)
else
strbuf_addstr(&rel, path->buf + strlen(base) + 1);
+ // Drop the trailing slash added above before testing for "/.git", since
+ // with it still attached the suffix never matches and every ordinary
+ // working tree is named "repo/.git" instead of "repo".
+ if (rel.len && rel.buf[rel.len - 1] == '/')
+ strbuf_setlen(&rel, rel.len - 1);
if (rel.len >= 5 && !strcmp(rel.buf + rel.len - 5, "/.git"))
strbuf_setlen(&rel, rel.len - 5);
- else if (rel.len && rel.buf[rel.len - 1] == '/')
- strbuf_setlen(&rel, rel.len - 1);
repo = cgit_add_repo(rel.buf);
if (ctx.cfg.enable_git_config) {