resolve_ref_unsafe() can't be told to be namespace aware,
so we need to use our helper function for resolving refs,
which prepends the namespace before resolving.

As an additional check, if the ref points outside the namespace,
then it will use the default "master".

upload-pack is not so tolerant, so try to avoid having such broken repos.

Signed-off-by: Richard Maw <[email protected]>
---
 cgit.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/cgit.c b/cgit.c
index 5d55187..7b499ea 100644
--- a/cgit.c
+++ b/cgit.c
@@ -472,13 +472,18 @@ static char *find_default_branch(struct cgit_repo *repo)
 
 static char *guess_defbranch(void)
 {
-       const char *ref;
+       char *ref, *ret;
        unsigned char sha1[20];
 
-       ref = resolve_ref_unsafe("HEAD", 0, sha1, NULL);
-       if (!ref || !starts_with(ref, "refs/heads/"))
-               return xstrdup("master");
-       return xstrdup(ref + 11);
+       ref = cgit_namespaced_resolve_ref("HEAD", 0, sha1, NULL);
+
+       if (!ref || !strip_namespace(ref) || !starts_with(strip_namespace(ref), 
"refs/heads/"))
+               ret = xstrdup("master");
+       else
+               ret = xstrdup(strip_namespace(ref) + 11);
+
+       free(ref);
+       return ret;
 }
 /* The caller must free filename and ref after calling this. */
 static inline void parse_readme(const char *readme, char **filename, char 
**ref, struct cgit_repo *repo)
-- 
2.9.0

_______________________________________________
CGit mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/cgit

Reply via email to