diff options
author | Conley Owens <cco3@android.com> | 2015-03-05 20:52:29 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-03-05 20:52:30 +0000 |
commit | 85e82670315cc2a6ac020430ae3f7e46862ff5d9 (patch) | |
tree | e1cec59a11dafef7dfc301651a5fe0fe5b721ef1 /project.py | |
parent | e30f46b957c9c192f09a4907e3e7e802c9b782f8 (diff) | |
parent | 38e4387f8eb8cffd6359d726c38a7c524fef07e3 (diff) | |
download | git-repo-85e82670315cc2a6ac020430ae3f7e46862ff5d9.tar.gz |
Merge "Implementation of manifest defined githooks"
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 57 |
1 files changed, 33 insertions, 24 deletions
@@ -69,27 +69,6 @@ def not_rev(r): | |||
69 | def sq(r): | 69 | def sq(r): |
70 | return "'" + r.replace("'", "'\''") + "'" | 70 | return "'" + r.replace("'", "'\''") + "'" |
71 | 71 | ||
72 | _project_hook_list = None | ||
73 | def _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 | |||
93 | class DownloadedChange(object): | 72 | class 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 \ |