Last active
March 29, 2020 18:25
-
-
Save webkod3r/bbbec0813d594c6a3786e5e8f8e4c15d to your computer and use it in GitHub Desktop.
write current git hash to file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!function_exists('get_commit_hash')) { | |
/** | |
* Checks to see if we have a .commit_hash file or .git repo and return the hash if we do. | |
* | |
* @return null|string | |
*/ | |
function get_commit_hash() | |
{ | |
$commitHash = base_path('.commit_hash'); | |
if (file_exists($commitHash)) { | |
// See if we have the .commit_hash file | |
return trim(exec(sprintf('cat %s', $commitHash))); | |
} elseif (is_dir(base_path('.git'))) { | |
// Do we have a .git repo? | |
return trim(exec('git log --pretty="%h" -n1 HEAD')); | |
} else { | |
// ¯\_(ツ)_/¯ | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment