repository: More debugging on stabilize branch

More debugging changes.  Repo is a hot mess for how we utilize it, which
is basically copying a binary around.  Even a forced upgrade fails due
to a corrupted git repo.  I think we've been getting lucky thus far as
this is the result of us moving to a preload directory.

BUG=None
TEST=None

Change-Id: I02c677909946f6cf76d78bf845662f9536f607e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2658364
Reviewed-by: Mike Nichols <mikenichols@chromium.org>
Commit-Queue: Mike Nichols <mikenichols@chromium.org>
Tested-by: Mike Nichols <mikenichols@chromium.org>
diff --git a/cbuildbot/repository.py b/cbuildbot/repository.py
index 702bffc..10755fa 100644
--- a/cbuildbot/repository.py
+++ b/cbuildbot/repository.py
@@ -124,7 +124,7 @@
   def __init__(self, manifest_repo_url, directory, branch=None,
                referenced_repo=None, manifest=constants.DEFAULT_MANIFEST,
                depth=None, repo_url=None,
-               repo_branch=None, groups=None, repo_cmd='/b/depot_tools/repo',
+               repo_branch=None, groups=None, repo_cmd='repo',
                preserve_paths=(), git_cache_dir=None):
     """Initialize.
 
@@ -201,7 +201,7 @@
         logging.warning('Unable to selfupdate because of warning "%s"',
                         SELFUPDATE_WARNING)
         failed_to_selfupdate = True
-      cmd = [self.repo_cmd, '--version']
+      cmd = [self.repo_cmd, 'version']
       cros_build_lib.run(cmd, cwd=self.directory,
                          capture_output=True, log_output=True)
     except cros_build_lib.RunCommandError as e:
@@ -397,14 +397,11 @@
       manifest_repo_url: A new value for manifest_repo_url.
       extra_args: Extra args to pass to 'repo init'
     """
+    self.repo_cmd = '/preload/chromeos/.repo/repo/repo'
     self.AssertNotNested()
-    cmd = ['which', self.repo_cmd]
-    cros_build_lib.run(cmd, cwd=self.directory,
-                       capture_output=True, log_output=True)
     cmd = [self.repo_cmd, 'version']
-    cros_build_lib.run(cmd, cwd=self.directory,
-                       capture_output=True, log_output=True)
-    self.repo_branch = 'v2.7'
+    cros_build_lib.run(cmd, capture_output=True,
+                       combine_stdout_stderr=True)
     if manifest_repo_url:
       self.manifest_repo_url = manifest_repo_url
 
@@ -427,17 +424,9 @@
     # we can destroy it.
     osutils.SafeUnlink(os.path.join(self.directory, 'local_manifest.xml'))
 
-    # Force a repo update the first time we initialize an old repo checkout.
-    # Don't update if there is nothing to update.
-    if self._repo_update_needed:
-      if IsARepoRoot(self.directory):
-        self._RepoSelfupdate()
-      self._repo_update_needed = False
-
     # Use our own repo, in case android.kernel.org (the default location) is
     # down.
-    init_cmd = [self.repo_cmd, 'init',
-                '--manifest-url', self.manifest_repo_url,
+    init_cmd = [self.repo_cmd, 'init', '--manifest-url', self.manifest_repo_url,
                 '--repo-rev', 'v2.7']
     if self.repo_url:
       init_cmd.extend(['--repo-url', self.repo_url])
@@ -536,10 +525,6 @@
 
     cros_build_lib.run(*args, **kwargs)
 
-  def _InstallDepotTools(self):
-    """Installs depot_tools to have access to a full version of repo."""
-    git.Clone(constants.DEPOT_TOOLS_URL, '/b/depot_tools')
-
   def Sync(self, local_manifest=None, jobs=None, all_branches=True,
            network_only=False, detach=False):
     """Sync/update the source.  Changes manifest if specified.
@@ -562,8 +547,6 @@
         branches.
     """
     try:
-      # Install depot_tools to have a full version of repo.
-      self._InstallDepotTools()
       # Always re-initialize to the current branch.
       self.Initialize(local_manifest)
       # Fix existing broken mirroring configurations.
@@ -575,8 +558,8 @@
       if not all_branches or self._depth is not None:
         # Note that this option can break kernel checkouts. crbug.com/464536
         cmd.append('-c')
-      if self.git_cache_dir is not None:
-        cmd.append('--cache-dir=%s' % self.git_cache_dir)
+      # if self.git_cache_dir is not None:
+      #   cmd.append('--cache-dir=%s' % self.git_cache_dir)
       # Do the network half of the sync; retry as necessary to get the content.
       try:
         if not _IsLocalPath(self.manifest_repo_url):
diff --git a/lib/constants.py b/lib/constants.py
index 6e6152c..aa9664d 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -39,6 +39,7 @@
 DEFAULT_CHROOT_PATH = os.path.join(SOURCE_ROOT, DEFAULT_CHROOT_DIR)
 DEPOT_TOOLS_URL = ('https://chromium.googlesource.com/'
                    'chromium/tools/depot_tools.git')
+REPO_BRANCH = 'v2.7'
 
 # These constants are defined and used in the die_hook that logs failed
 # packages: 'cros_log_failed_packages' in profiles/base/profile.bashrc in
diff --git a/scripts/cbuildbot_launch.py b/scripts/cbuildbot_launch.py
index dfe797f..258e588 100644
--- a/scripts/cbuildbot_launch.py
+++ b/scripts/cbuildbot_launch.py
@@ -344,6 +344,8 @@
     repo: repository.RepoRepository instance.
   """
   logging.PrintBuildbotStepText('Branch: %s' % repo.branch)
+  logging.info('Repo command: %s', repo.repo_cmd)
+  logging.info('Reoo branch: %s', repo.repo_branch)
   logging.info('Bootstrap script starting initial sync on branch: %s',
                repo.branch)
   repo.PreLoad('/preload/chromeos')
@@ -494,7 +496,8 @@
       manifest_url = config_lib.GetSiteParams().MANIFEST_INT_URL
       repo = repository.RepoRepository(manifest_url, buildroot,
                                        branch=branchname,
-                                       git_cache_dir=options.git_cache_dir)
+                                       git_cache_dir=options.git_cache_dir,
+                                       repo_branch=constants.REPO_BRANCH)
       previous_build_state = GetLastBuildState(root)
 
       # Clean up the buildroot to a safe state.