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 49db02e3..68bc7bd3 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
@@ -2091,7 +2070,7 @@ class Project(object):
2091 if GitCommand(self, cmd).Wait() != 0: 2070 if GitCommand(self, cmd).Wait() != 0:
2092 raise GitError('%s merge %s ' % (self.name, head)) 2071 raise GitError('%s merge %s ' % (self.name, head))
2093 2072
2094 def _InitGitDir(self, mirror_git=None): 2073 def _InitGitDir(self, mirror_git=None, MirrorOverride=False):
2095 if not os.path.exists(self.gitdir): 2074 if not os.path.exists(self.gitdir):
2096 2075
2097 # Initialize the bare repository, which contains all of the objects. 2076 # Initialize the bare repository, which contains all of the objects.
@@ -2133,11 +2112,38 @@ class Project(object):
2133 for key in ['user.name', 'user.email']: 2112 for key in ['user.name', 'user.email']:
2134 if m.Has(key, include_defaults=False): 2113 if m.Has(key, include_defaults=False):
2135 self.config.SetString(key, m.GetString(key)) 2114 self.config.SetString(key, m.GetString(key))
2136 if self.manifest.IsMirror: 2115 if self.manifest.IsMirror and not MirrorOverride:
2137 self.config.SetString('core.bare', 'true') 2116 self.config.SetString('core.bare', 'true')
2138 else: 2117 else:
2139 self.config.SetString('core.bare', None) 2118 self.config.SetString('core.bare', None)
2140 2119
2120 def _ProjectHooks(self, remote, repodir):
2121 """List the hooks present in the 'hooks' directory.
2122
2123 These hooks are project hooks and are copied to the '.git/hooks' directory
2124 of all subprojects.
2125
2126 The remote projecthooks supplement/overrule any stockhook making it possible to
2127 have a combination of hooks both from the remote projecthook and
2128 .repo/hooks directories.
2129
2130 Returns:
2131 A list of absolute paths to all of the files in the hooks directory and
2132 projecthooks files, excluding the .git folder.
2133 """
2134 hooks = {}
2135 d = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'hooks')
2136 hooks = dict([(x, os.path.join(d, x)) for x in os.listdir(d)])
2137 if remote is not None:
2138 if remote.projecthookName is not None:
2139 d = os.path.abspath('%s/projecthooks/%s/%s' % (repodir, remote.name, remote.projecthookName))
2140 if os.path.isdir(d):
2141 hooks.update(dict([(x, os.path.join(d, x)) for x in os.listdir(d)]))
2142
2143 if hooks.has_key('.git'):
2144 del hooks['.git']
2145 return hooks.values()
2146
2141 def _UpdateHooks(self): 2147 def _UpdateHooks(self):
2142 if os.path.exists(self.gitdir): 2148 if os.path.exists(self.gitdir):
2143 self._InitHooks() 2149 self._InitHooks()
@@ -2146,7 +2152,10 @@ class Project(object):
2146 hooks = os.path.realpath(self._gitdir_path('hooks')) 2152 hooks = os.path.realpath(self._gitdir_path('hooks'))
2147 if not os.path.exists(hooks): 2153 if not os.path.exists(hooks):
2148 os.makedirs(hooks) 2154 os.makedirs(hooks)
2149 for stock_hook in _ProjectHooks(): 2155 pr = None
2156 if self is not self.manifest.manifestProject:
2157 pr = self.manifest.remotes.get(self.remote.name)
2158 for stock_hook in self._ProjectHooks(pr, self.manifest.repodir):
2150 name = os.path.basename(stock_hook) 2159 name = os.path.basename(stock_hook)
2151 2160
2152 if name in ('commit-msg',) and not self.remote.review \ 2161 if name in ('commit-msg',) and not self.remote.review \