summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorJonathan Nieder <jrn@google.com>2015-03-17 11:29:58 -0700
committerJonathan Nieder <jrn@google.com>2015-03-17 11:29:58 -0700
commit9371979628a945a1caf526aeff84a1ac68a22efe (patch)
treedddfeb5a602f799f31a8d62ac5feb72fa2fb06ab /project.py
parent20860042617d43ed192d60659cd92c71ea251519 (diff)
downloadgit-repo-9371979628a945a1caf526aeff84a1ac68a22efe.tar.gz
Revert "Implementation of manifest defined githooks"v1.12.20
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 <jrn@google.com>
Diffstat (limited to 'project.py')
-rw-r--r--project.py57
1 files changed, 24 insertions, 33 deletions
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):
69def sq(r): 69def sq(r):
70 return "'" + r.replace("'", "'\''") + "'" 70 return "'" + r.replace("'", "'\''") + "'"
71 71
72_project_hook_list = None
73def _ProjectHooks():
74 """List the hooks present in the 'hooks' directory.
75
76 These hooks are project hooks and are copied to the '.git/hooks' directory
77 of all subprojects.
78
79 This function caches the list of hooks (based on the contents of the
80 'repo/hooks' directory) on the first call.
81
82 Returns:
83 A list of absolute paths to all of the files in the hooks directory.
84 """
85 global _project_hook_list
86 if _project_hook_list is None:
87 d = os.path.realpath(os.path.abspath(os.path.dirname(__file__)))
88 d = os.path.join(d, 'hooks')
89 _project_hook_list = [os.path.join(d, x) for x in os.listdir(d)]
90 return _project_hook_list
91
92
72class DownloadedChange(object): 93class DownloadedChange(object):
73 _commit_cache = None 94 _commit_cache = None
74 95
@@ -2085,7 +2106,7 @@ class Project(object):
2085 if GitCommand(self, cmd).Wait() != 0: 2106 if GitCommand(self, cmd).Wait() != 0:
2086 raise GitError('%s merge %s ' % (self.name, head)) 2107 raise GitError('%s merge %s ' % (self.name, head))
2087 2108
2088 def _InitGitDir(self, mirror_git=None, MirrorOverride=False): 2109 def _InitGitDir(self, mirror_git=None):
2089 if not os.path.exists(self.gitdir): 2110 if not os.path.exists(self.gitdir):
2090 2111
2091 # Initialize the bare repository, which contains all of the objects. 2112 # Initialize the bare repository, which contains all of the objects.
@@ -2127,38 +2148,11 @@ class Project(object):
2127 for key in ['user.name', 'user.email']: 2148 for key in ['user.name', 'user.email']:
2128 if m.Has(key, include_defaults=False): 2149 if m.Has(key, include_defaults=False):
2129 self.config.SetString(key, m.GetString(key)) 2150 self.config.SetString(key, m.GetString(key))
2130 if self.manifest.IsMirror and not MirrorOverride: 2151 if self.manifest.IsMirror:
2131 self.config.SetString('core.bare', 'true') 2152 self.config.SetString('core.bare', 'true')
2132 else: 2153 else:
2133 self.config.SetString('core.bare', None) 2154 self.config.SetString('core.bare', None)
2134 2155
2135 def _ProjectHooks(self, remote, repodir):
2136 """List the hooks present in the 'hooks' directory.
2137
2138 These hooks are project hooks and are copied to the '.git/hooks' directory
2139 of all subprojects.
2140
2141 The remote projecthooks supplement/overrule any stockhook making it possible to
2142 have a combination of hooks both from the remote projecthook and
2143 .repo/hooks directories.
2144
2145 Returns:
2146 A list of absolute paths to all of the files in the hooks directory and
2147 projecthooks files, excluding the .git folder.
2148 """
2149 hooks = {}
2150 d = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'hooks')
2151 hooks = dict([(x, os.path.join(d, x)) for x in os.listdir(d)])
2152 if remote is not None:
2153 if remote.projecthookName is not None:
2154 d = os.path.abspath('%s/projecthooks/%s/%s' % (repodir, remote.name, remote.projecthookName))
2155 if os.path.isdir(d):
2156 hooks.update(dict([(x, os.path.join(d, x)) for x in os.listdir(d)]))
2157
2158 if hooks.has_key('.git'):
2159 del hooks['.git']
2160 return hooks.values()
2161
2162 def _UpdateHooks(self): 2156 def _UpdateHooks(self):
2163 if os.path.exists(self.gitdir): 2157 if os.path.exists(self.gitdir):
2164 self._InitHooks() 2158 self._InitHooks()
@@ -2167,10 +2161,7 @@ class Project(object):
2167 hooks = os.path.realpath(self._gitdir_path('hooks')) 2161 hooks = os.path.realpath(self._gitdir_path('hooks'))
2168 if not os.path.exists(hooks): 2162 if not os.path.exists(hooks):
2169 os.makedirs(hooks) 2163 os.makedirs(hooks)
2170 pr = None 2164 for stock_hook in _ProjectHooks():
2171 if self is not self.manifest.manifestProject:
2172 pr = self.manifest.remotes.get(self.remote.name)
2173 for stock_hook in self._ProjectHooks(pr, self.manifest.repodir):
2174 name = os.path.basename(stock_hook) 2165 name = os.path.basename(stock_hook)
2175 2166
2176 if name in ('commit-msg',) and not self.remote.review \ 2167 if name in ('commit-msg',) and not self.remote.review \