Exemple #1
0
    def Execute(self, opt, args):
        project_list = self.GetProjects(args)
        pending = []
        reviewers = []
        cc = []
        branch = None

        if opt.branch:
            branch = opt.branch

        for project in project_list:
            if opt.current_branch:
                cbr = project.CurrentBranch
                up_branch = project.GetUploadableBranch(cbr)
                if up_branch:
                    avail = [up_branch]
                else:
                    avail = None
                    print('repo: error: Unable to upload branch "%s". '
                          'You might be able to fix the branch by running:\n'
                          '  git branch --set-upstream-to m/%s' %
                          (str(cbr), self.manifest.branch),
                          file=sys.stderr)
            else:
                avail = project.GetUploadableBranches(branch)
            if avail:
                pending.append((project, avail))

        if not pending:
            if branch is None:
                print('repo: error: no branches ready for upload',
                      file=sys.stderr)
            else:
                print('repo: error: no branches named "%s" ready for upload' %
                      (branch, ),
                      file=sys.stderr)
            return 1

        pending_proj_names = [project.name for (project, available) in pending]
        pending_worktrees = [
            project.worktree for (project, available) in pending
        ]
        hook = RepoHook.FromSubcmd(hook_type='pre-upload',
                                   manifest=self.manifest,
                                   opt=opt,
                                   abort_if_user_denies=True)
        if not hook.Run(project_list=pending_proj_names,
                        worktree_list=pending_worktrees):
            return 1

        if opt.reviewers:
            reviewers = _SplitEmails(opt.reviewers)
        if opt.cc:
            cc = _SplitEmails(opt.cc)
        people = (reviewers, cc)

        if len(pending) == 1 and len(pending[0][1]) == 1:
            self._SingleBranch(opt, pending[0][1][0], people)
        else:
            self._MultipleBranches(opt, pending, people)
Exemple #2
0
    def Execute(self, opt, args):
        projects = self.GetProjects(args)

        def _ProcessResults(_pool, _out, results):
            pending = []
            for result in results:
                project, avail = result
                if avail is None:
                    print('repo: error: %s: Unable to upload branch "%s". '
                          'You might be able to fix the branch by running:\n'
                          '  git branch --set-upstream-to m/%s' %
                          (project.relpath, project.CurrentBranch,
                           self.manifest.branch),
                          file=sys.stderr)
                elif avail:
                    pending.append(result)
            return pending

        pending = self.ExecuteInParallel(opt.jobs,
                                         functools.partial(
                                             self._GatherOne, opt),
                                         projects,
                                         callback=_ProcessResults)

        if not pending:
            if opt.branch is None:
                print('repo: error: no branches ready for upload',
                      file=sys.stderr)
            else:
                print('repo: error: no branches named "%s" ready for upload' %
                      (opt.branch, ),
                      file=sys.stderr)
            return 1

        pending_proj_names = [project.name for (project, available) in pending]
        pending_worktrees = [
            project.worktree for (project, available) in pending
        ]
        hook = RepoHook.FromSubcmd(hook_type='pre-upload',
                                   manifest=self.manifest,
                                   opt=opt,
                                   abort_if_user_denies=True)
        if not hook.Run(project_list=pending_proj_names,
                        worktree_list=pending_worktrees):
            return 1

        reviewers = _SplitEmails(opt.reviewers) if opt.reviewers else []
        cc = _SplitEmails(opt.cc) if opt.cc else []
        people = (reviewers, cc)

        if len(pending) == 1 and len(pending[0][1]) == 1:
            self._SingleBranch(opt, pending[0][1][0], people)
        else:
            self._MultipleBranches(opt, pending, people)
Exemple #3
0
  def _RunHooks(self, all_projects, opt, err_event):
    """Run the post repo sync hooks

    Args:
      all_projects: List of all projects for which to run the hook.
      opt: Program options returned from optparse.  See _Options().
      err_event: We'll set this event in the case of an error (after printing
          out info about the error).
    """
    pending_proj_names = [project.name for project in all_projects]
    pending_worktrees = [project.worktree for project in all_projects]
    hook = RepoHook.FromSubcmd(
        hook_type='post-sync', manifest=self.manifest,
        opt=opt, abort_if_user_denies=True)
    if (not hook.Run(
        project_list=pending_proj_names,
        worktree_list=pending_worktrees)):
      err_event.set()
Exemple #4
0
 def _Options(self, p):
     p.add_option('-t',
                  dest='auto_topic',
                  action='store_true',
                  help='Send local branch name to Gerrit Code Review')
     p.add_option('--hashtag',
                  '--ht',
                  dest='hashtags',
                  action='append',
                  default=[],
                  help='Add hashtags (comma delimited) to the review.')
     p.add_option('--hashtag-branch',
                  '--htb',
                  action='store_true',
                  help='Add local branch name as a hashtag.')
     p.add_option('-l',
                  '--label',
                  dest='labels',
                  action='append',
                  default=[],
                  help='Add a label when uploading.')
     p.add_option('--re',
                  '--reviewers',
                  type='string',
                  action='append',
                  dest='reviewers',
                  help='Request reviews from these people.')
     p.add_option('--cc',
                  type='string',
                  action='append',
                  dest='cc',
                  help='Also send email to these email addresses.')
     p.add_option('--br',
                  type='string',
                  action='store',
                  dest='branch',
                  help='Branch to upload.')
     p.add_option('--cbr',
                  '--current-branch',
                  dest='current_branch',
                  action='store_true',
                  help='Upload current git branch.')
     p.add_option('--ne',
                  '--no-emails',
                  action='store_false',
                  dest='notify',
                  default=True,
                  help='If specified, do not send emails on upload.')
     p.add_option('-p',
                  '--private',
                  action='store_true',
                  dest='private',
                  default=False,
                  help='If specified, upload as a private change.')
     p.add_option('-w',
                  '--wip',
                  action='store_true',
                  dest='wip',
                  default=False,
                  help='If specified, upload as a work-in-progress change.')
     p.add_option('-o',
                  '--push-option',
                  type='string',
                  action='append',
                  dest='push_options',
                  default=[],
                  help='Additional push options to transmit')
     p.add_option('-D',
                  '--destination',
                  '--dest',
                  type='string',
                  action='store',
                  dest='dest_branch',
                  metavar='BRANCH',
                  help='Submit for review on this target branch.')
     p.add_option('-n',
                  '--dry-run',
                  dest='dryrun',
                  default=False,
                  action='store_true',
                  help='Do everything except actually upload the CL.')
     p.add_option('-y',
                  '--yes',
                  default=False,
                  action='store_true',
                  help='Answer yes to all safe prompts.')
     p.add_option('--no-cert-checks',
                  dest='validate_certs',
                  action='store_false',
                  default=True,
                  help='Disable verifying ssl certs (unsafe).')
     RepoHook.AddOptionGroup(p, 'pre-upload')
Exemple #5
0
  def _Options(self, p, show_smart=True):
    try:
      self.jobs = self.manifest.default.sync_j
    except ManifestParseError:
      self.jobs = 1

    p.add_option('-f', '--force-broken',
                 dest='force_broken', action='store_true',
                 help='obsolete option (to be deleted in the future)')
    p.add_option('--fail-fast',
                 dest='fail_fast', action='store_true',
                 help='stop syncing after first error is hit')
    p.add_option('--force-sync',
                 dest='force_sync', action='store_true',
                 help="overwrite an existing git directory if it needs to "
                      "point to a different object directory. WARNING: this "
                      "may cause loss of data")
    p.add_option('--force-remove-dirty',
                 dest='force_remove_dirty', action='store_true',
                 help="force remove projects with uncommitted modifications if "
                      "projects no longer exist in the manifest. "
                      "WARNING: this may cause loss of data")
    p.add_option('-l', '--local-only',
                 dest='local_only', action='store_true',
                 help="only update working tree, don't fetch")
    p.add_option('--no-manifest-update', '--nmu',
                 dest='mp_update', action='store_false', default='true',
                 help='use the existing manifest checkout as-is. '
                      '(do not update to the latest revision)')
    p.add_option('-n', '--network-only',
                 dest='network_only', action='store_true',
                 help="fetch only, don't update working tree")
    p.add_option('-d', '--detach',
                 dest='detach_head', action='store_true',
                 help='detach projects back to manifest revision')
    p.add_option('-c', '--current-branch',
                 dest='current_branch_only', action='store_true',
                 help='fetch only current branch from server')
    p.add_option('-v', '--verbose',
                 dest='output_mode', action='store_true',
                 help='show all sync output')
    p.add_option('-q', '--quiet',
                 dest='output_mode', action='store_false',
                 help='only show errors')
    p.add_option('-j', '--jobs',
                 dest='jobs', action='store', type='int',
                 help="projects to fetch simultaneously (default %d)" % self.jobs)
    p.add_option('-m', '--manifest-name',
                 dest='manifest_name',
                 help='temporary manifest to use for this sync', metavar='NAME.xml')
    p.add_option('--clone-bundle', action='store_true',
                 help='enable use of /clone.bundle on HTTP/HTTPS')
    p.add_option('--no-clone-bundle', dest='clone_bundle', action='store_false',
                 help='disable use of /clone.bundle on HTTP/HTTPS')
    p.add_option('-u', '--manifest-server-username', action='store',
                 dest='manifest_server_username',
                 help='username to authenticate with the manifest server')
    p.add_option('-p', '--manifest-server-password', action='store',
                 dest='manifest_server_password',
                 help='password to authenticate with the manifest server')
    p.add_option('--fetch-submodules',
                 dest='fetch_submodules', action='store_true',
                 help='fetch submodules from server')
    p.add_option('--no-tags',
                 dest='tags', default=True, action='store_false',
                 help="don't fetch tags")
    p.add_option('--optimized-fetch',
                 dest='optimized_fetch', action='store_true',
                 help='only fetch projects fixed to sha1 if revision does not exist locally')
    p.add_option('--retry-fetches',
                 default=0, action='store', type='int',
                 help='number of times to retry fetches on transient errors')
    p.add_option('--prune', dest='prune', action='store_true',
                 help='delete refs that no longer exist on the remote')
    if show_smart:
      p.add_option('-s', '--smart-sync',
                   dest='smart_sync', action='store_true',
                   help='smart sync using manifest from the latest known good build')
      p.add_option('-t', '--smart-tag',
                   dest='smart_tag', action='store',
                   help='smart sync using manifest from a known tag')

    RepoHook.AddOptionGroup(p, 'post-sync')

    g = p.add_option_group('repo Version options')
    g.add_option('--no-repo-verify',
                 dest='repo_verify', default=True, action='store_false',
                 help='do not verify repo source code')
    g.add_option('--repo-upgraded',
                 dest='repo_upgraded', action='store_true',
                 help=SUPPRESS_HELP)
Exemple #6
0
    def Execute(self, opt, args):
        project_list = self.GetProjects(args)
        pending = []
        reviewers = []
        cc = []
        branch = None

        if opt.branch:
            branch = opt.branch

        for project in project_list:
            if opt.current_branch:
                cbr = project.CurrentBranch
                up_branch = project.GetUploadableBranch(cbr)
                if up_branch:
                    avail = [up_branch]
                else:
                    avail = None
                    print(
                        "ERROR: Current branch (%s) not uploadable. "
                        "You may be able to type "
                        '"git branch --set-upstream-to m/master" to fix '
                        "your branch." % str(cbr),
                        file=sys.stderr,
                    )
            else:
                avail = project.GetUploadableBranches(branch)
            if avail:
                pending.append((project, avail))

        if not pending:
            if branch is None:
                print("repo: error: no branches ready for upload", file=sys.stderr)
            else:
                print(
                    'repo: error: no branches named "%s" ready for upload' % (branch,),
                    file=sys.stderr,
                )
            return 1

        if not opt.bypass_hooks:
            hook = RepoHook(
                "pre-upload",
                self.manifest.repo_hooks_project,
                self.manifest.topdir,
                self.manifest.manifestProject.GetRemote("origin").url,
                abort_if_user_denies=True,
            )
            pending_proj_names = [project.name for (project, available) in pending]
            pending_worktrees = [project.worktree for (project, available) in pending]
            passed = True
            try:
                hook.Run(
                    opt.allow_all_hooks,
                    project_list=pending_proj_names,
                    worktree_list=pending_worktrees,
                )
            except SystemExit:
                passed = False
                if not opt.ignore_hooks:
                    raise
            except HookError as e:
                passed = False
                print("ERROR: %s" % str(e), file=sys.stderr)

            if not passed:
                if opt.ignore_hooks:
                    print(
                        "\nWARNING: pre-upload hooks failed, but uploading anyways.",
                        file=sys.stderr,
                    )
                else:
                    return 1

        if opt.reviewers:
            reviewers = _SplitEmails(opt.reviewers)
        if opt.cc:
            cc = _SplitEmails(opt.cc)
        people = (reviewers, cc)

        if len(pending) == 1 and len(pending[0][1]) == 1:
            self._SingleBranch(opt, pending[0][1][0], people)
        else:
            self._MultipleBranches(opt, pending, people)
Exemple #7
0
 def _Options(self, p):
     p.add_option('-t',
                  dest='auto_topic',
                  action='store_true',
                  help='send local branch name to Gerrit Code Review')
     p.add_option('--hashtag',
                  '--ht',
                  dest='hashtags',
                  action='append',
                  default=[],
                  help='add hashtags (comma delimited) to the review')
     p.add_option('--hashtag-branch',
                  '--htb',
                  action='store_true',
                  help='add local branch name as a hashtag')
     p.add_option('-l',
                  '--label',
                  dest='labels',
                  action='append',
                  default=[],
                  help='add a label when uploading')
     p.add_option('--re',
                  '--reviewers',
                  type='string',
                  action='append',
                  dest='reviewers',
                  help='request reviews from these people')
     p.add_option('--cc',
                  type='string',
                  action='append',
                  dest='cc',
                  help='also send email to these email addresses')
     p.add_option('--br',
                  '--branch',
                  type='string',
                  action='store',
                  dest='branch',
                  help='(local) branch to upload')
     p.add_option('-c',
                  '--current-branch',
                  dest='current_branch',
                  action='store_true',
                  help='upload current git branch')
     p.add_option('--no-current-branch',
                  dest='current_branch',
                  action='store_false',
                  help='upload all git branches')
     # Turn this into a warning & remove this someday.
     p.add_option('--cbr',
                  dest='current_branch',
                  action='store_true',
                  help=optparse.SUPPRESS_HELP)
     p.add_option('--ne',
                  '--no-emails',
                  action='store_false',
                  dest='notify',
                  default=True,
                  help='do not send e-mails on upload')
     p.add_option('-p',
                  '--private',
                  action='store_true',
                  dest='private',
                  default=False,
                  help='upload as a private change (deprecated; use --wip)')
     p.add_option('-w',
                  '--wip',
                  action='store_true',
                  dest='wip',
                  default=False,
                  help='upload as a work-in-progress change')
     p.add_option('-o',
                  '--push-option',
                  type='string',
                  action='append',
                  dest='push_options',
                  default=[],
                  help='additional push options to transmit')
     p.add_option('-D',
                  '--destination',
                  '--dest',
                  type='string',
                  action='store',
                  dest='dest_branch',
                  metavar='BRANCH',
                  help='submit for review on this target branch')
     p.add_option('-n',
                  '--dry-run',
                  dest='dryrun',
                  default=False,
                  action='store_true',
                  help='do everything except actually upload the CL')
     p.add_option('-y',
                  '--yes',
                  default=False,
                  action='store_true',
                  help='answer yes to all safe prompts')
     p.add_option('--no-cert-checks',
                  dest='validate_certs',
                  action='store_false',
                  default=True,
                  help='disable verifying ssl certs (unsafe)')
     RepoHook.AddOptionGroup(p, 'pre-upload')