Created
August 12, 2018 20:08
-
-
Save blaggacao/5b468e9c0efe80df5afc0b81ee34d502 to your computer and use it in GitHub Desktop.
Backport patches from master
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 | |
folders=("vendor/odoo/cc/.git") | |
devbranch="master" | |
branches=("11.0") | |
owndev="dev" | |
prefix="remotes/" | |
canidate_branches="remotes/${owndev}/${devbranch}-" | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
NC='\033[0m' # No Color | |
for folder in "${folders[@]}"; do | |
echo -e "\nBackporting patches in ${folder}\n" | |
gitcmd="git --git-dir ${folder}" | |
HEAD=$(eval "${gitcmd} rev-parse --abbrev-ref HEAD") | |
candidates=($(eval "$gitcmd branch -a | grep '${canidate_branches}'")) | |
for branch in "${branches[@]}"; do | |
for candidate in "${candidates[@]}"; do | |
candidate=${candidate#"$prefix"} | |
echo -e "\nBackporting ${candidate} to ${branch}\n" | |
eval "${gitcmd} checkout ${branch}" | |
# Create appropriate name for target branch | |
newbranch=${branch}${candidate#"$owndev/$devbranch"} | |
eval "${gitcmd} checkout -b ${newbranch}" | |
commits=($(eval "${gitcmd} cherry ${owndev}/${devbranch} ${candidate}" | sed 's/^+ //')) | |
if eval "${gitcmd} cherry-pick" "${commits[@]}"; then | |
echo -e "\nPushing ${newbranch} to ${owndev}" | |
eval "${gitcmd} push ${owndev}" | |
else | |
exit 1 | |
fi | |
done | |
done | |
eval "${gitcmd} checkout ${HEAD}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment