May be used as a pre-commit git hook, as part of a CI/CD pipeline or as a standalone tool.
Supports the following platforms: x86_64, arm64.
-
Download the latest git-commit-check release and place it within your repository.
-
Change directory to the main directory of your project & copy file config.sh.example and edit their values according to your project e.g., project path, gitcc path, container name, shell.
Let's assume you placed the git-commit-check directory under the bin directory of your project:
cd path/to/your/project
cp bin/git-commit-check/config.sh.example bin/git-commit-check/config.sh
- Copy file pre-commit.example to pre-commit
cp bin/git-commit-check/hooks/pre-commit.example bin/git-commit-check/hooks/pre-commit
Edit the config.sh file to set the values for the checks you want to run. Set the SCRIPTS_ENABLED string variable with the script names that you want to use, separated by new-line.
-
Create your own new script and add it to the
scripts/usedirectory. Script naming conventions:- Prepend a two-digit script ID followed by '_' to the script name to indicate the order of execution.
- Append the .sh extension to the script name.
- Copy the contents of the
scripts/templatescript into the new script file. - Follow the instructions within the template file.
MUST implement function 'before_run' and initialize the 4 variables (HEADER, COMMAND, COMMAND_NAME & COMMAND_VERSION)MAY implement function 'run' and add custom logic. A typical use case can be found in the template file.MAY implement function 'after_run' to perform any cleanup or post-processing actions. - Try to keep your scripts POSIX-compliant so that they will work in all (most) SHELL. There are command line and online tools that can help you verify this.
Alternatively, you may copy one of the existing scripts from
scripts/librarydirectory into thescripts/usedirectory.
-
Make the pre-commit hook executable. Run the following command to instruct git to call
gitccbefore allowing the developer to create a new commit.
git config core.hooksPath bin/git-commit-check/hooks
- Run
git committo test the pre-commit hook. If your application is containerized (docker/podman), gitcc will automatically run within your container, regardless whether you dogit commitfrom the host machine or the container. This way the pre-commit hook and all the checks will be executed in the same environment as the application. There is a configuration option for forcing gitcc to run in Host machine if desired.
Done!