From 37a1da075e40160ed348fd972dfc6eb7c9cee032 Mon Sep 17 00:00:00 2001 From: Kenny Cheng Date: Mon, 2 Jun 2025 21:55:04 +0800 Subject: [PATCH] repo: support post-sync hook via This patch adds support for a `post-sync` hook, defined via the `` tag in the manifest. It allows teams to automatically run a script after successful `repo sync`, commonly needed to initialize workspaces or install project-wide Git hooks. Example usage: The corresponding hook script (`post-sync.py`) must be located in the root of the `hooks_project`. This hook will not block sync completion even if it fails. Change-Id: I69f3158f0fc319d73a85028d6e90fea02c1dc8c8 Signed-off-by: Kenny Cheng --- subcmds/sync.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/subcmds/sync.py b/subcmds/sync.py index 3a4151dfe..e3e9aa7f7 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -79,6 +79,7 @@ from repo_logging import RepoLogger from repo_trace import Trace import ssh from wrapper import Wrapper +from hooks import RepoHook _ONE_DAY_S = 24 * 60 * 60 @@ -1736,6 +1737,22 @@ later is required to fix a server side protocol bug. errors = [] try: self._ExecuteHelper(opt, args, errors) + + try: + manifest = self.manifest + post_sync_hook = RepoHook( + hook_type="post-sync", + hooks_project=manifest.repo_hooks_project, + repo_topdir=manifest.topdir, + manifest_url=manifest.manifestProject.GetRemote("origin").url, + bypass_hooks=False, + allow_all_hooks=True, + ignore_hooks=True, + ) + post_sync_hook.Run() + except Exception as e: + print(f"Warning: post-sync hook failed: {e}") + except (RepoExitError, RepoChangedException): raise except (KeyboardInterrupt, Exception) as e: