Skip to content

Instantly share code, notes, and snippets.

@m8rge
Created November 15, 2013 05:15
Show Gist options
  • Save m8rge/7479452 to your computer and use it in GitHub Desktop.
Save m8rge/7479452 to your computer and use it in GitHub Desktop.
Подтягивает последний тег до последнего коммита и пушит его в мастер.
#!/usr/bin/env php
<?php namespace App;
/**
* @param string $command
* @return string[]
*/
function exec($command)
{
echo "> $command\n";
ob_start();
passthru($command, $return_var);
if ($return_var) {
exit($return_var);
}
$output = ob_get_flush();
// add missing new line
if (!empty($output) && substr($output, -1, 1) !== "\n") {
echo "\n";
}
$output = rtrim($output, PHP_EOL);
return empty($output) ? array() : explode(PHP_EOL, $output);
}
/**
* @param string $text
* @param int $returnCode
*/
function writeError($text, $returnCode = 1)
{
file_put_contents('php://stderr', $text . "\n", FILE_APPEND);
exit($returnCode);
}
$commits = exec('git log -5 --pretty=format:"%H"');
$lastCommit = array_shift($commits);
$tag = exec("git tag --contains=$lastCommit");
if (!empty($tag)) {
writeError("Last commit already contains tag: " . reset($tag));
}
foreach ($commits as $commit) {
$tag = exec("git tag --contains=$commit");
$tag = reset($tag);
if (!empty($tag)) {
exec("git tag -f \"$tag\"");
exec("git push origin -f \"$tag\"");
exit(0);
}
}
writeError("No tags were found in last 5 commits");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment