+ setenv("GIT_DIR", ctx.repo->path, 1);
+
+ if (!ctx.qry.head) {
+ ctx.qry.head = xstrdup(find_default_branch(ctx.repo));
+ ctx.repo->defbranch = ctx.qry.head;
+ }
+
+ if (!ctx.qry.head) {
+ cgit_print_docstart(title, item);
+ cgit_print_pageheader(title, 0);
+ cgit_print_error("Repository seems to be empty");
+ cgit_print_docend();
+ return;
+ }
+
+ if (get_sha1(ctx.qry.head, sha1)) {
+ tmp = xstrdup(ctx.qry.head);
+ ctx.qry.head = ctx.repo->defbranch;
+ cgit_print_docstart(title, item);
+ cgit_print_pageheader(title, 0);
+ cgit_print_error(fmt("Invalid branch: %s", tmp));
+ cgit_print_docend();
+ return;
+ }