def RefreshManifestCheckout(manifest_dir, manifest_repo): """Checks out manifest-versions into the manifest directory. If a repository is already present, it will be cleansed of any local changes and restored to its pristine state, checking out the origin. """ reinitialize = True if os.path.exists(manifest_dir): result = git.RunGit(manifest_dir, ['config', 'remote.origin.url'], error_code_ok=True) if (result.returncode == 0 and result.output.rstrip() == manifest_repo): logging.info('Updating manifest-versions checkout.') try: git.RunGit(manifest_dir, ['gc', '--auto']) git.CleanAndCheckoutUpstream(manifest_dir) except cros_build_lib.RunCommandError: logging.warning('Could not update manifest-versions checkout.') else: reinitialize = False else: logging.info('No manifest-versions checkout exists at %s', manifest_dir) if reinitialize: logging.info('Cloning fresh manifest-versions checkout.') osutils.RmDir(manifest_dir, ignore_missing=True) repository.CloneGitRepo(manifest_dir, manifest_repo)
def _AdjustRepoCheckoutToLocalManifest(self, manifest_path): """Re-checkout repository based on patched internal manifest repository. This method clones the current state of 'manifest-internal' into a temp location, and then re-sync's the current repository to that manifest. This is intended to allow sync'ing with test manifest CLs included. It does NOT clean up afterwards. Args: manifest_path: Directory containing the already patched manifest. Normally SOURCE_ROOT/manifest or SOURCE_ROOT/manifest-internal. """ tmp_manifest_repo = tempfile.mkdtemp(prefix='patched_manifest') logging.info('Cloning manifest repository from %s to %s.', manifest_path, tmp_manifest_repo) repository.CloneGitRepo(tmp_manifest_repo, manifest_path) git.CreateBranch(tmp_manifest_repo, self.cros_source.branch or 'master') logging.info('Switching to local patched manifest repository:') logging.info('TMPDIR: %s', tmp_manifest_repo) logging.info(' %s', os.listdir(tmp_manifest_repo)) self.cros_source.Initialize(manifest_repo_url=tmp_manifest_repo) self.cros_source.Sync(detach=True)
def _SetupMirrors(self): mirror = os.path.join(self.tempdir, 'tryjobs_mirror') os.mkdir(mirror) url = '%s/%s' % (site_config.params.EXTERNAL_GOB_URL, 'chromiumos/tryjobs') repository.CloneGitRepo(mirror, url, bare=True) self.ext_mirror = mirror mirror = os.path.join(self.tempdir, 'tryjobs_int_mirror') os.mkdir(mirror) repository.CloneGitRepo(mirror, self.ext_mirror, reference=self.ext_mirror, bare=True) self.int_mirror = mirror RemoteTryJobMock.EXTERNAL_URL = self.ext_mirror RemoteTryJobMock.INTERNAL_URL = self.int_mirror self._SetMirrorVersion(remote_try.RemoteTryJob.TRYJOB_FORMAT_VERSION, True)
def _SetupWorkDirectoryForPatch(work_dir, patch, branch, manifest, email): """Set up local dir for uploading changes to the given patch's project.""" logging.notice('Setting up dir %s for uploading changes to %s', work_dir, patch.project_url) # Clone the git repo from reference if we have a pointer to a # ManifestCheckout object. reference = None if manifest: # Get the path to the first checkout associated with this change. Since # all of the checkouts share git objects, it doesn't matter which checkout # we pick. path = manifest.FindCheckouts(patch.project, only_patchable=True)[0]['path'] reference = os.path.join(constants.SOURCE_ROOT, path) if not os.path.isdir(reference): logging.error('Unable to locate git checkout: %s', reference) logging.error('Did you mean to use --nomirror?') # This will do an "raise OSError" with the right values. os.open(reference, os.O_DIRECTORY) # Use the email if email wasn't specified. if not email: email = git.GetProjectUserEmail(reference) repository.CloneGitRepo(work_dir, patch.project_url, reference=reference) # Set the git committer. git.RunGit(work_dir, ['config', '--replace-all', 'user.email', email]) mbranch = git.MatchSingleBranchName(work_dir, branch, namespace='refs/remotes/origin/') if branch != mbranch: logging.notice('Auto resolved branch name "%s" to "%s"', branch, mbranch) branch = mbranch # Finally, create a local branch for uploading changes to the given remote # branch. git.CreatePushBranch(constants.PATCH_BRANCH, work_dir, sync=False, remote_push_branch=git.RemoteRef( 'ignore', 'origin/%s' % branch)) return branch
def CloneWorkingRepo(dest, url, reference, branch): """Clone a git repository with an existing local copy as a reference. Also copy the hooks into the new repository. Args: dest: The directory to clone int. url: The URL of the repository to clone. reference: Local checkout to draw objects from. branch: The branch to clone. """ repository.CloneGitRepo(dest, url, reference=reference, single_branch=True, branch=branch) for name in glob.glob(os.path.join(reference, '.git', 'hooks', '*')): newname = os.path.join(dest, '.git', 'hooks', os.path.basename(name)) shutil.copyfile(name, newname) shutil.copystat(name, newname)