summaryrefslogtreecommitdiffstats
path: root/subcmds
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 /subcmds
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 'subcmds')
-rw-r--r--subcmds/sync.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 20d75dc8..250925f4 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -68,6 +68,7 @@ from git_config import GetUrlCookieFile
68from git_refs import HEAD 68from git_refs import HEAD
69from git_refs import R_HEADS 69from git_refs import R_HEADS
70import git_superproject 70import git_superproject
71from hooks import RepoHook
71import platform_utils 72import platform_utils
72from progress import elapsed_str 73from progress import elapsed_str
73from progress import jobs_str 74from progress import jobs_str
@@ -623,6 +624,7 @@ later is required to fix a server side protocol bug.
623 action="store_true", 624 action="store_true",
624 help=optparse.SUPPRESS_HELP, 625 help=optparse.SUPPRESS_HELP,
625 ) 626 )
627 RepoHook.AddOptionGroup(p, "post-sync")
626 628
627 def _GetBranch(self, manifest_project): 629 def _GetBranch(self, manifest_project):
628 """Returns the branch name for getting the approved smartsync manifest. 630 """Returns the branch name for getting the approved smartsync manifest.
@@ -1847,6 +1849,21 @@ later is required to fix a server side protocol bug.
1847 except (KeyboardInterrupt, Exception) as e: 1849 except (KeyboardInterrupt, Exception) as e:
1848 raise RepoUnhandledExceptionError(e, aggregate_errors=errors) 1850 raise RepoUnhandledExceptionError(e, aggregate_errors=errors)
1849 1851
1852 # Run post-sync hook only after successful sync
1853 self._RunPostSyncHook(opt)
1854
1855 def _RunPostSyncHook(self, opt):
1856 """Run post-sync hook if configured in manifest <repo-hooks>."""
1857 hook = RepoHook.FromSubcmd(
1858 hook_type="post-sync",
1859 manifest=self.manifest,
1860 opt=opt,
1861 abort_if_user_denies=False,
1862 )
1863 success = hook.Run(repo_topdir=self.client.topdir)
1864 if not success:
1865 print("Warning: post-sync hook reported failure.")
1866
1850 def _ExecuteHelper(self, opt, args, errors): 1867 def _ExecuteHelper(self, opt, args, errors):
1851 manifest = self.outer_manifest 1868 manifest = self.outer_manifest
1852 if not opt.outer_manifest: 1869 if not opt.outer_manifest: