From 82d500eb7aa93f9bff66a4358a08d2ba2d599550 Mon Sep 17 00:00:00 2001 From: Kenny Cheng Date: Mon, 2 Jun 2025 21:55:04 +0800 Subject: sync: support post-sync hook in Add support for a new hook type "post-sync" declared in the manifest using . This allows executing a script automatically after a successful `repo sync`. This is useful for initializing developer environments, installing project-wide Git hooks, generating configs, and other post-sync automation tasks. Example manifest usage: The hook script must be named `post-sync.py` and located at the root of the hook project. The post-sync hook does not block `repo sync`; if the script fails, the sync still completes successfully with a warning. Test: Added `post-sync.py` in hook project and verified it runs after `repo sync` Bug: b/421694721 Change-Id: I69f3158f0fc319d73a85028d6e90fea02c1dc8c8 Signed-off-by: Kenny Cheng Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/480581 Reviewed-by: Scott Lee Reviewed-by: Gavin Mak --- docs/repo-hooks.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'docs') diff --git a/docs/repo-hooks.md b/docs/repo-hooks.md index cbb1aac7..a56f261c 100644 --- a/docs/repo-hooks.md +++ b/docs/repo-hooks.md @@ -133,3 +133,43 @@ def main(project_list, worktree_list=None, **kwargs): kwargs: Leave this here for forward-compatibility. """ ``` + +### post-sync + +This hook runs when `repo sync` completes without errors. + +Note: This includes cases where no actual checkout may occur. The hook will still run. +For example: +- `repo sync -n` performs network fetches only and skips the checkout phase. +- `repo sync ` only updates the specified project(s). +- Partial failures may still result in a successful exit. + +This hook is useful for post-processing tasks such as setting up git hooks, +bootstrapping configuration files, or running project initialization logic. + +The hook is defined using the existing `` manifest block and is +optional. If the hook script fails or is missing, `repo sync` will still +complete successfully, and the error will be printed as a warning. + +Example: + +```xml + + + + +``` + +The `post-sync.py` file should be defined like: + +```py +def main(repo_topdir=None, **kwargs): + """Main function invoked directly by repo. + + We must use the name "main" as that is what repo requires. + + Args: + repo_topdir: The absolute path to the top-level directory of the repo workspace. + kwargs: Leave this here for forward-compatibility. + """ +``` -- cgit v1.2.3-54-g00ecf