From 9371979628a945a1caf526aeff84a1ac68a22efe Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 17 Mar 2015 11:29:58 -0700 Subject: Revert "Implementation of manifest defined githooks" This reverts commit 38e4387f8eb8cffd6359d726c38a7c524fef07e3. A "repo init" followed by "repo sync" is meant to be as safe as "git clone". In particular it should not run arbitrary code provided by the manifest owner. It would still be nice to have support for manifest-defined git hooks --- they'd just need a prompt like the upload RepoHook has. Hopefully a later change can bring them back. Change-Id: I5ecd90fb5c2ed64f103d856d1ffcba38a47b062d Signed-off-by: Jonathan Nieder --- project.py | 57 ++++++++++++++++++++++++--------------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) (limited to 'project.py') diff --git a/project.py b/project.py index c6a91d05..028deb5f 100644 --- a/project.py +++ b/project.py @@ -69,6 +69,27 @@ def not_rev(r): def sq(r): return "'" + r.replace("'", "'\''") + "'" +_project_hook_list = None +def _ProjectHooks(): + """List the hooks present in the 'hooks' directory. + + These hooks are project hooks and are copied to the '.git/hooks' directory + of all subprojects. + + This function caches the list of hooks (based on the contents of the + 'repo/hooks' directory) on the first call. + + Returns: + A list of absolute paths to all of the files in the hooks directory. + """ + global _project_hook_list + if _project_hook_list is None: + d = os.path.realpath(os.path.abspath(os.path.dirname(__file__))) + d = os.path.join(d, 'hooks') + _project_hook_list = [os.path.join(d, x) for x in os.listdir(d)] + return _project_hook_list + + class DownloadedChange(object): _commit_cache = None @@ -2085,7 +2106,7 @@ class Project(object): if GitCommand(self, cmd).Wait() != 0: raise GitError('%s merge %s ' % (self.name, head)) - def _InitGitDir(self, mirror_git=None, MirrorOverride=False): + def _InitGitDir(self, mirror_git=None): if not os.path.exists(self.gitdir): # Initialize the bare repository, which contains all of the objects. @@ -2127,38 +2148,11 @@ class Project(object): for key in ['user.name', 'user.email']: if m.Has(key, include_defaults=False): self.config.SetString(key, m.GetString(key)) - if self.manifest.IsMirror and not MirrorOverride: + if self.manifest.IsMirror: self.config.SetString('core.bare', 'true') else: self.config.SetString('core.bare', None) - def _ProjectHooks(self, remote, repodir): - """List the hooks present in the 'hooks' directory. - - These hooks are project hooks and are copied to the '.git/hooks' directory - of all subprojects. - - The remote projecthooks supplement/overrule any stockhook making it possible to - have a combination of hooks both from the remote projecthook and - .repo/hooks directories. - - Returns: - A list of absolute paths to all of the files in the hooks directory and - projecthooks files, excluding the .git folder. - """ - hooks = {} - d = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'hooks') - hooks = dict([(x, os.path.join(d, x)) for x in os.listdir(d)]) - if remote is not None: - if remote.projecthookName is not None: - d = os.path.abspath('%s/projecthooks/%s/%s' % (repodir, remote.name, remote.projecthookName)) - if os.path.isdir(d): - hooks.update(dict([(x, os.path.join(d, x)) for x in os.listdir(d)])) - - if hooks.has_key('.git'): - del hooks['.git'] - return hooks.values() - def _UpdateHooks(self): if os.path.exists(self.gitdir): self._InitHooks() @@ -2167,10 +2161,7 @@ class Project(object): hooks = os.path.realpath(self._gitdir_path('hooks')) if not os.path.exists(hooks): os.makedirs(hooks) - pr = None - if self is not self.manifest.manifestProject: - pr = self.manifest.remotes.get(self.remote.name) - for stock_hook in self._ProjectHooks(pr, self.manifest.repodir): + for stock_hook in _ProjectHooks(): name = os.path.basename(stock_hook) if name in ('commit-msg',) and not self.remote.review \ -- cgit v1.2.3-54-g00ecf