Created
February 24, 2014 17:03
-
-
Save arodland/9192291 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# display commands and their arguments as they are executed | |
set -x | |
WEEK=$(date +%-V) | |
if [ $[ $WEEK % 2 ] -ne 1 ]; then | |
exit 0 | |
fi | |
cd /home/arodland/code/shutterstock-mason.clean | |
# make sure we're up to date to begin with | |
git remote update --prune | |
echo Removing prod-ready branches from origin | |
git branch -r | grep "\<prod-ready" | sed 's/\s*origin\///' | |
git branch -r | grep "\<prod-ready" | sed 's/\s*origin\//:/' | xargs -n 50 --no-run-if-empty git push origin | |
git remote update --prune | |
for branch_name in staging qa integration | |
do | |
echo Removing $branch_name-ready branches from origin with now invalid commits in them | |
# show and then delete '$env-ready' branches so there is no premerged content with now invalid refs for that env | |
git branch -r | grep "\<$branch_name-ready" | sed 's/\s*origin\///' | |
git branch -r | grep "\<$branch_name-ready" | sed 's/\s*origin\//:/' | xargs -n 50 --no-run-if-empty git push origin | |
# make sure we're up to date | |
git remote update --prune | |
origin_master=$(git rev-parse origin/master) | |
echo "The following branches will be un-merged from $branch_name:" | |
/usr/bin/comm -23 <(git branch -r --merged origin/$branch_name | sort) <(git branch -r --merged $origin_master | sort) | |
echo "Resetting $branch_name back to the current state of production ($origin_master)" | |
git push origin +$origin_master:$branch_name | |
git remote update --prune | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment