Last active
February 28, 2019 14:02
-
-
Save Fusselwurm/2f553439f4fdc861d8c047f2d29c618a to your computer and use it in GitHub Desktop.
rebase loop for projects with high push frequency and rebase-always policy
This file contains hidden or 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 | |
projectdir=$(realpath $1) | |
frequency=$2 | |
if [[ $frequency == "" ]]; then $frequency=30; fi | |
if [[ ! -d $projectdir ]]; then echo "first param must be a directory"; exit 2; fi | |
if [[ ! -d $projectdir/.git ]]; then echo "not a git project"; exit 4; fi | |
pushd $projectdir | |
branchname=$(git status -buno --porcelain | sed 's/## //'); | |
if [[ $branchname == "master" ]]; then | |
echo "must not force-push master!" | |
popd | |
exit 1 | |
fi | |
while [[ true ]]; do | |
git fetch | |
$diff=$(git diff origin/$branchname) | |
if [[ $? != 0]]; then | |
echo "error comparing to remote!" | |
popd | |
exit 8 | |
fi | |
if [[ $diff != "" ]]; then | |
git rebase origin/master | |
git push -f origin $branchname | |
fi | |
sleep $frequency | |
done | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment