Skip to content

Instantly share code, notes, and snippets.

@octavian-nita
Last active March 24, 2020 11:29
Show Gist options
  • Save octavian-nita/2a6dec338efa2ff25ce9b7ac551cda09 to your computer and use it in GitHub Desktop.
Save octavian-nita/2a6dec338efa2ff25ce9b7ac551cda09 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Consider writing robust bash shell scripts ( http://mywiki.wooledge.org/ ;)
set -o nounset
# ----------------------
# Command line arguments
# ----------------------
#[[ $# -ge 1 ]] || { printf "\nusage: `basename ${BASH_SOURCE}` <repo-name>\n\n" 1>&2; return 1; }
# -------------
# Configuration
# -------------
declare -a REPOS=`ls -d */ | cut -d/ -f1 | sort`
declare -r CWD=`pwd`
declare -r DTS=`date +%Y-%m-%d-%H-%M-%S`
declare -r LOG=`basename $0`-${DTS}.log
declare -r DEFAULT_BRANCH="develop"
declare -r -A WORKING_BRANCHES=(
["some-module"]="env/DEV"
)
# Alternatively, for bash pre-version 4 (i.e. no hashes/maps)
#working_branch() {
# case $1 in
# "mod01" | \
# "mod02")
# echo "env/DEV"
# ;;
# "mod03")
# echo "feature/some-feat"
# ;;
# *)
# echo "develop"
# ;;
# esac
#}
## ----
## Main
## ----
echo -e "\n--- ${DTS}\n" 2>&1 | tee -a "$CWD/$LOG"
for M in ${REPOS[*]}; do
# Execute loop body only for Git repos!
[[ -d "${CWD}/${M}" && -d "${CWD}/${M}/.git" ]] || continue
echo -e "\nRepository in ${M}..." 2>&1 | tee -a "$CWD/$LOG"
cd "${CWD}/${M}"
#: CUSTOM ( do use 2>&1 | tee -a "$CWD/$LOG" )
git fetch --all && \
git checkout ${WORKING_BRANCHES["${M}"]:-${DEFAULT_BRANCH}} && \
#git checkout `working_branch "${M}"` && \
git pull 2>&1 | tee -a "$CWD/$LOG"
#/ CUSTOM
cd $CWD
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment