Пример #1
0
        def RunCleanupCommands(project, cwd):
            with locking.FileLock(lock_path,
                                  verbose=False).read_lock() as lock:
                # Calculate where the git repository is stored.
                relpath = os.path.relpath(cwd, self.directory)
                projects_dir = os.path.join(self.directory, '.repo',
                                            'projects')
                project_objects_dir = os.path.join(self.directory, '.repo',
                                                   'project-objects')
                repo_git_store = '%s.git' % os.path.join(projects_dir, relpath)
                repo_obj_store = '%s.git' % os.path.join(
                    project_objects_dir, project)

                try:
                    if os.path.isdir(cwd):
                        git.CleanAndDetachHead(cwd)

                    if os.path.isdir(repo_git_store):
                        git.GarbageCollection(repo_git_store,
                                              prune_all=prune_all)
                except cros_build_lib.RunCommandError as e:
                    result = e.result
                    logging.PrintBuildbotStepWarnings()
                    logging.warning('\n%s', result.error)

                    # If there's no repository corruption, just delete the index.
                    corrupted = git.IsGitRepositoryCorrupted(repo_git_store)
                    lock.write_lock()
                    logging.warning('Deleting %s because %s failed', cwd,
                                    result.cmd)
                    osutils.RmDir(cwd, ignore_missing=True, sudo=True)
                    if corrupted:
                        # Looks like the object dir is corrupted. Delete it.
                        deleted_objdirs.set()
                        for store in (repo_git_store, repo_obj_store):
                            logging.warning('Deleting %s as well', store)
                            osutils.RmDir(store, ignore_missing=True)

                # TODO: Make the deletions below smarter. Look to see what exists,
                # instead of just deleting things we think might be there.

                # Delete all branches created by cbuildbot.
                if os.path.isdir(repo_git_store):
                    cmd = ['branch', '-D'] + list(constants.CREATED_BRANCHES)
                    # Ignore errors, since we delete branches without checking existence.
                    git.RunGit(repo_git_store, cmd, error_code_ok=True)

                if os.path.isdir(cwd):
                    # Above we deleted refs/heads/<branch> for each created branch, now we
                    # need to delete the bare ref <branch> if it was created somehow.
                    for ref in constants.CREATED_BRANCHES:
                        # Ignore errors, since we delete branches without checking
                        # existence.
                        git.RunGit(cwd, ['update-ref', '-d', ref],
                                   error_code_ok=True)
 def PerformStage(self):
     logging.info('Update configs for branch %s, template gs path %s',
                  self.branch, self.template_gs_path)
     try:
         self._CheckoutBranch()
         self._SetupConfigPaths()
         self._DownloadTemplate()
         self._RunUnitTest()
         if self._ContainsConfigUpdates():
             self._PushCommits()
         else:
             logging.info(
                 'Nothing changed. No need to update configs for %s',
                 self.template_gs_path)
     finally:
         git.CleanAndDetachHead(self.chromite_dir)
Пример #3
0
 def PerformStage(self):
     logging.info('Update configs for branch %s, template gs path %s',
                  self.branch, self.template_gs_path)
     candidate_files = [
         self.GE_CONFIG_LOCAL_PATH, self.CONFIG_DUMP_PATH,
         self.WATERFALL_DUMP_PATH
     ]
     try:
         self._CheckoutBranch()
         self._DownloadTemplate()
         self._UpdateConfigDump()
         self._RunUnitTest()
         if self._ContainsUpdates(candidate_files):
             self._PushCommits(candidate_files)
         else:
             logging.info(
                 'Nothing changed. No need to update configs for %s',
                 self.template_gs_path)
     finally:
         git.CleanAndDetachHead(self.chromite_dir)