Merge pull request #1976 from phl0/moreDebug

Display branch info on unpushed branches correctly
这个提交包含在:
Peter Goodhall 2023-02-02 16:36:05 +00:00 提交者 GitHub
当前提交 48e43eecc8
找不到此签名对应的密钥
GPG 密钥 ID: 4AEE18F83AFDEB23

查看文件

@ -161,19 +161,23 @@
<?php if (file_exists('.git')) { ?> <?php if (file_exists('.git')) { ?>
<?php <?php
$commitHash = trim(exec('git log --pretty="%H" -n1 HEAD')); $commitHash = trim(exec('git log --pretty="%H" -n1 HEAD'));
$branch = '';
$remote = '';
$owner = '';
// only proceed here if git can actually be executed // only proceed here if git can actually be executed
if ($commitHash != "") { if ($commitHash != "") {
$commitDate = trim(exec('git log --pretty="%ci" -n1 HEAD')); $commitDate = trim(exec('git log --pretty="%ci" -n1 HEAD'));
$line = trim(exec('git log -n 1 --pretty=%D HEAD')); $line = trim(exec('git log -n 1 --pretty=%D HEAD'));
$pieces = explode(', ', $line); $pieces = explode(', ', $line);
$remote = substr($pieces[1], 0, strpos($pieces[1], '/')); if (isset($pieces[1])) {
$branch = substr($pieces[1], strpos($pieces[1], '/')+1); $remote = substr($pieces[1], 0, strpos($pieces[1], '/'));
$url = trim(exec('git remote get-url '.$remote)); $branch = substr($pieces[1], strpos($pieces[1], '/')+1);
$owner = ''; $url = trim(exec('git remote get-url '.$remote));
if (strpos($url, 'https://github.com') !== false) { if (strpos($url, 'https://github.com') !== false) {
$owner = preg_replace('/https:\/\/github\.com\/(\w+)\/Cloudlog\.git/', '$1', $url); $owner = preg_replace('/https:\/\/github\.com\/(\w+)\/Cloudlog\.git/', '$1', $url);
} else if (strpos($url, 'git@github.com') !== false) { } else if (strpos($url, 'git@github.com') !== false) {
$owner = preg_replace('/git@github\.com:(\w+)\/Cloudlog\.git/', '$1', $url); $owner = preg_replace('/git@github\.com:(\w+)\/Cloudlog\.git/', '$1', $url);
}
} }
$tag = trim(exec('git describe --tags '.$commitHash)); $tag = trim(exec('git describe --tags '.$commitHash));
} }