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/lint.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
.
- Check the
git
documentation, and copypre-push
into a script with the right name. - Make sure the script has the executable bit set
(
chmod +x <script>
). - Add a new
Command
implementation underlib/src
. Give the newCommand
the same name as the new hook. - Add the new
Command
to theCommandRunner
inlib/githooks.dart
. - Make sure the script from step (1) is passing the new command to the Dart program.