From d63d1dde9f08d54d13c625953733fa6aa516604d Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Mon, 9 Nov 2020 18:18:44 +0000 Subject: [PATCH] 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 Reviewed-by: Edward Lesmes --- testing_support/fake_repos.py | 6 ++++++ testing_support/git_test_utils.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/testing_support/fake_repos.py b/testing_support/fake_repos.py index 9e4091ae3..04443421c 100755 --- a/testing_support/fake_repos.py +++ b/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 diff --git a/testing_support/git_test_utils.py b/testing_support/git_test_utils.py index 31e0e787c..5a05385e0 100644 --- a/testing_support/git_test_utils.py +++ b/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]