summaryrefslogtreecommitdiffstats
path: root/docs/repo-hooks.md
diff options
context:
space:
mode:
authorKenny Cheng <chao.shun.cheng.tw@gmail.com>2025-06-02 21:55:04 +0800
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2025-07-01 16:11:50 -0700
commit82d500eb7aa93f9bff66a4358a08d2ba2d599550 (patch)
tree60d2003fa946943a13bfb9a96bd88bb60167c57f /docs/repo-hooks.md
parent21269c3eedc428610a5cab1494b2459a7e939fc7 (diff)
downloadgit-repo-82d500eb7aa93f9bff66a4358a08d2ba2d599550.tar.gz
sync: support post-sync hook in <repo-hooks>
Add support for a new hook type "post-sync" declared in the manifest using <repo-hooks>. 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: <project name="myorg/repo-hooks" path="hooks" revision="main" /> <repo-hooks in-project="myorg/repo-hooks" enabled-list="post-sync"> <hook name="post-sync" /> </repo-hooks> 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 <chao.shun.cheng.tw@gmail.com> Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/480581 Reviewed-by: Scott Lee <ddoman@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com>
Diffstat (limited to 'docs/repo-hooks.md')
-rw-r--r--docs/repo-hooks.md40
1 files changed, 40 insertions, 0 deletions
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):
133 kwargs: Leave this here for forward-compatibility. 133 kwargs: Leave this here for forward-compatibility.
134 """ 134 """
135``` 135```
136
137### post-sync
138
139This hook runs when `repo sync` completes without errors.
140
141Note: This includes cases where no actual checkout may occur. The hook will still run.
142For example:
143- `repo sync -n` performs network fetches only and skips the checkout phase.
144- `repo sync <project>` only updates the specified project(s).
145- Partial failures may still result in a successful exit.
146
147This hook is useful for post-processing tasks such as setting up git hooks,
148bootstrapping configuration files, or running project initialization logic.
149
150The hook is defined using the existing `<repo-hooks>` manifest block and is
151optional. If the hook script fails or is missing, `repo sync` will still
152complete successfully, and the error will be printed as a warning.
153
154Example:
155
156```xml
157<project name="myorg/dev-tools" path="tools" revision="main" />
158<repo-hooks in-project="myorg/dev-tools" enabled-list="post-sync">
159 <hook name="post-sync" />
160</repo-hooks>
161```
162
163The `post-sync.py` file should be defined like:
164
165```py
166def main(repo_topdir=None, **kwargs):
167 """Main function invoked directly by repo.
168
169 We must use the name "main" as that is what repo requires.
170
171 Args:
172 repo_topdir: The absolute path to the top-level directory of the repo workspace.
173 kwargs: Leave this here for forward-compatibility.
174 """
175```