Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63dd672467 |
No files matched your search
@@ -80,18 +80,7 @@ return [
|
||||
return uniqid("debug_");
|
||||
}
|
||||
|
||||
$gitdir = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . ".git" . DIRECTORY_SEPARATOR;
|
||||
|
||||
if ( file_exists($gitdir . "HEAD") ) {
|
||||
if (false !== ($currentBranch = file_get_contents($gitdir . "HEAD"))) {
|
||||
$file = explode(": ", $currentBranch)[1];
|
||||
$path = $gitdir . str_replace("/", DIRECTORY_SEPARATOR, trim($file, " \t\n\r"));
|
||||
|
||||
return file_exists($path) ? trim(file_get_contents($path), " \t\n\r") : null;
|
||||
}
|
||||
}
|
||||
|
||||
return "gitless-project";
|
||||
return \Lean\Git::getLatestCommit(getenv("PROJECT_PATH"));
|
||||
},
|
||||
|
||||
Kash\CacheInvalidator::class => create(Kash\CacheInvalidator::class)->constructor(getenv('CACHE_PATH')."/version.cache", (bool) getenv('DEBUG')),
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Lean;
|
||||
|
||||
class Git
|
||||
{
|
||||
public static function projectVersion(string $projectPath) : string
|
||||
{
|
||||
$gitdir = implode(DIRECTORY_SEPARATOR, [ $projectPath, ".git", "refs", "tags" ]);
|
||||
|
||||
if ( file_exists($gitdir) ) {
|
||||
$tags = array_filter(scandir($gitdir, SCANDIR_SORT_DESCENDING), fn($e) => ! str_starts_with($e, '.'));
|
||||
}
|
||||
|
||||
return array_shift($tags);
|
||||
}
|
||||
|
||||
public static function getLatestCommit(string $projectPath) : string
|
||||
{
|
||||
$gitdir = implode(DIRECTORY_SEPARATOR, [ getenv("PROJECT_PATH"), ".git", "" ]);
|
||||
|
||||
if ( file_exists($gitdir . "HEAD") ) {
|
||||
if (false !== ($currentBranch = file_get_contents($gitdir . "HEAD"))) {
|
||||
$file = explode(": ", $currentBranch)[1];
|
||||
$path = $gitdir . str_replace("/", DIRECTORY_SEPARATOR, trim($file, " \t\n\r"));
|
||||
|
||||
return file_exists($path) ? trim(file_get_contents($path), " \t\n\r") : "";
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user