Skip to content

Instantly share code, notes, and snippets.

@poldz123
Last active March 25, 2019 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poldz123/4f2e41d9ba677eea2fee26d82d10c27d to your computer and use it in GitHub Desktop.
Save poldz123/4f2e41d9ba677eea2fee26d82d10c27d to your computer and use it in GitHub Desktop.
#!/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 ../
@poldz123
Copy link
Author

poldz123 commented Mar 4, 2019

Run using:
sudo bash -c "$(curl -L https://gist.githubusercontent.com/poldz123/4f2e41d9ba677eea2fee26d82d10c27d/raw/e48d48f6b5897a2dde5b1b89d61bfc268e8482b7/git-filter-and-update.sh)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment