-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Added pre-commit hook to handle submodules (#8302)
refs #8235 Usage: - for existing development setups: `grunt symlink` (will create the pre-commit symlink) - for fresh development setups: `npm run init` (symlinking happens as part of the typical set up) - ✨ Added pre-commit hook to handle submodules - Checks to see if there are any submodules about to be committed - Output matches closely to `git st` to make it easy to read - Requires interaction from the committer to accept that this really should be committed - ✨ Use grunt symlink to register githooks - Grunt symlink will make a link to the pre-commit hook - It ONLY does this if there isn't already a pre-commit hook, so won't overwrite anything - It does this as part of npm run init, not grunt init, because a release repo would NEVER want this - This is a dev tool, that configures the repo for development
- Loading branch information
1 parent
8dae1cd
commit e9a5370
Showing
5 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
# Modified from https://github.com/chaitanyagupta/gitutils | ||
|
||
green='\033[0;32m' | ||
no_color='\033[0m' | ||
grey='\033[0;90m' | ||
|
||
|
||
ROOT_DIR=$(git rev-parse --show-cdup) | ||
SUBMODULES=$(grep path ${ROOT_DIR}.gitmodules | sed 's/^.*path = //') | ||
MOD_SUBMODULES=$(git diff --cached --name-only | grep -F "$SUBMODULES") | ||
|
||
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 [[ -n "$MOD_SUBMODULES" ]]; then | ||
echo "Submodules to be committed:" | ||
echo " (use \"git reset HEAD <file>...\" to unstage)" | ||
echo | ||
|
||
for SUB in $MOD_SUBMODULES | ||
do | ||
echo -e "\t${green}modified:\t$SUB${no_color}" | ||
done | ||
echo | ||
echo -n -e "Continue with commit? ${grey}(N|y)${no_color} " | ||
read -n 1 reply </dev/tty | ||
echo | ||
if [[ "$reply" == "y" || "$reply" == "Y" ]]; then | ||
echo "Permitting submodules to be committed..." | ||
exit 0 | ||
else | ||
echo "Aborting commit due to submodule update." | ||
exit 1 | ||
fi | ||
else | ||
echo "No submodules in commit, continuing..." | ||
exit 0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters