From 63dd6724677c50e2119ccc97a3a043a6829d920f Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Mon, 26 Oct 2026 13:04:24 +0000 Subject: [PATCH] - Added a GIT lib to query directly from it's folder --- meta/definitions/software.php | 13 +------------ src/Git.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 src/Git.php diff --git a/meta/definitions/software.php b/meta/definitions/software.php index 48c2278..b6495a7 100644 --- a/meta/definitions/software.php +++ b/meta/definitions/software.php @@ -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')), diff --git a/src/Git.php b/src/Git.php new file mode 100644 index 0000000..240d7a4 --- /dev/null +++ b/src/Git.php @@ -0,0 +1,33 @@ + ! 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 ""; + } +} \ No newline at end of file