-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clang-format git hook pre-commit enforcement (#760)
* Added clang-format git pre-commit hook Signed-off-by: The MathWorks, Inc. <alchrist@mathworks.com> * Updated README * Updated help instructions to include '--style=file' * Added '--style=file' flag in actual pre-commit hook check * Updated README * Removed unnecessary code in pre-commit hook * Updated README Signed-off-by: The MathWorks, Inc. <alchrist@mathworks.com>
- Loading branch information
1 parent
8899851
commit 196dec7
Showing
5 changed files
with
67 additions
and
0 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,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Run clang-format pre-commit hook | ||
sh .githooks/pre-commit-clang-format-hook |
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,27 @@ | ||
#!/usr/bin/env bash | ||
|
||
printf "Running clang-format pre-commit hook... "; | ||
|
||
CLANG_FORMAT=$(which clang-format) | ||
|
||
if [ ! -x "$CLANG_FORMAT" ]; then | ||
printf "Error.\n"; | ||
printf "The clang-format cannot be found in your PATH. Please ensure clang-format is installed and on the PATH." | ||
exit 1 | ||
fi | ||
|
||
# Get clang-format output and store it for later checking | ||
clangformatoutput=$(git clang-format --style=file --diff --staged -q) | ||
|
||
# Redirect output to stderr | ||
exec 1>&2 | ||
|
||
if [ "$clangformatoutput" != "" ]; | ||
then | ||
printf "Error.\n"; | ||
printf "clang-format detected that changes have been made and are not properly formatted!\n" | ||
printf "Please run \`git clang-format --style=file --staged\`, re-stage modified files, and commit.\n" | ||
exit 1 | ||
else | ||
printf "Success.\n"; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"DisableFormat": true, | ||
"SortIncludes": false, | ||
} |