Skip to content

Commit

Permalink
Handle a detatched head state when looking for git hash
Browse files Browse the repository at this point in the history
  • Loading branch information
bakert committed Nov 26, 2024
1 parent bea7a68 commit f06590a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions gatherling/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@
$CONFIG['GIT_HASH'] = null;
if (file_exists('../.git/HEAD')) {
$branch = trim(substr(file_get_contents('../.git/HEAD'), 5));
if ($hash = file_get_contents(sprintf('../.git/%s', $branch))) {
$CONFIG['GIT_HASH'] = $hash;
$hash_file = sprintf('../.git/%s', $branch);
if (file_exists($hash_file)) {
// On a branch, get the hash
$CONFIG['GIT_HASH'] = file_get_contents($hash_file);
} else {
// On a detached HEAD, just use the branch name
$CONFIG['GIT_HASH'] = $branch;
}
}

Expand Down

0 comments on commit f06590a

Please sign in to comment.