diff --git a/.github/hooks/pre-commit b/.github/hooks/pre-commit index 3226992868..d0a3a9e7fd 100755 --- a/.github/hooks/pre-commit +++ b/.github/hooks/pre-commit @@ -25,20 +25,23 @@ MOD_SUBMODULES=$(git diff --cached --name-only --ignore-submodules=none | grep - echo -e "Checking submodules ${grey}(pre-commit hook)${no_color} " -# If no modified submodules, exit with status code 0, else prompt the -# user and exit accordingly +# If no modified submodules, exit with status code 0, else remove them and continue if [[ -n "$MOD_SUBMODULES" ]]; then - echo "Submodules to be committed:" - echo " (use \"git reset HEAD ...\" to unstage)" - echo - + echo -e "${grey}Removing submodules from commit...${no_color}" for SUB in $MOD_SUBMODULES do - echo -e "\t${green}modified:\t$SUB${no_color}" + git reset --quiet HEAD "$SUB" + echo -e "\t${grey}removed:\t$SUB${no_color}" done echo - echo -e "${red}Aborting commit due to submodule update. Please unstage the submodule(s) and commit again.${no_color}" - exit 1 + echo -e "${grey}Submodules removed from commit, continuing...${no_color}" + + # If there are no changes to commit after removing submodules, abort to avoid an empty commit + if output=$(git status --porcelain) && [ -z "$output" ]; then + echo -e "nothing to commit, working tree clean" + exit 1 + fi + exit 0 else echo "No submodules in commit, continuing..." exit 0