Exemplo n.º 1
0
def PrepManifestForRepo(git_repo, manifest):
    """Use this to store a local manifest in a git repo suitable for repo.

  The repo tool can only fetch manifests from git repositories. So, to use
  a local manifest file as the basis for a checkout, it must be checked into
  a local git repository.

  Common Usage:
    manifest = CreateOrFetchWondrousManifest()
    with osutils.TempDir() as manifest_git_dir:
      PrepManifestForRepo(manifest_git_dir, manifest)
      repo = RepoRepository(manifest_git_dir, repo_dir)
      repo.Sync()

  Args:
    git_repo: Path at which to create the git repository (directory created, if
              needed). If a tempdir, then cleanup is owned by the caller.
    manifest: Path to existing manifest file to copy into the new git
              repository.
  """
    if not git.IsGitRepo(git_repo):
        git.Init(git_repo)

    new_manifest = os.path.join(git_repo, constants.DEFAULT_MANIFEST)

    shutil.copyfile(manifest, new_manifest)
    git.AddPath(new_manifest)
    message = 'Local repository holding: %s' % manifest

    # Commit new manifest. allow_empty in case it's the same as last manifest.
    git.Commit(git_repo, message, allow_empty=True)
Exemplo n.º 2
0
    def _PrepareProject(self):
        """Make sure the project is synced properly and is ready for pinning."""
        handler = git.ManifestCheckout.Cached(self.repo_root)
        path_to_project_dict = dict(
            ([attrs['path'], project])
            for project, attrs in handler.projects.iteritems())

        # TODO(rcui): Handle case where a dependency never makes it to the manifest
        # (i.e., dep path added as double checkout, and then gets deleted). We need
        # to delete those.  crosbug/22123.
        if not git.IsGitRepo(self.abs_path):
            if self.manifest_rel_path in path_to_project_dict:
                raise ProjectException(
                    '%s in full layout manifest but not in working '
                    "tree. Please run 'repo sync %s'" %
                    (self.manifest_rel_path,
                     path_to_project_dict[self.manifest_rel_path]))
            else:
                cros_build_lib.Warning(
                    'Project %s is not in the manifest.  Automatically checking out '
                    'to %s.\n' % (self.project_url, self.abs_path))
                repository.CloneGitRepo(self.abs_path, self.project_url)
                cros_build_lib.RunCommand(
                    ['git', 'checkout',
                     git.GetGitRepoRevision(self.abs_path)],
                    cwd=self.abs_path)
        elif not _IsGitStoreInRepo(self.abs_path):
            if self.manifest_rel_path in path_to_project_dict:
                # If path is now in the manifest, tell user to manually delete our
                # managed checkout and re-sync.
                raise ProjectException(
                    '%s needs to be replaced.  Please remove the '
                    "directory and run 'repo sync %s'" %
                    (self.manifest_rel_path,
                     path_to_project_dict[self.manifest_rel_path]))
            else:
                # If not managed by Repo we need to perform sync.
                cros_build_lib.RunCommand(
                    ['git', 'pull', '--rebase', self.project_url],
                    cwd=self.abs_path)
        elif not os.path.islink(self.abs_path):
            # Skip symlinks - we don't want to error out for the cros.DEPS projects.
            if self.manifest_rel_path not in path_to_project_dict:
                # If it is 'managed by repo' but not in the manifest, repo tried
                # deleting it but failed because of local changes.
                raise ProjectException(
                    '%s is no longer in the manifest but has local '
                    'changes.  Please remove and try again.' %
                    self.manifest_rel_path)
            elif self.project_name != path_to_project_dict[
                    self.manifest_rel_path]:
                cros_build_lib.Die(
                    '.DEPS.git for %s conflicts with manifest.xml!  Running with '
                    'older .DEPS.git files are not yet supported.  '
                    "Please run'repo sync --jobs=<jobs>' to sync everything up."
                    % self.manifest_rel_path)
Exemplo n.º 3
0
def UpdateGitRepo(working_dir, repo_url, **kwargs):
    """Update the given git repo, blowing away any local changes.

  If the repo does not exist, clone it from scratch.

  Args:
    working_dir: location where it should be cloned to
    repo_url: git repo to clone
    **kwargs: See CloneGitRepo.
  """
    assert not kwargs.get('bare'), 'Bare checkouts are not supported'
    if git.IsGitRepo(working_dir):
        try:
            git.CleanAndCheckoutUpstream(working_dir)
        except cros_build_lib.RunCommandError:
            logging.warning('Could not update %s', working_dir, exc_info=True)
            shutil.rmtree(working_dir)
            CloneGitRepo(working_dir, repo_url, **kwargs)
    else:
        CloneGitRepo(working_dir, repo_url, **kwargs)
Exemplo n.º 4
0
    def SetUp(self):
        """Sets up Chromium repo.

    It skips repo set up if reuse_repo is set and repo exists.
    Setup steps:
    1. Make sure chromium_dir doesn't exist.
    2. mkdir chromium_dir and cd to it
    3. Run "fetch --nohooks chromium"
    4. Set up gclient config ('managed' set to False)
    5. In chromium_dir/src, run "git pull origin master"
    6. "gclient sync --nohooks"
    """
        if self.reuse_repo and os.path.exists(self.repo_dir):
            if git.IsGitRepo(self.repo_dir):
                return
            else:
                raise Exception(
                    'Chromium repo broken. Please manually remove it: %s' %
                    self.chromium_dir)
        if os.path.exists(self.chromium_dir):
            raise Exception(
                'Chromium repo exists. Please manually remove it: %s' %
                self.chromium_dir)

        osutils.SafeMakedirs(self.chromium_dir)
        cros_build_lib.RunCommand(['fetch', '--nohooks', 'chromium'],
                                  cwd=self.chromium_dir,
                                  log_output=True)
        # 'managed' should be set to False. Otherwise, 'gclient sync' will call
        # 'git pull' to ruin bisecting point.
        gclient.WriteConfigFile(self.gclient,
                                self.chromium_dir,
                                True,
                                None,
                                managed=False)

        # Need to perform git pull before gclient sync when managed is set to False.
        git.RunGit(self.repo_dir, ['pull', 'origin', 'master'])
        self.GclientSync(reset=True, nohooks=True)