Example #1
0
    def _ProjectBranchName(self, branch, project, original=None):
        """Determine's the git branch name for the project.

    Args:
      branch: The base branch name.
      project: The repo_manfest.Project in question.
      original: Original branch name to remove from the branch suffix.

    Returns:
      The branch name for the project.
    """
        # If project has only one checkout, the base branch name is fine.
        checkouts = [p.name for p in self.checkout.manifest.Projects()]
        if checkouts.count(project.name) == 1:
            return branch

        # Otherwise, the project branch name needs a suffix. We append its
        # upstream or revision to distinguish it from other checkouts.
        suffix = '-' + git.StripRefs(project.upstream or project.Revision())

        # If the revision is itself a branch, we need to strip the old branch name
        # from the suffix to keep naming consistent.
        if original:
            suffix = re.sub('^-%s-' % original, '-', suffix)

        return branch + suffix
Example #2
0
    def __init__(self, path, tracking_branch, remote='origin'):

        tracking_branch = 'refs/remotes/%s/%s' % (
            remote,
            git.StripRefs(tracking_branch),
        )
        attrs = dict(local_path=path,
                     path=path,
                     tracking_branch=tracking_branch)
        self.checkout = git.ProjectCheckout(attrs)
Example #3
0
  def _GetBranchSuffix(self, manifest, checkout):
    """Return the branch suffix for the given checkout.

    If a given project is checked out to multiple locations, it is necessary
    to append a branch suffix. To be safe, we append branch suffixes for all
    repositories that use a non-standard branch name (e.g., if our default
    revision is "master", then any repository which does not use "master"
    has a non-standard branch name.)

    Args:
      manifest: The associated ManifestCheckout.
      checkout: The associated ProjectCheckout.
    """
    # Get the default and tracking branch.
    suffix = ''
    if len(manifest.FindCheckouts(checkout['name'])) > 1:
      default_branch = git.StripRefs(manifest.default['revision'])
      tracking_branch = git.StripRefs(checkout['tracking_branch'])
      suffix = '-%s' % (tracking_branch,)
      if default_branch != 'master':
        suffix = re.sub('^-%s-' % re.escape(default_branch), '-', suffix)
    return suffix
Example #4
0
  def _RunPush(self, checkout, src_ref, dest_ref, force=False):
    """Perform a git push for a checkout.

    Args:
      checkout: A dictionary of checkout manifest attributes.
      src_ref: The source local ref to push to the remote.
      dest_ref: The local remote ref that correspond to destination ref name.
      force: Whether to override non-fastforward checks.
    """
    # Convert local tracking ref to refs/heads/* on a remote:
    # refs/remotes/<remote name>/<branch> to refs/heads/<branch>.
    # If dest_ref is already refs/heads/<branch> it's a noop.
    dest_ref = git.NormalizeRef(git.StripRefs(dest_ref))
    push_to = git.RemoteRef(checkout['push_remote'], dest_ref)
    git.GitPush(checkout['local_path'], src_ref, push_to, force=force,
                skip=self.skip_remote_push)
Example #5
0
    def Create(self, push=False, force=False):
        """Creates a new branch from the given version.

    Branches are always created locally, even when push is true.

    Args:
      push: Whether to push the new branch to remote.
      force: Whether or not to overwrite an existing branch.
    """
        branches = self._ProjectBranches(self.name)

        if not force:
            self._ValidateBranches(branches)

        self._RepairManifestRepositories(branches)
        self._PushBranchesToRemote(branches, dry_run=not push, force=force)

        # Must bump version last because of how VersionInfo is implemented. Sigh...
        which_version = self._WhichVersionShouldBump()
        self.checkout.BumpVersion(which_version,
                                  self.name,
                                  'Bump %s number after creating branch %s.' %
                                  (which_version, self.name),
                                  dry_run=not push)
        # Increment branch/build number for source 'master' branch.
        # manifest_version already does this for release branches.
        # TODO(@jackneus): Make this less of a hack.
        # In reality, this whole tool is being deleted pretty soon.
        if self.__class__.__name__ != 'ReleaseBranch':
            source_version = 'branch' if which_version == 'patch' else 'build'
            # Use the default node's revision if it exists. We stopped writing this
            # for new branches in 2019 though, so this won't be true for newer
            # branches.
            source_ref = self.checkout.manifest.Default().revision
            if not source_ref:
                # Otherwise, use the source version's upstream,
                # e.g. refs/heads/release-R77-12371.B
                source_ref = self.checkout.manifest.GetUniqueProject(
                    'chromeos/manifest-internal').upstream
            self.checkout.BumpVersion(
                source_version,
                git.StripRefs(source_ref),
                'Bump %s number for source branch after creating branch %s' %
                (source_version, self.name),
                dry_run=not push)
Example #6
0
    def _FilterProjectsInManifestByGroup(cls, manifest, groups):
        """Filters projects in |manifest| by |groups|.

    Args:
      manifest: A git.Manifest instance.
      groups: A list of groups to filter.

    Returns:
      A set of (project, branch) tuples where each tuple is asssociated
      with at least one group in |groups|.
    """
        results = set()
        for project, checkout_list in manifest.checkouts_by_name.iteritems():
            for checkout in checkout_list:
                if any(x in checkout['groups'] for x in groups):
                    branch = git.StripRefs(checkout['tracking_branch'])
                    results.add((project, branch))

        return results