When you run `repo upload` to upload your local commits to Gerrit, a preupload phase runs. This is used to run linters or local unittests to catch various common errors.
These can be customized on a per-git repo basis. You can have custom scripts execute using the hooks phase, or opt in/out of common checks that are kept in the main upload script.
You can find the main preupload script in the src/repohooks/ directory.
All settings live in the PRESUBMIT.cfg file in the root of the git repo.
You can run arbitrary scripts with the hooks section.
You do not need to send stderr to stdout since the script that runs them combines these anyway.
You can list as many/few scripts as you want. Just keep adding a unique number after the "hook" key name. Each script must fit on one line (so don't worry about any 80-character limits).
The following variables are defined for use by your script:
Since many tests are not specific to a repo, we make them available we enable them on a global basis. You can see the current list by looking at the _DISABLE_FLAGS dict in the pre-upload.py file itself.
When looking to add a new check, you should first consider whether it would benefit more projects than just your own. If so, you should add it to the repohooks/pre-upload.py file itself.
This isn't directly related to repohooks, but you can learn more about COMMIT-QUEUE.ini in the Bypassing tests on a per-project basis page.