Browse Source

Set default branch in fake_repos

Tests should start to rely on fake_repos.DEFAULT_BRANCH so it can be
renamed in the future. This is a quick fix in case
git.init.defaultBranch is set to a custom value.

Bug: 1144918
Change-Id: I1c8cd591bee6b5fe14a5de4683111a89224cb2b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2521655
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Josip Sokcevic 4 years ago
parent
commit
d63d1dde9f
2 changed files with 11 additions and 0 deletions
  1. 6 0
      testing_support/fake_repos.py
  2. 5 0
      testing_support/git_test_utils.py

+ 6 - 0
testing_support/fake_repos.py

@@ -28,6 +28,8 @@ import gclient_utils
 import scm
 import subprocess2
 
+DEFAULT_BRANCH = 'master'
+
 
 def write(path, content):
   f = open(path, 'wb')
@@ -160,7 +162,11 @@ class FakeReposBase(object):
     except (OSError, subprocess2.CalledProcessError):
       return False
     for repo in ['repo_%d' % r for r in range(1, self.NB_GIT_REPOS + 1)]:
+      # TODO(crbug.com/114712) use git.init -b and remove 'checkout' once git is
+      # upgraded to 2.28 on all builders.
       subprocess2.check_call(['git', 'init', '-q', join(self.git_base, repo)])
+      subprocess2.check_call(['git', 'checkout', '-q', '-b', DEFAULT_BRANCH],
+                             cwd=join(self.git_base, repo))
       self.git_hashes[repo] = [(None, None)]
     self.populateGit()
     self.initialized = True

+ 5 - 0
testing_support/git_test_utils.py

@@ -18,6 +18,8 @@ import unittest
 import gclient_utils
 
 
+DEFAULT_BRANCH = 'master'
+
 if sys.version_info.major == 3:
   # pylint: disable=redefined-builtin
   basestring = (str,)
@@ -297,9 +299,12 @@ class GitRepo(object):
 
     self.to_schema_refs = ['--branches']
 
+    # TODO(crbug.com/114712) use git.init -b and remove 'checkout' once git is
+    # upgraded to 2.28 on all builders.
     self.git('init')
     self.git('config', 'user.name', 'testcase')
     self.git('config', 'user.email', 'testcase@example.com')
+    self.git('checkout', '-b', DEFAULT_BRANCH)
     for commit in schema.walk():
       self._add_schema_commit(commit, schema.data_for(commit.name))
       self.last_commit = self[commit.name]