summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorJimmie Wester <jimmie.wester@stericsson.com>2012-10-24 14:35:05 +0200
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2015-02-03 16:01:15 +0900
commit38e4387f8eb8cffd6359d726c38a7c524fef07e3 (patch)
tree897b7f640822d21019d740fd45aa564fba6a18f9 /project.py
parentee6908442102008df57b46271323d9b06d5fdfbf (diff)
downloadgit-repo-38e4387f8eb8cffd6359d726c38a7c524fef07e3.tar.gz
Implementation of manifest defined githooks
When working within a team or corporation it is often useful/required to use predefined git templates. This change teaches repo to use a per-remote git hook template structure. The implementation is done as a continuation of the existing projecthook functionality. The terminology is therefore defined as projecthooks. The downloaded projecthooks are stored in the .repo directory as a metaproject separating them from the users project forest. The projecthooks are downloaded and set up when doing a repo init and updated for each new repo init. When downloading a mirror the projecthooks gits are not added to the bare forest since the intention is to ensure that the latest are used (allows for company policy enforcement). The projecthooks are defined in the manifest file in the remote element as a subnode, the name refers to the project name on the server referred to in the remote. <remote name="myremote ..> <projecthook name="myprojecthookgit" revision="myrevision"/> </remote> The hooks found in the projecthook revision supersede the stock hooks found in repo. This removes the need for updating the projecthook gits for repo stock hook changes. Change-Id: I6796b7b0342c1f83c35f4b3e46782581b069a561 Signed-off-by: Patrik Ryd <patrik.ryd@stericsson.com> Signed-off-by: Ian Kumlien <ian.kumlien@gmail.com>
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 \