dotfiles/bin/git-publish

31 lines
816 B
Plaintext
Raw Normal View History

2019-10-22 09:50:54 +00:00
#!/usr/bin/env php
<?php
2020-01-15 08:14:44 +00:00
/**
* Usage: git publish <remote-branch-name>
*
* Open the pull request page for <branch>, or the current branch if not
* specified. Lands on the new pull request page when no PR exists yet.
* The local branch must be tracking the remote branch.
*
* Use the `BRANCH_PREFIX` environment variable to add a prefix to the
* remote branch name.
*/
$branchesToIgnore = ['develop', 'master', 'staging', 'production'];
$localBranch = exec('git rev-parse --abbrev-ref HEAD');
2019-10-22 09:50:54 +00:00
if (in_array($localBranch, $branchesToIgnore)) {
print "Currently on ${localBranch}. Aborting.";
exit(1);
}
if ($prefix = getenv('BRANCH_PREFIX')) {
$remoteBranch = "{$prefix}-{$localBranch}";
} else {
$remoteBranch = $localBranch;
2019-10-22 09:50:54 +00:00
}
exec("git push -u origin ${localBranch}:${remoteBranch}");