diff options
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(): |
