예제 #1
0
 def _RunGitPush():
     """Runs git.GitPush with some default arguments."""
     git.GitPush('some_repo_path',
                 'local-ref',
                 git.RemoteRef('some-remote', 'remote-ref'),
                 retry=True,
                 skip=False)
예제 #2
0
    def _FixUpManifests(self, repo_manifest):
        """Points the checkouts at the new branch in the manifests.

    Within the branch, make sure all manifests with projects that are
    "branchable" are checked out to "refs/heads/<new_branch>".  Do this
    by updating all manifests in the known manifest projects.
    """
        assert not self._run.options.delete_branch, 'Cannot fix a deleted branch.'

        # Use local branch ref.
        branch_ref = git.NormalizeRef(self.branch_name)

        logging.debug('Fixing manifest projects for new branch.')
        for project in site_config.params.MANIFEST_PROJECTS:
            manifest_checkout = repo_manifest.FindCheckout(project)
            manifest_dir = manifest_checkout['local_path']
            push_remote = manifest_checkout['push_remote']

            # Checkout revision can be either a sha1 or a branch ref.
            src_ref = manifest_checkout['revision']
            if not git.IsSHA1(src_ref):
                src_ref = git.NormalizeRemoteRef(push_remote, src_ref)

            git.CreateBranch(manifest_dir, manifest_version.PUSH_BRANCH,
                             src_ref)

            # We want to process default.xml and official.xml + their imports.
            pending_manifests = [
                constants.DEFAULT_MANIFEST, constants.OFFICIAL_MANIFEST
            ]
            processed_manifests = []

            while pending_manifests:
                # Canonicalize the manifest name (resolve dir and symlinks).
                manifest_path = os.path.join(manifest_dir,
                                             pending_manifests.pop())
                manifest_path = os.path.realpath(manifest_path)

                # Don't process a manifest more than once.
                if manifest_path in processed_manifests:
                    continue

                processed_manifests.append(manifest_path)

                if not os.path.exists(manifest_path):
                    logging.info('Manifest not found: %s', manifest_path)
                    continue

                logging.debug('Fixing manifest at %s.', manifest_path)
                included_manifests = self._UpdateManifest(manifest_path)
                pending_manifests += included_manifests

            git.RunGit(manifest_dir, ['add', '-A'], print_cmd=True)
            message = 'Fix up manifest after branching %s.' % branch_ref
            git.RunGit(manifest_dir, ['commit', '-m', message], print_cmd=True)
            push_to = git.RemoteRef(push_remote, branch_ref)
            git.GitPush(manifest_dir,
                        manifest_version.PUSH_BRANCH,
                        push_to,
                        skip=self.skip_remote_push)
예제 #3
0
def _PushGitChanges(git_repo, message, dry_run=False, push_to=None):
    """Push the final commit into the git repo.

  Args:
    git_repo: git repo to push
    message: Commit message
    dry_run: If true, don't actually push changes to the server
    push_to: A git.RemoteRef object specifying the remote branch to push to.
      Defaults to the tracking branch of the current branch.
  """
    if push_to is None:
        # TODO(akeshet): Clean up git.GetTrackingBranch to always or never return a
        # tuple.
        # pylint: disable=unpacking-non-sequence
        push_to = git.GetTrackingBranch(git_repo,
                                        for_checkout=False,
                                        for_push=True)

    git.RunGit(git_repo, ['add', '-A'])

    # It's possible that while we are running on dry_run, someone has already
    # committed our change.
    try:
        git.RunGit(git_repo, ['commit', '-m', message])
    except cros_build_lib.RunCommandError:
        if dry_run:
            return
        raise

    git.GitPush(git_repo, PUSH_BRANCH, push_to, skip=dry_run)
예제 #4
0
def _PushGitChanges(git_repo, message, dry_run=True, push_to=None):
    """Push the final commit into the git repo.

  Args:
    git_repo: git repo to push
    message: Commit message
    dry_run: If true, don't actually push changes to the server
    push_to: A git.RemoteRef object specifying the remote branch to push to.
      Defaults to the tracking branch of the current branch.
  """
    push_branch = None
    if push_to is None:
        remote, push_branch = git.GetTrackingBranch(git_repo,
                                                    for_checkout=False,
                                                    for_push=True)
        push_to = git.RemoteRef(remote, push_branch)

    git.RunGit(git_repo, ['add', '-A'])

    # It's possible that while we are running on dry_run, someone has already
    # committed our change.
    try:
        git.RunGit(git_repo, ['commit', '-m', message])
    except cros_build_lib.RunCommandError:
        if dry_run:
            return
        raise

    git.GitPush(git_repo, PUSH_BRANCH, push_to, dryrun=dry_run, force=dry_run)
 def testGitPushSimple(self):
     """Test GitPush with minimal arguments."""
     git.GitPush('git_path', 'HEAD', git.RemoteRef('origin', 'master'))
     self.assertCommandCalled(['git', 'push', 'origin', 'HEAD:master'],
                              capture_output=True,
                              print_cmd=False,
                              cwd='git_path',
                              encoding='utf-8')
예제 #6
0
 def testGitPushComplix(self):
   """Test GitPush with some arguments."""
   git.GitPush('git_path', 'HEAD', git.RemoteRef('origin', 'master'),
               force=True, dry_run=True)
   self.assertCommandCalled(['git', 'push', 'origin', 'HEAD:master',
                             '--force', '--dry-run'],
                            capture_output=True, print_cmd=False,
                            cwd='git_path', encoding='utf-8')
예제 #7
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)
def _GitPushProjectUpstream(repo_root, project, dry_run):
    """Push the project revision to its remote upstream."""
    git.GitPush(os.path.join(repo_root, project.Path()),
                project.revision,
                git.RemoteRef(project.Remote().GitName(), project.upstream),
                dry_run=dry_run)