summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
Diffstat (limited to 'project.py')
-rw-r--r--project.py57
1 files changed, 33 insertions, 24 deletions
diff --git a/project.py b/project.py
index 5f478993..68d7421f 100644
--- a/project.py
+++ b/project.py
@@ -69,27 +69,6 @@ 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
93class DownloadedChange(object): 72class DownloadedChange(object):
94 _commit_cache = None 73 _commit_cache = None
95 74
@@ -2106,7 +2085,7 @@ class Project(object):
2106 if GitCommand(self, cmd).Wait() != 0: 2085 if GitCommand(self, cmd).Wait() != 0:
2107 raise GitError('%s merge %s ' % (self.name, head)) 2086 raise GitError('%s merge %s ' % (self.name, head))
2108 2087
2109 def _InitGitDir(self, mirror_git=None): 2088 def _InitGitDir(self, mirror_git=None, MirrorOverride=False):
2110 if not os.path.exists(self.gitdir): 2089 if not os.path.exists(self.gitdir):
2111 2090
2112 # Initialize the bare repository, which contains all of the objects. 2091 # Initialize the bare repository, which contains all of the objects.
@@ -2148,11 +2127,38 @@ class Project(object):
2148 for key in ['user.name', 'user.email']: 2127 for key in ['user.name', 'user.email']:
2149 if m.Has(key, include_defaults=False): 2128 if m.Has(key, include_defaults=False):
2150 self.config.SetString(key, m.GetString(key)) 2129 self.config.SetString(key, m.GetString(key))
2151 if self.manifest.IsMirror: 2130 if self.manifest.IsMirror and not MirrorOverride:
2152 self.config.SetString('core.bare', 'true') 2131 self.config.SetString('core.bare', 'true')
2153 else: 2132 else:
2154 self.config.SetString('core.bare', None) 2133 self.config.SetString('core.bare', None)
2155 2134
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
2156 def _UpdateHooks(self): 2162 def _UpdateHooks(self):
2157 if os.path.exists(self.gitdir): 2163 if os.path.exists(self.gitdir):
2158 self._InitHooks() 2164 self._InitHooks()
@@ -2161,7 +2167,10 @@ class Project(object):
2161 hooks = os.path.realpath(self._gitdir_path('hooks')) 2167 hooks = os.path.realpath(self._gitdir_path('hooks'))
2162 if not os.path.exists(hooks): 2168 if not os.path.exists(hooks):
2163 os.makedirs(hooks) 2169 os.makedirs(hooks)
2164 for stock_hook in _ProjectHooks(): 2170 pr = None
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):
2165 name = os.path.basename(stock_hook) 2174 name = os.path.basename(stock_hook)
2166 2175
2167 if name in ('commit-msg',) and not self.remote.review \ 2176 if name in ('commit-msg',) and not self.remote.review \