Git
Integrate codee
with git
to reject the commit if critical
issues are found in the code.
Prerequisites
Ensure you have:
codee
installed and accessible from your command line.jq
package installed in your system.
Optional tools
pre-commit
package manager installed in your system.
This is not an actual requirement but a simpler and more robust approach to git hooks.
Configuration
This guide is configured to use the MATMUL
Fortran example
of the codee-demos
repository.
Create a file named .pre-commit-config.yaml
:
repos:
- repo: local
hooks:
- id: codee-analyzer
name: Codee Analyzer
entry: ./scripts/codee-checks.sh
language: system
types: [file]
files: '\.(f|F|f90|F90|f95|F95)$'
It is also necessary to create a script where we will include the checkers that are considered critical for the current project:
mkdir -p scripts/
Then, create a codee-checks.sh
file:
touch scripts/codee-checks.sh
The content of the script should be something similar to this:
#!/bin/bash
# A collection of check you may consider relevant
CHECKS="PWR072,PWR079,PWR007,PWR008,PWR068,PWR003,PWR069"
COMPILE_COMMANDS="Fortran/MATMUL/compile_commands.json"
ISSUE_COUNT=$(codee checks --check-id "$CHECKS" --verbose -p "$COMPILE_COMMANDS" --json | jq '.Checks | length')
if [ "$ISSUE_COUNT" -gt 0 ]; then
echo "❌ Commit aborted: $ISSUE_COUNT critical issues were found. Review codee_checks_output.json for details."
exit 1
fi
Finally, run pre-commit install
in the root of the repository to
set up the git hook scripts.
pre-commit install
Now the pre-commit
hook is installed at .git/hooks/pre-commit
and it will run automatically on git commit
.
Usage
On every git commit
, if any Fortran files have been modified,
codee checks
will be executed and the commit will be rejected
if any critical checkers are triggered.