The behavior of git
commands can be customized through the use of “hooks”. These hooks are described in detail in git's documentation.
git
looks for an executables by name in the directory specified by the core.hooksPath
git config
setting. The script setup.py
here points core.hooksPath
at this directory. It runs during a gclient sync
or a gclient runhooks
.
The hooks here are implemented in Dart by the program with entrypoint bin/main.dart
in this directory. The commands of the program are the implementation of the different hooks, for example bin/main.dart pre-push ...
. Since the Dart program itself isn't an executable, these commands are invoked by small Python wrapper scripts. These wrapper scripts have the names that git
will look for.
This hooks runs when pushing commits to a remote branch, for example to create or update a pull request: git push origin my-local-branch
.
The pre-push
hook runs ci/clang_tidy.sh
, ci/pylint.sh
and ci/format.sh
. ci/analyze.sh
and ci/licenses.sh
are more expensive and are not run.
Since the pre-push checks run on every git push
, they should run quickly. New checks can be added by modifying the run()
method of the PrePushCommand
class in lib/src/pre_push_command.dart
.
git
documentation, and copy pre-push
into a script with the right name.chmod +x <script>
).Command
implementation under lib/src
. Give the new Command
the same name as the new hook.Command
to the CommandRunner
in lib/githooks.dart
.