diff options
author | Ethan P <eth-p+git@hidden.email> | 2019-10-04 11:43:36 -0700 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2019-10-10 23:49:39 +0200 |
commit | 962abcef80c6b7b5dd2ae960b984a41716514470 (patch) | |
tree | 1240529683c3f90ac76e9f0bd20b881c01ecc271 | |
parent | 95f2e5bbb726534bd511885177db3a4b291b9af6 (diff) |
Update create.sh to quickly check for and update missing submodules
-rwxr-xr-x | assets/create.sh | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/assets/create.sh b/assets/create.sh index d95ffa31..0ebd1dcd 100755 --- a/assets/create.sh +++ b/assets/create.sh @@ -2,10 +2,42 @@ set -euo pipefail ASSET_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +REPO_DIR="$ASSET_DIR/.." # Ensure submodules are initialized. -git submodule init -git submodule update +function update_submodules() { + local submodule + local submodule_prompt=unspecified + local submodule_path + + { + while { read -r submodule && read -r submodule_path; } <&3; do + if ! [[ -d "${REPO_DIR}/.git/modules/${submodule}" ]] && [[ -d "${REPO_DIR}/${submodule_path}" ]]; then + if [[ "$submodule_prompt" = "unspecified" ]]; then + echo "One or more submodules were found to be uninitialized." + printf "Initialize and update them? [Y/n] " + read -r submodule_prompt + fi + + case "$submodule_prompt" in + y|yes|'') { + git -C "$REPO_DIR" submodule update --init "$submodule_path" + };; + n|no) { + return + };; + *) { + echo "Unknown answer. Not updating submodules." + };; + esac + fi + done + } 3< <(git config --file "${REPO_DIR}/.gitmodules" --null --get-regexp path | xargs -0 printf "%s\n" | sed 's/^submodule.//;s/.path$//') +} + +if [ -t 0 ]; then + update_submodules +fi # Always remove the local cache to avoid any confusion bat cache --clear |