diff options
Diffstat (limited to 'cgit.c')
-rw-r--r-- | cgit.c | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -421,6 +421,17 @@ char *find_default_branch(struct cgit_repo *repo) | |||
421 | return ref; | 421 | return ref; |
422 | } | 422 | } |
423 | 423 | ||
424 | static char *guess_defbranch(const char *repo_path) | ||
425 | { | ||
426 | const char *ref; | ||
427 | unsigned char sha1[20]; | ||
428 | |||
429 | ref = resolve_ref("HEAD", sha1, 0, NULL); | ||
430 | if (!ref || prefixcmp(ref, "refs/heads/")) | ||
431 | return "master"; | ||
432 | return xstrdup(ref + 11); | ||
433 | } | ||
434 | |||
424 | static int prepare_repo_cmd(struct cgit_context *ctx) | 435 | static int prepare_repo_cmd(struct cgit_context *ctx) |
425 | { | 436 | { |
426 | char *tmp; | 437 | char *tmp; |
@@ -447,10 +458,12 @@ static int prepare_repo_cmd(struct cgit_context *ctx) | |||
447 | } | 458 | } |
448 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); | 459 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); |
449 | 460 | ||
461 | if (!ctx->repo->defbranch) | ||
462 | ctx->repo->defbranch = guess_defbranch(ctx->repo->path); | ||
463 | |||
450 | if (!ctx->qry.head) { | 464 | if (!ctx->qry.head) { |
451 | ctx->qry.nohead = 1; | 465 | ctx->qry.nohead = 1; |
452 | ctx->qry.head = find_default_branch(ctx->repo); | 466 | ctx->qry.head = find_default_branch(ctx->repo); |
453 | ctx->repo->defbranch = ctx->qry.head; | ||
454 | } | 467 | } |
455 | 468 | ||
456 | if (!ctx->qry.head) { | 469 | if (!ctx->qry.head) { |