repo: support post-sync hook via <repo-hooks>
This patch adds support for a `post-sync` hook, defined via the `<repo-hooks>` 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: <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 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 <chao.shun.cheng.tw@gmail.com>
This commit is contained in:
parent
08815ad3eb
commit
37a1da075e
1 changed files with 17 additions and 0 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue