#!/usr/bin/env zsh CMDNAME=$0 SUBMODULES=("Apps/Directus CMS") exit_with_msg() { local msg=$1 code=$2 echo $msg >&2 exit $code } is_clean_git_workspace() { git diff-index --quiet HEAD } commit_submodule_changes() { # REQUIRES submodule to be a valid variable. git add . git commit -m "chore(${submodule:t}): Pull remote changes" } update_submodules() { local submodule for submodule in ${SUBMODULES}; do [[ ! -d $submodule ]] && continue echo ">> Updating submodule ${submodule}" pushd -q $submodule git pull --rebase popd -q is_clean_git_workspace && continue commit_submodule_changes done } show_help() { cat <<- HELPMSG $CMDNAME [command] Task manager for HDA - CMS monorepo. Commands start: Run daily chores like pulling upstream changes and updating submodules. HELPMSG } main() { local CMD=$1 case $CMD in start) is_clean_git_workspace || exit_with_msg "Please clean workspace before running command" 10 update_submodules ;; *) show_help ;; esac } main $*