summaryrefslogtreecommitdiffstats
path: root/subcmds/init.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 /subcmds/init.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 'subcmds/init.py')
-rw-r--r--subcmds/init.py49
1 files changed, 48 insertions, 1 deletions
diff --git a/subcmds/init.py b/subcmds/init.py
index b73de71c..c5bf2823 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -32,7 +32,7 @@ else:
32from color import Coloring 32from color import Coloring
33from command import InteractiveCommand, MirrorSafeCommand 33from command import InteractiveCommand, MirrorSafeCommand
34from error import ManifestParseError 34from error import ManifestParseError
35from project import SyncBuffer 35from project import SyncBuffer, MetaProject
36from git_config import GitConfig 36from git_config import GitConfig
37from git_command import git_require, MIN_GIT_VERSION 37from git_command import git_require, MIN_GIT_VERSION
38 38
@@ -374,6 +374,52 @@ to update the working directory files.
374 print(' rm -r %s/.repo' % self.manifest.topdir) 374 print(' rm -r %s/.repo' % self.manifest.topdir)
375 print('and try again.') 375 print('and try again.')
376 376
377 def _SyncProjectHooks(self, opt, repodir):
378 """Downloads the defined hooks supplied in the projecthooks element
379
380 """
381 # Always delete projecthooks and re-download for every new init.
382 projecthooksdir = os.path.join(repodir, 'projecthooks')
383 if os.path.exists(projecthooksdir):
384 shutil.rmtree(projecthooksdir)
385 for remotename in self.manifest.remotes:
386 r = self.manifest.remotes.get(remotename)
387 if r.projecthookName is not None and r.projecthookRevision is not None:
388 projecthookurl = r.resolvedFetchUrl.rstrip('/') + '/' + r.projecthookName
389
390 ph = MetaProject(manifest = self.manifest,
391 name = r.projecthookName,
392 gitdir = os.path.join(projecthooksdir,'%s/%s.git' % (remotename, r.projecthookName)),
393 worktree = os.path.join(projecthooksdir,'%s/%s' % (remotename, r.projecthookName)))
394
395 ph.revisionExpr = r.projecthookRevision
396 is_new = not ph.Exists
397
398 if is_new:
399 if not opt.quiet:
400 print('Get projecthook %s' % \
401 GitConfig.ForUser().UrlInsteadOf(projecthookurl), file=sys.stderr)
402 ph._InitGitDir(MirrorOverride=True)
403
404 phr = ph.GetRemote(remotename)
405 phr.name = 'origin'
406 phr.url = projecthookurl
407 phr.ResetFetch()
408 phr.Save()
409
410 if not ph.Sync_NetworkHalf(quiet=opt.quiet, is_new=is_new, clone_bundle=False):
411 print('fatal: cannot obtain projecthook %s' % phr.url, file=sys.stderr)
412
413 # Better delete the git dir if we created it; otherwise next
414 # time (when user fixes problems) we won't go through the "is_new" logic.
415 if is_new:
416 shutil.rmtree(ph.gitdir)
417 sys.exit(1)
418
419 syncbuf = SyncBuffer(ph.config)
420 ph.Sync_LocalHalf(syncbuf)
421 syncbuf.Finish()
422
377 def Execute(self, opt, args): 423 def Execute(self, opt, args):
378 git_require(MIN_GIT_VERSION, fail=True) 424 git_require(MIN_GIT_VERSION, fail=True)
379 425
@@ -389,6 +435,7 @@ to update the working directory files.
389 435
390 self._SyncManifest(opt) 436 self._SyncManifest(opt)
391 self._LinkManifest(opt.manifest_name) 437 self._LinkManifest(opt.manifest_name)
438 self._SyncProjectHooks(opt, self.manifest.repodir)
392 439
393 if os.isatty(0) and os.isatty(1) and not self.manifest.IsMirror: 440 if os.isatty(0) and os.isatty(1) and not self.manifest.IsMirror:
394 if opt.config_name or self._ShouldConfigureUser(): 441 if opt.config_name or self._ShouldConfigureUser():