Last active
March 25, 2019 18:35
-
-
Save poldz123/4f2e41d9ba677eea2fee26d82d10c27d 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 | |
update_repo() { | |
echo ============================ | |
echo ========= NEXT: $1 ========= | |
echo ============================ | |
echo | |
rm -Rf .git/refs/original | |
git checkout dev | |
# git fetch origin dev | |
git fetch reference $2 | |
git fetch reference $3 | |
git filter-branch -f --prune-empty --subdirectory-filter $1 reference/$2 reference/$3 -- --all | |
DEV_ORIGIN_REV_HEAD=$(git rev-parse --short origin/dev~1) | |
DEV_LOCAL_REV_HEAD=$(git rev-parse --short reference/$2) | |
if [ "$DEV_ORIGIN_REV_HEAD" != "$DEV_LOCAL_REV_HEAD" ]; then | |
git fetch origin/dev | |
git reset reference/$2 --hard | |
git cherry-pick $(git rev-parse --short origin/dev) | |
git push -f | |
else | |
echo ============================== | |
echo PROJECT DEV ALREADY UPDATED | |
echo ============================== | |
fi | |
PROD_LOCAL_REV_HEAD_COUNT=$(git rev-list reference/$3..origin/prod --count) | |
if [ "$PROD_LOCAL_REV_HEAD_COUNT" -gt "0" ]; then | |
git checkout prod | |
git branch --set-upstream-to=origin/prod prod | |
git reset reference/$3 --hard | |
git push -f | |
git checkout test | |
git branch --set-upstream-to=origin/test test | |
git reset reference/$3 --hard | |
git push -f | |
git checkout dev | |
else | |
echo ============================== | |
echo PROJECT PROD ALREADY UPDATED | |
echo ============================== | |
echo ============================== | |
echo PROJECT TEST ALREADY UPDATED | |
echo ============================== | |
fi | |
echo | |
} | |
cd core | |
update_repo core dev prod | |
cd ../ | |
cd ms-billing | |
update_repo microservices/billing dev prod | |
cd ../ | |
cd ms-integration | |
update_repo microservices/integration dev prod | |
cd ../ | |
cd ms-notification | |
update_repo microservices/notification dev prod | |
cd ../ | |
cd ms-prediction | |
update_repo microservices/prediction dev prod | |
cd ../ | |
cd ms-report-generator | |
update_repo microservices/report_generator dev prod | |
cd ../ | |
cd ms-stats-log | |
update_repo microservices/stats_log dev prod | |
cd ../ | |
cd util-deployment | |
update_repo deployment dev prod | |
cd ../ | |
cd util-giatec | |
update_repo giatecutilities dev prod | |
cd ../ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run using:
sudo bash -c "$(curl -L https://gist.githubusercontent.com/poldz123/4f2e41d9ba677eea2fee26d82d10c27d/raw/e48d48f6b5897a2dde5b1b89d61bfc268e8482b7/git-filter-and-update.sh)"