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>
This commit is contained in:
parent
21269c3eed
commit
82d500eb7a
3 changed files with 58 additions and 0 deletions
|
@ -68,6 +68,7 @@ from git_config import GetUrlCookieFile
|
|||
from git_refs import HEAD
|
||||
from git_refs import R_HEADS
|
||||
import git_superproject
|
||||
from hooks import RepoHook
|
||||
import platform_utils
|
||||
from progress import elapsed_str
|
||||
from progress import jobs_str
|
||||
|
@ -623,6 +624,7 @@ later is required to fix a server side protocol bug.
|
|||
action="store_true",
|
||||
help=optparse.SUPPRESS_HELP,
|
||||
)
|
||||
RepoHook.AddOptionGroup(p, "post-sync")
|
||||
|
||||
def _GetBranch(self, manifest_project):
|
||||
"""Returns the branch name for getting the approved smartsync manifest.
|
||||
|
@ -1847,6 +1849,21 @@ later is required to fix a server side protocol bug.
|
|||
except (KeyboardInterrupt, Exception) as e:
|
||||
raise RepoUnhandledExceptionError(e, aggregate_errors=errors)
|
||||
|
||||
# Run post-sync hook only after successful sync
|
||||
self._RunPostSyncHook(opt)
|
||||
|
||||
def _RunPostSyncHook(self, opt):
|
||||
"""Run post-sync hook if configured in manifest <repo-hooks>."""
|
||||
hook = RepoHook.FromSubcmd(
|
||||
hook_type="post-sync",
|
||||
manifest=self.manifest,
|
||||
opt=opt,
|
||||
abort_if_user_denies=False,
|
||||
)
|
||||
success = hook.Run(repo_topdir=self.client.topdir)
|
||||
if not success:
|
||||
print("Warning: post-sync hook reported failure.")
|
||||
|
||||
def _ExecuteHelper(self, opt, args, errors):
|
||||
manifest = self.outer_manifest
|
||||
if not opt.outer_manifest:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue