-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OXDEV-7675: Add pre-commit hook to execute static analysis before commit
- Loading branch information
1 parent
8febff8
commit d3ffe27
Showing
2 changed files
with
31 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
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,29 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
function setup_git_hooks() | ||
{ | ||
echo "Initialising git hooks..." | ||
|
||
MODULE_PATH=$(git rev-parse --show-toplevel) | ||
PRE_COMMIT_HOOK_FILE_PATH=$MODULE_PATH/.git/hooks/pre-commit | ||
|
||
echo "Add hook command to pre-commit file $PRE_COMMIT_HOOK_FILE_PATH" | ||
|
||
if ! [ -f "${PRE_COMMIT_HOOK_FILE_PATH}" ];then | ||
echo $'#!/bin/bash\n' >> $PRE_COMMIT_HOOK_FILE_PATH | ||
fi | ||
|
||
COMPOSER_STATIC_COMMAND="docker compose exec -T --workdir $MODULE_PATH php composer static" | ||
|
||
if grep -q "$COMPOSER_STATIC_COMMAND" "$PRE_COMMIT_HOOK_FILE_PATH"; then | ||
echo "Command has already been added" | ||
return | ||
fi | ||
|
||
echo "$COMPOSER_STATIC_COMMAND" >> $PRE_COMMIT_HOOK_FILE_PATH | ||
chmod +x $PRE_COMMIT_HOOK_FILE_PATH | ||
} | ||
|
||
setup_git_hooks |