Created
September 20, 2015 21:07
-
-
Save idlemoor/fb4dd5cafd9e70af9a12 to your computer and use it in GitHub Desktop.
Synchronise branches in Ponce's repo for SBo-current
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 | |
csi=$'\x1b[' | |
colour_warning="${csi}1;35m" | |
colour_normal="${csi}0m" | |
#=============================================================================== | |
function sync_stable | |
{ | |
cd /SBo/14.1/slackbuilds | |
git clean -fxd | |
echo "" | |
echo "BRANCH SYNC: master" | |
git checkout -f master | |
git fetch --all | |
git remote prune origin | |
git remote prune github | |
git merge --ff-only origin/master || return 1 | |
git stash clear | |
echo "" | |
echo "BRANCH SYNC: 14.1" | |
git checkout 14.1 | |
git merge --ff-only origin/14.1 || return 1 | |
echo "" | |
echo "REBASE master-* & 14.1-*" | |
for b in $(git branch --list master-* 14.1-* | tr -d '*'); do | |
git checkout "$b" | |
git rebase 14.1 | |
[ $? != 0 ] && PS1='rebase fixup$ ' sh | |
done | |
echo "" | |
echo "BRANCH SYNC: master++" | |
git branch -D master++ | |
git checkout -b master++ master | |
for b in $(git branch --list master-* 14.1-* | tr -d '*'); do | |
bchnam="$(basename "$b")" | |
prgnam="$(echo "$bchnam" | sed 's:master-::')" | |
if [ -z "$(git rev-list master.."$b")" ]; then | |
echo -e "\n${colour_warning}==== Skipping $bchnam (empty branch) ====${colour_normal}\n" | |
else | |
echo "==== Merging $bchnam ====" | |
git merge --squash "$b" | |
[ $? != 0 ] && PS1='merge fixup$ ' sh | |
git stash save -u "$b" | |
fi | |
done | |
echo "==== Popping the stash ====" | |
i=0 | |
for stashname in $(git stash list | sed 's/:.*//') ; do | |
git stash pop -q || return 1 | |
i=$(( i + 1 )) | |
[ ${i: -1} = '0' ] && echo -n "$i ... " | |
done | |
echo -e "\n$i stashes applied." | |
echo "==== Committing ====" | |
git add --all . | |
git commit -m "$(date '+%Y%m%d'): Global branch merge of master and 14.1 fixes." || return 1 | |
echo "==== Pushing ====" | |
git push -f github master 14.1 master++ testing | |
return 0 | |
} | |
#=============================================================================== | |
function sync_current | |
{ | |
cd /SBo/current/slackbuilds | |
git clean -fxd | |
echo "" | |
echo "BRANCH SYNC: master" | |
git checkout -f master | |
git fetch --all | |
git remote prune origin | |
git remote prune github | |
git remote prune local14.1 | |
git merge --ff-only origin/master || return 1 | |
echo "" | |
echo "REBASE: removals" | |
git checkout removals | |
git rebase master | |
[ $? != 0 ] && PS1='rebase fixup$ ' sh | |
echo "" | |
echo "BRANCH SYNC: current" | |
git branch -D current | |
git checkout -b current -t origin/current | |
echo "" | |
echo "BRANCH SYNC: current++" | |
git stash clear | |
git branch -D current++ | |
git checkout -b current++ master | |
# local master-* branches | |
for b in $(git branch -r --list local14.1/master-* | tr -d '*'); do | |
bchnam="$(basename "$b")" | |
prgnam="$(echo "$bchnam" | sed 's:master-::')" | |
if [ -z "$(git rev-list master.."$b")" ]; then | |
echo -e "\n${colour_warning}==== Skipping $bchnam (empty branch) ====${colour_normal}\n" | |
elif [ -n "$(git branch -r --list origin/"$prgnam")" ]; then | |
echo -e "\n${colour_warning}==== Skipping $bchnam (branch origin/$prgnam exists) ====${colour_normal}\n" | |
else | |
echo "==== Merging $bchnam ====" | |
git merge --squash "$b" | |
[ $? != 0 ] && PS1='merge fixup$ ' sh | |
git stash save -u "$b" | |
fi | |
done | |
echo "==== Popping the stash ====" | |
i=0 | |
for stashname in $(git stash list | sed 's/:.*//') ; do | |
git stash pop -q || return 1 | |
i=$(( i + 1 )) | |
[ ${i: -1} = '0' ] && echo -n "$i ... " | |
done | |
echo -e "\n$i stashes applied." | |
echo "==== Committing ====" | |
git add --all . | |
git commit -m "$(date '+%Y%m%d'): Global merge of master fixes." || return 1 | |
# upstream current branches | |
echo "==== Merging current into current++ ====" | |
git merge --no-edit current || return 1 | |
[ $? != 0 ] && PS1='merge fixup$ ' sh | |
echo "==== Rebasing and dropping local branches ====" | |
for b in $(git branch | sed 's/^. //' | grep -v -E '^(master|current|current\+\+|removals)$'); do | |
git checkout "$b" | |
git rebase master | |
[ $? != 0 ] && PS1='rebase fixup$ ' sh | |
if git diff --quiet origin/"$b" 2>/dev/null; then | |
git checkout current++ | |
git branch -D "$b" | |
fi | |
done | |
git checkout current++ | |
# removals | |
echo "==== Merging removals into current++ ====" | |
git merge --no-edit removals || return 1 | |
[ $? != 0 ] && PS1='merge fixup$ ' sh | |
# merge local current branches | |
echo "==== Merging local branches into current++ ====" | |
for b in $(git branch | sed 's/^. //' | grep -v -E '^(master|current|current\+\+|removals)$'); do | |
git merge --no-edit "$b" | |
[ $? != 0 ] && PS1='rebase fixup$ ' sh | |
done | |
# push to github | |
echo "==== Pushing ====" | |
git push -f github master current current++ removals | |
return 0 | |
} | |
#=============================================================================== | |
repos=${1:-"both"} | |
if [ "$repos" = 'stable' ] || [ "$repos" = 'both' ]; then | |
echo "SYNCING REPO /SBo/14.1/slackbuilds" | |
sync_stable | |
if [ $? != 0 ]; then | |
echo -e "\n${colour_warning}synculator.sh: Error: sync_stable failed${colour_normal}\n" | |
exit 1 | |
fi | |
echo "" | |
echo "" | |
echo "" | |
fi | |
if [ "$repos" = 'current' ] || [ "$repos" = 'both' ]; then | |
echo "SYNCING REPO /SBo/current/slackbuilds" | |
sync_current | |
if [ $? != 0 ]; then | |
echo -e "\n${colour_warning}synculator.sh: Error: sync_current failed${colour_normal}\n" | |
exit 1 | |
fi | |
echo "" | |
echo "" | |
echo "" | |
fi | |
#=============================================================================== | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment