#!/bin/bash ################################################## #################### IMPORTANT ################### # NEVER try to add dangerous functionalities like: # - checkout -b # - commit # - push # - merge # which updates/writes to the repositories. # Any update/wtire to repositories # MUST be MANUALLY reviewed by developer, # prior to getting applied, LINE BY LINE. # #################### IMPORTANT ################### # Also all the branches on each repository # MUST be created from the # - STORY on JIRA of the current feature/bug, # for the code review to be created automatically. # ################################################## LINE_SEPARATOR="--------------------------------------------------------------------------------" ERROR_CHECKOUT_FAIL=1 repositories=( "." "common" "config" "plugins" "resources" "scripts" ) function help() { echo "usage:" echo "$0 " echo " pull" echo " pullsync " echo " sync " echo " status" } function pull() { for repo in "${repositories[@]}"; do echo " $LINE_SEPARATOR : $repo pull" echo "git pull $repo" git -C "$repo" pull done } function checkout() { if [[ "$1" != "" ]]; then echo " $LINE_SEPARATOR : checkout $1" git checkout "$1" if (( $? )); then echo "ERROR_CHECKOUT_FAIL" exit $ERROR_CHECKOUT_FAIL fi fi local _branch="$(git branch --show-current)" echo " $LINE_SEPARATOR : checkout $_branch" for repo in "${repositories[@]}"; do echo " $LINE_SEPARATOR : $repo checkout" git -C "$repo" checkout "$_branch" if (( $? )); then echo " +++++ ERROR check out to staging" git -C "$repo" checkout staging fi done } function status() { # git status for repo in "${repositories[@]}"; do echo " $LINE_SEPARATOR : $repo status" git -C "$repo" status done } case $1 in pull) pull ;; sync) checkout "$2" ;; pullsync) pull checkout "$2" ;; status) status ;; *) help ;; esac