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 /subcmds/init.py | |
parent | e30f46b957c9c192f09a4907e3e7e802c9b782f8 (diff) | |
parent | 38e4387f8eb8cffd6359d726c38a7c524fef07e3 (diff) | |
download | git-repo-85e82670315cc2a6ac020430ae3f7e46862ff5d9.tar.gz |
Merge "Implementation of manifest defined githooks"
Diffstat (limited to 'subcmds/init.py')
-rw-r--r-- | subcmds/init.py | 49 |
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: | |||
32 | from color import Coloring | 32 | from color import Coloring |
33 | from command import InteractiveCommand, MirrorSafeCommand | 33 | from command import InteractiveCommand, MirrorSafeCommand |
34 | from error import ManifestParseError | 34 | from error import ManifestParseError |
35 | from project import SyncBuffer | 35 | from project import SyncBuffer, MetaProject |
36 | from git_config import GitConfig | 36 | from git_config import GitConfig |
37 | from git_command import git_require, MIN_GIT_VERSION | 37 | from 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(): |