Last active
August 29, 2015 14:07
-
-
Save bigfive/68719b29456213e5d244 to your computer and use it in GitHub Desktop.
Push release/hotfix branch to origin remote. Checks if any orphan commits on target
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
function fpushrel () { | |
# Assertion: At least one arg | |
if [ -z $1 ]; then | |
echo "ERROR: Please provide a branch to push (eg staging/production)"; return | |
fi | |
# Assertion: No uncommited changes | |
if ! [ $(git status -s | wc -l) -eq 0 ]; then | |
echo "ERROR: You have changes that have not been committed"; return | |
fi | |
# Assertion: Pushing a release or hotfix branch | |
LOCALREF=$(git rev-parse HEAD) | |
if [ $(git show-ref --heads | grep $LOCALREF | grep 'release\|hotfix' | wc -l) -eq 0 ]; then | |
echo "ERROR: You are not pushing a release or hotfix branch"; return | |
fi | |
echo "Force pushing $LOCALREF to $1" | |
ORIGINREF=$(git ls-remote origin $1 | cut -f1) | |
# Assertion: Destination branch exists on origin | |
if [ $(echo $ORIGINREF | wc -l) -eq 0 ]; then | |
echo "ERROR: $1 does not exist on origin"; return | |
fi | |
# Assertion: Destination branch doesnt have orphan commits | |
if [ $(git branch --remote --contains $ORIGINREF | wc -l) -eq 1 ]; then | |
echo "ERROR: There are commits on $1 that are not in any other origin branch (ie: $ORIGINREF). CLEAN THAT SHIT UP!"; return | |
fi | |
git push --force origin $LOCALREF:$1 &>/dev/null || {echo "ERROR: Cannot force push to origin/$1"; return} | |
echo "Complete" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment