Skip to content

Instantly share code, notes, and snippets.

@joaorobertopb
Last active June 15, 2018 12:14
Show Gist options
  • Save joaorobertopb/e48979f1bbfa6c3afd89d20449970f27 to your computer and use it in GitHub Desktop.
Save joaorobertopb/e48979f1bbfa6c3afd89d20449970f27 to your computer and use it in GitHub Desktop.
Get latest git tag version with PHP.
<?php
if (! function_exists('git_version')) {
/**
* Get latest git tag version.
*
* @return string
*/
function git_version()
{
$gitCommand = 'git describe --tags $(git rev-list --tags --max-count=1)';
if (class_exists('Symfony\Component\Process\Process')) {
$process = (new Symfony\Component\Process\Process($gitCommand))->run();
return trim($process->getOutput());
}
return trim(exec($gitCommand));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment