From f3bcbe3aaa8d314b8dc5d10994a1e65fa36989d1 Mon Sep 17 00:00:00 2001 From: Philipe Fatio Date: Wed, 15 Feb 2023 15:09:37 +0100 Subject: [PATCH] Improve post-checkout hook This now also initializes a new submodule. --- git_template/hooks/post-checkout | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/git_template/hooks/post-checkout b/git_template/hooks/post-checkout index f9878c4..aafad1c 100755 --- a/git_template/hooks/post-checkout +++ b/git_template/hooks/post-checkout @@ -1,12 +1,10 @@ #!/usr/bin/env bash -git config --file .gitmodules --get-regexp path \ - | awk '{print $2}' \ - | while read -r submodule; do - diff="$(git diff -- "$submodule")" - if [[ "$diff" = *-dirty ]]; then +git submodule status \ + | while read -r sha submodule rest; do + if [[ "$(git diff -- "$submodule")" = *-dirty ]]; then echo "Submodule path '$submodule': dirty, not updating" - elif [[ -n "$diff" ]]; then + elif [[ "$sha" = [-+]* ]]; then git submodule update --init -- "$submodule" fi done