mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-01-19 08:57:55 +00:00
allow using codeberg pages without having a master branch
use HEAD instad
This commit is contained in:
parent
330daaab5b
commit
8a932d68b1
1 changed files with 4 additions and 4 deletions
|
@ -54,7 +54,7 @@ if (substr($git_root, 0, strlen($git_prefix)) !== $git_prefix) {
|
||||||
}
|
}
|
||||||
|
|
||||||
# If this is a folder, we explicitly redirect to folder URL, otherwise browsers will construct invalid relative links:
|
# If this is a folder, we explicitly redirect to folder URL, otherwise browsers will construct invalid relative links:
|
||||||
$command = "sh -c \"cd '$git_root' && /usr/bin/git ls-tree 'master:$file_url' > /dev/null\"";
|
$command = "sh -c \"cd '$git_root' && /usr/bin/git ls-tree 'HEAD:$file_url' > /dev/null\"";
|
||||||
exec($command, $output, $retval);
|
exec($command, $output, $retval);
|
||||||
if ($retval === 0) {
|
if ($retval === 0) {
|
||||||
if (substr($request_url, -1) !== "/") {
|
if (substr($request_url, -1) !== "/") {
|
||||||
|
@ -101,17 +101,17 @@ if (array_key_exists($ext, $mime_types)) {
|
||||||
|
|
||||||
## We are executing command twice (first for send_response-checking, then for actual raw output to stream),
|
## We are executing command twice (first for send_response-checking, then for actual raw output to stream),
|
||||||
## which seems wasteful, but it seems exec+echo cannot do raw binary output? Is this true?
|
## which seems wasteful, but it seems exec+echo cannot do raw binary output? Is this true?
|
||||||
$command = "sh -c \"cd '$git_root' && /usr/bin/git show 'master:$file_url'\"";
|
$command = "sh -c \"cd '$git_root' && /usr/bin/git show 'HEAD:$file_url'\"";
|
||||||
exec($command . " > /dev/null", $output, $retval);
|
exec($command . " > /dev/null", $output, $retval);
|
||||||
if ($retval != 0) {
|
if ($retval != 0) {
|
||||||
# Try adding '.html' suffix, if this does not work either, report error
|
# Try adding '.html' suffix, if this does not work either, report error
|
||||||
$command = "sh -c \"cd '$git_root' && /usr/bin/git show 'master:$file_url.html'\"";
|
$command = "sh -c \"cd '$git_root' && /usr/bin/git show 'HEAD:$file_url.html'\"";
|
||||||
exec($command . " > /dev/null", $output, $retval);
|
exec($command . " > /dev/null", $output, $retval);
|
||||||
header("Content-Type: text/html");
|
header("Content-Type: text/html");
|
||||||
if ($retval != 0) {
|
if ($retval != 0) {
|
||||||
# Render user-provided 404.html if exists, generic 404 message if not:
|
# Render user-provided 404.html if exists, generic 404 message if not:
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
$command = "sh -c \"cd '$git_root' && /usr/bin/git show 'master:404.html'\"";
|
$command = "sh -c \"cd '$git_root' && /usr/bin/git show 'HEAD:404.html'\"";
|
||||||
exec($command . " > /dev/null", $output, $retval);
|
exec($command . " > /dev/null", $output, $retval);
|
||||||
if ($retval != 0)
|
if ($retval != 0)
|
||||||
send_response(404 , "no such file in repo: '" . htmlspecialchars($file_url) . "'");
|
send_response(404 , "no such file in repo: '" . htmlspecialchars($file_url) . "'");
|
||||||
|
|
Loading…
Reference in a new issue