Commit 7e133ff1 authored by Josip Sokcevic's avatar Josip Sokcevic Committed by LUCI CQ

Use main branch as the default branch

R=apolito@google.com

Change-Id: I6a2ed557b9e8d45194b2fe4ea5327ce62020733c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3000134Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
parent 9eee47a8
......@@ -252,7 +252,7 @@ class GitWrapper(SCMWrapper):
def diff(self, options, _args, _file_list):
_, revision = gclient_utils.SplitUrlRevision(self.url)
if not revision:
revision = 'refs/remotes/%s/master' % self.remote
revision = 'refs/remotes/%s/main' % self.remote
self._Run(['-c', 'core.quotePath=false', 'diff', revision], options)
def pack(self, _options, _args, _file_list):
......@@ -866,7 +866,7 @@ class GitWrapper(SCMWrapper):
# Don't reuse the args.
return self.update(options, [], file_list)
default_rev = "refs/heads/master"
default_rev = "refs/heads/main"
if options.upstream:
if self._GetCurrentBranch():
upstream_branch = scm.GIT.GetUpstreamBranch(self.checkout_path)
......
......@@ -104,8 +104,8 @@ TRACES_README_FORMAT = (
POSTUPSTREAM_HOOK = '.git/hooks/post-cl-land'
DESCRIPTION_BACKUP_FILE = '.git_cl_description_backup'
REFS_THAT_ALIAS_TO_OTHER_REFS = {
'refs/remotes/origin/lkgr': 'refs/remotes/origin/master',
'refs/remotes/origin/lkcr': 'refs/remotes/origin/master',
'refs/remotes/origin/lkgr': 'refs/remotes/origin/main',
'refs/remotes/origin/lkcr': 'refs/remotes/origin/main',
}
DEFAULT_OLD_BRANCH = 'refs/remotes/origin/master'
......
......@@ -707,7 +707,7 @@ def upstream_default():
pass
return ret
except subprocess2.CalledProcessError:
return 'origin/master'
return 'origin/main'
def root():
......
......@@ -216,7 +216,7 @@ class GIT(object):
except subprocess2.CalledProcessError:
pass
# Return default branch
return 'refs/remotes/%s/master' % remote
return 'refs/remotes/%s/main' % remote
@staticmethod
def GetBranch(cwd):
......
......@@ -28,7 +28,7 @@ import gclient_utils
import scm
import subprocess2
DEFAULT_BRANCH = 'master'
DEFAULT_BRANCH = 'main'
def write(path, content):
......
......@@ -18,7 +18,7 @@ import unittest
import gclient_utils
DEFAULT_BRANCH = 'master'
DEFAULT_BRANCH = 'main'
if sys.version_info.major == 3:
# pylint: disable=redefined-builtin
......@@ -138,7 +138,7 @@ class GitRepoSchema(object):
Every commit gets a tag 'tag_%(commit)s'
Every unique terminal commit gets a branch 'branch_%(commit)s'
Last commit in First line is the branch 'master'
Last commit in First line is the branch 'main'
Root commits get a ref 'root_%(commit)s'
Timestamps are in topo order, earlier commits (as indicated by their presence
......@@ -160,7 +160,7 @@ class GitRepoSchema(object):
commit_name). See the docstring on the GitRepo class for the format of
the data returned by this function.
"""
self.master = None
self.main = None
self.par_map = {}
self.data_cache = {}
self.content_fn = content_fn
......@@ -207,8 +207,8 @@ class GitRepoSchema(object):
for commit in commits:
self.add_partial(commit, parent)
parent = commit
if parent and not self.master:
self.master = parent
if parent and not self.main:
self.main = parent
for _ in self.walk(): # This will throw if there are any cycles.
pass
......@@ -308,8 +308,8 @@ class GitRepo(object):
for commit in schema.walk():
self._add_schema_commit(commit, schema.data_for(commit.name))
self.last_commit = self[commit.name]
if schema.master:
self.git('update-ref', 'refs/heads/master', self[schema.master])
if schema.main:
self.git('update-ref', 'refs/heads/main', self[schema.main])
def __getitem__(self, commit_name):
"""Gets the hash of a commit by its schema name.
......
......@@ -296,7 +296,7 @@ class GClientSmokeGIT(gclient_smoketest_base.GClientSmokeBase):
'sync', '-v', '-v', '-v',
'--revision', 'src/repo2@%s' % self.githash('repo_2', 1),
'--patch-ref',
'%srepo_2@refs/heads/master:%s' % (
'%srepo_2@refs/heads/main:%s' % (
self.git_base, self.githash('repo_2', 2)),
])
# Assert that repo_2 files coincide with revision @2 (the patch ref)
......@@ -318,7 +318,7 @@ class GClientSmokeGIT(gclient_smoketest_base.GClientSmokeBase):
'sync', '-v', '-v', '-v',
'--revision', 'src/repo2@%s' % self.githash('repo_2', 1),
'--patch-ref',
'%srepo_2@refs/heads/master:%s' % (
'%srepo_2@refs/heads/main:%s' % (
self.git_base, self.githash('repo_2', 2)),
'--nohooks',
])
......
......@@ -112,8 +112,8 @@ mark :2
data 4
Bye
reset refs/heads/master
commit refs/heads/master
reset refs/heads/main
commit refs/heads/main
mark :3
author Bob <bob@example.com> 1253744361 -0700
committer Bob <bob@example.com> 1253744361 -0700
......@@ -158,7 +158,7 @@ Add C
from :3
M 100644 :7 c
reset refs/heads/master
reset refs/heads/main
from :3
"""
def Options(self, *args, **kwargs):
......@@ -186,9 +186,9 @@ from :3
cwd=path).communicate()
Popen([GIT, 'remote', 'add', '-f', 'origin', '.'], stdout=PIPE,
stderr=STDOUT, cwd=path).communicate()
Popen([GIT, 'checkout', '-b', 'new', 'origin/master', '-q'], stdout=PIPE,
Popen([GIT, 'checkout', '-b', 'new', 'origin/main', '-q'], stdout=PIPE,
stderr=STDOUT, cwd=path).communicate()
Popen([GIT, 'push', 'origin', 'origin/origin:origin/master', '-q'],
Popen([GIT, 'push', 'origin', 'origin/origin:origin/main', '-q'],
stdout=PIPE, stderr=STDOUT, cwd=path).communicate()
Popen([GIT, 'config', '--unset', 'remote.origin.fetch'], stdout=PIPE,
stderr=STDOUT, cwd=path).communicate()
......@@ -196,8 +196,8 @@ from :3
stderr=STDOUT, cwd=path).communicate()
Popen([GIT, 'config', 'user.name', 'Some User'], stdout=PIPE,
stderr=STDOUT, cwd=path).communicate()
# Set HEAD back to master
Popen([GIT, 'checkout', 'master', '-q'],
# Set HEAD back to main
Popen([GIT, 'checkout', 'main', '-q'],
stdout=PIPE,
stderr=STDOUT,
cwd=path).communicate()
......@@ -393,7 +393,7 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
parent = 'HEAD^' if sys.platform != 'win32' else 'HEAD^^'
self.assertEqual(scm._Capture(['rev-parse', parent + '1']), rev)
self.assertEqual(scm._Capture(['rev-parse', parent + '2']),
scm._Capture(['rev-parse', 'origin/master']))
scm._Capture(['rev-parse', 'origin/main']))
sys.stdout.close()
def testUpdateRebase(self):
......@@ -417,7 +417,7 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
'd2e35c10ac24d6c621e14a1fcadceb533155627d')
parent = 'HEAD^' if sys.platform != 'win32' else 'HEAD^^'
self.assertEqual(scm._Capture(['rev-parse', parent + '1']),
scm._Capture(['rev-parse', 'origin/master']))
scm._Capture(['rev-parse', 'origin/main']))
sys.stdout.close()
def testUpdateReset(self):
......@@ -561,7 +561,7 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
scm.update(options, (), [])
self.assertEqual(
e.exception.args[0],
'\n____ . at refs/remotes/origin/master\n'
'\n____ . at refs/remotes/origin/main\n'
'\tYou have unstaged changes.\n'
'\tPlease commit, stash, or reset.\n')
......@@ -758,7 +758,7 @@ class UnmanagedGitWrapperTestCase(BaseGitWrapperTestCase):
# indicates detached HEAD
self.assertEqual(self.getCurrentBranch(), None)
self.checkInStdout(
'Checked out refs/remotes/origin/master to a detached HEAD')
'Checked out refs/remotes/origin/main to a detached HEAD')
def testUpdateCloneOnCommit(self):
......@@ -1000,11 +1000,11 @@ class BranchHeadsFakeRepo(fake_repos.FakeReposBase):
# |
# 4
# |
# 1--2--3 refs/heads/master
# 1--2--3 refs/heads/main
self._commit_git('repo_1', {'commit 1': 'touched'})
self._commit_git('repo_1', {'commit 2': 'touched'})
self._commit_git('repo_1', {'commit 3': 'touched'})
self._create_ref('repo_1', 'refs/heads/master', 3)
self._create_ref('repo_1', 'refs/heads/main', 3)
self._commit_git('repo_1', {'commit 4': 'touched'}, base=2)
self._commit_git('repo_1', {'commit 5': 'touched'}, base=2)
......@@ -1073,9 +1073,9 @@ class GerritChangesFakeRepo(fake_repos.FakeReposBase):
# |
# 5 refs/changes/34/1234/1
# |
# 1--2--3--4 refs/heads/master
# 1--2--3--4 refs/heads/main
# | |
# | 11(5)--12 refs/heads/master-with-5
# | 11(5)--12 refs/heads/main-with-5
# |
# 7--8--9 refs/heads/feature
# |
......@@ -1086,7 +1086,7 @@ class GerritChangesFakeRepo(fake_repos.FakeReposBase):
self._commit_git('repo_1', {'commit 2': 'touched'})
self._commit_git('repo_1', {'commit 3': 'touched'})
self._commit_git('repo_1', {'commit 4': 'touched'})
self._create_ref('repo_1', 'refs/heads/master', 4)
self._create_ref('repo_1', 'refs/heads/main', 4)
# Create a change on top of commit 3 that consists of two commits.
self._commit_git('repo_1',
......@@ -1113,7 +1113,7 @@ class GerritChangesFakeRepo(fake_repos.FakeReposBase):
base=8)
self._create_ref('repo_1', 'refs/changes/36/1236/1', 10)
# Create a refs/heads/master-with-5 on top of commit 3 which is a branch
# Create a refs/heads/main-with-5 on top of commit 3 which is a branch
# where refs/changes/34/1234/1 (commit 5) has already landed as commit 11.
self._commit_git('repo_1',
# This is really commit 11, but has the changes of commit 5
......@@ -1121,7 +1121,7 @@ class GerritChangesFakeRepo(fake_repos.FakeReposBase):
'change': '1234'},
base=3)
self._commit_git('repo_1', {'commit 12': 'touched'})
self._create_ref('repo_1', 'refs/heads/master-with-5', 12)
self._create_ref('repo_1', 'refs/heads/main-with-5', 12)
class GerritChangesTest(fake_repos.FakeReposTestBase):
......@@ -1202,7 +1202,7 @@ class GerritChangesTest(fake_repos.FakeReposTestBase):
self.assertEqual(push_url, self.url)
def testAppliesPatchOnTopOfMasterByDefault(self):
"""Test the default case, where we apply a patch on top of master."""
"""Test the default case, where we apply a patch on top of main."""
scm = gclient_scm.GitWrapper(self.url, self.root_dir, '.')
file_list = []
......@@ -1212,7 +1212,7 @@ class GerritChangesTest(fake_repos.FakeReposTestBase):
self.assertEqual(self.githash('repo_1', 4), self.gitrevparse(self.root_dir))
scm.apply_patch_ref(
self.url, 'refs/changes/35/1235/1', 'refs/heads/master', self.options,
self.url, 'refs/changes/35/1235/1', 'refs/heads/main', self.options,
file_list)
self.assertCommits([1, 2, 3, 4, 5, 6])
......@@ -1235,14 +1235,14 @@ class GerritChangesTest(fake_repos.FakeReposTestBase):
# Apply the change on top of that.
scm.apply_patch_ref(
self.url, 'refs/changes/35/1235/1', 'refs/heads/master', self.options,
self.url, 'refs/changes/35/1235/1', 'refs/heads/main', self.options,
file_list)
self.assertCommits([1, 5, 6])
self.assertEqual(self.githash('repo_1', 1), self.gitrevparse(self.root_dir))
def testCheckoutOriginFeature(self):
"""Tests that we can apply a patch on a branch other than master."""
"""Tests that we can apply a patch on a branch other than main."""
scm = gclient_scm.GitWrapper(self.url, self.root_dir, '.')
file_list = []
......@@ -1261,7 +1261,7 @@ class GerritChangesTest(fake_repos.FakeReposTestBase):
def testCheckoutOriginFeatureOnOldRevision(self):
"""Tests that we can apply a patch on an old checkout, on a branch other
than master."""
than main."""
scm = gclient_scm.GitWrapper(self.url, self.root_dir, '.')
file_list = []
......@@ -1276,7 +1276,7 @@ class GerritChangesTest(fake_repos.FakeReposTestBase):
file_list)
# We shouldn't have rebased on top of 2 (which is the merge base between
# remote's master branch and the change) but on top of 7 (which is the
# remote's main branch and the change) but on top of 7 (which is the
# merge base between remote's feature branch and the change).
self.assertCommits([1, 2, 7, 10])
self.assertEqual(self.githash('repo_1', 7), self.gitrevparse(self.root_dir))
......@@ -1290,10 +1290,10 @@ class GerritChangesTest(fake_repos.FakeReposTestBase):
scm.update(self.options, None, file_list)
self.assertEqual(self.githash('repo_1', 9), self.gitrevparse(self.root_dir))
# Apply refs/changes/34/1234/1, created for remote's master branch on top of
# Apply refs/changes/34/1234/1, created for remote's main branch on top of
# remote's feature branch.
scm.apply_patch_ref(
self.url, 'refs/changes/35/1235/1', 'refs/heads/master', self.options,
self.url, 'refs/changes/35/1235/1', 'refs/heads/main', self.options,
file_list)
# Commits 5 and 6 are part of the patch, and commits 1, 2, 7, 8 and 9 are
......@@ -1313,7 +1313,7 @@ class GerritChangesTest(fake_repos.FakeReposTestBase):
# Apply the change on top of that.
scm.apply_patch_ref(
self.url, 'refs/changes/35/1235/1', 'refs/heads/master', self.options,
self.url, 'refs/changes/35/1235/1', 'refs/heads/main', self.options,
file_list)
self.assertCommits([1, 2, 3, 5, 6])
......@@ -1333,7 +1333,7 @@ class GerritChangesTest(fake_repos.FakeReposTestBase):
# Apply the change on top of that.
scm.apply_patch_ref(
self.url, 'refs/changes/35/1235/1', 'refs/heads/master', self.options,
self.url, 'refs/changes/35/1235/1', 'refs/heads/main', self.options,
file_list)
self.assertCommits([1, 2, 3, 5, 6])
......@@ -1349,7 +1349,7 @@ class GerritChangesTest(fake_repos.FakeReposTestBase):
self.assertEqual(self.githash('repo_1', 4), self.gitrevparse(self.root_dir))
scm.apply_patch_ref(
self.url, 'refs/changes/35/1235/1', 'refs/heads/master', self.options,
self.url, 'refs/changes/35/1235/1', 'refs/heads/main', self.options,
file_list)
self.assertCommits([1, 2, 3, 4, 5, 6])
......@@ -1370,7 +1370,7 @@ class GerritChangesTest(fake_repos.FakeReposTestBase):
# patch 'refs/changes/36/1236/1' creates a patch failure.
with self.assertRaises(subprocess2.CalledProcessError) as cm:
scm.apply_patch_ref(
self.url, 'refs/changes/36/1236/1', 'refs/heads/master', self.options,
self.url, 'refs/changes/36/1236/1', 'refs/heads/main', self.options,
file_list)
self.assertEqual(cm.exception.cmd[:2], ['git', 'cherry-pick'])
self.assertIn(b'error: could not apply', cm.exception.stderr)
......@@ -1378,7 +1378,7 @@ class GerritChangesTest(fake_repos.FakeReposTestBase):
# Try to apply 'refs/changes/35/1235/1', which doesn't have a merge
# conflict.
scm.apply_patch_ref(
self.url, 'refs/changes/35/1235/1', 'refs/heads/master', self.options,
self.url, 'refs/changes/35/1235/1', 'refs/heads/main', self.options,
file_list)
self.assertCommits([1, 2, 3, 5, 6])
self.assertEqual(self.githash('repo_1', 5), self.gitrevparse(self.root_dir))
......@@ -1387,7 +1387,7 @@ class GerritChangesTest(fake_repos.FakeReposTestBase):
scm = gclient_scm.GitWrapper(self.url, self.root_dir, '.')
file_list = []
self.options.revision = 'refs/heads/master-with-5'
self.options.revision = 'refs/heads/main-with-5'
scm.update(self.options, None, file_list)
self.assertEqual(self.githash('repo_1', 12),
self.gitrevparse(self.root_dir))
......@@ -1421,7 +1421,7 @@ class GerritChangesTest(fake_repos.FakeReposTestBase):
# Try to apply 'refs/changes/35/1235/1', which doesn't have a merge
# conflict.
scm.apply_patch_ref(
self.url, 'refs/changes/35/1235/1', 'refs/heads/master', self.options,
self.url, 'refs/changes/35/1235/1', 'refs/heads/main', self.options,
file_list)
self.assertCommits([1, 2, 3, 5, 6])
self.assertEqual(self.githash('repo_1', 5), self.gitrevparse(self.root_dir))
......
......@@ -96,7 +96,7 @@ class ChangelistMock(object):
class GitMocks(object):
def __init__(self, config=None, branchref=None):
self.branchref = branchref or 'refs/heads/master'
self.branchref = branchref or 'refs/heads/main'
self.config = config or {}
def GetBranchRef(self, _root):
......@@ -265,11 +265,11 @@ class TestGitClBasic(unittest.TestCase):
mock.patch('git_cl.Changelist.GetGerritProject',
return_value='foo').start()
mock.patch('git_cl.gerrit_util.GetProjectHead',
return_value='refs/heads/master').start()
return_value='refs/heads/main').start()
cl = git_cl.Changelist()
options = optparse.Values()
options.target_branch = 'refs/heads/master'
options.target_branch = 'refs/heads/main'
with self.assertRaises(SystemExitMock):
cl.CMDUploadChange(options, [], 'foo', git_cl.ChangeDescription('bar'))
......@@ -280,27 +280,6 @@ class TestGitClBasic(unittest.TestCase):
self.assertFalse(hasattr(options, 'force'))
self.assertFalse(hasattr(options, 'edit_description'))
def test_upload_to_old_default_retry_on_failure(self):
m = mock.patch('git_cl.Changelist._CMDUploadChange',
side_effect=[git_cl.GitPushError(), None]).start()
mock.patch('git_cl.Changelist.GetRemoteBranch',
return_value=('foo', git_cl.DEFAULT_OLD_BRANCH)).start()
mock.patch('git_cl.Changelist.GetGerritProject',
return_value='foo').start()
mock.patch('git_cl.gerrit_util.GetProjectHead',
return_value='refs/heads/main').start()
mock.patch('git_cl.RunGit').start()
cl = git_cl.Changelist()
options = optparse.Values()
options.target_branch = 'refs/heads/master'
cl.CMDUploadChange(options, [], 'foo', git_cl.ChangeDescription('bar'))
# ensure upload is called twice
self.assertEqual(len(m.mock_calls), 2)
# option overrides on retry
self.assertEqual(options.force, True)
self.assertEqual(options.edit_description, False)
def test_upload_with_message_file_no_editor(self):
m = mock.patch('git_cl.ChangeDescription.prompt',
return_value=None).start()
......@@ -318,7 +297,7 @@ class TestGitClBasic(unittest.TestCase):
cl = git_cl.Changelist()
options = optparse.Values()
options.target_branch = 'refs/heads/master'
options.target_branch = 'refs/heads/main'
options.squash = True
options.edit_description = False
options.force = False
......@@ -334,32 +313,6 @@ class TestGitClBasic(unittest.TestCase):
cl.CMDUploadChange(options, [], 'foo', git_cl.ChangeDescription('bar'))
self.assertEqual(len(m.mock_calls), 1)
def test_upload_to_old_default_retry_on_rollback(self):
"""Test when default branch migration had to be rolled back to old name"""
m = mock.patch('git_cl.Changelist._CMDUploadChange',
side_effect=[git_cl.GitPushError(), None]).start()
mock.patch('git_cl.Changelist.GetRemoteBranch',
return_value=('foo', git_cl.DEFAULT_NEW_BRANCH)).start()
mock.patch('git_cl.Changelist.GetGerritProject',
return_value='foo').start()
mock.patch('git_cl.gerrit_util.GetProjectHead',
return_value='refs/heads/master').start()
# GetTargetRef returns new default branch since it has stale remote
# information.
mock.patch('git_cl.GetTargetRef',
return_value='refs/heads/main').start()
mock.patch('git_cl.RunGit').start()
cl = git_cl.Changelist()
options = optparse.Values()
options.target_branch = 'refs/heads/master'
cl.CMDUploadChange(options, [], 'foo', git_cl.ChangeDescription('bar'))
# ensure upload is called twice
self.assertEqual(len(m.mock_calls), 2)
# option overrides on retry
self.assertEqual(options.force, True)
self.assertEqual(options.edit_description, False)
def test_get_cl_statuses_no_changes(self):
self.assertEqual([], list(git_cl.get_cl_statuses([], True)))
......@@ -680,7 +633,7 @@ class TestGitCl(unittest.TestCase):
'git_new_branch.create_new_branch', self.mockGit.NewBranch).start()
mock.patch(
'scm.GIT.FetchUpstreamTuple',
return_value=('origin', 'refs/heads/master')).start()
return_value=('origin', 'refs/heads/main')).start()
mock.patch(
'scm.GIT.CaptureStatus', return_value=[('M', 'foo.txt')]).start()
# It's important to reset settings to not have inter-tests interference.
......@@ -776,7 +729,7 @@ class TestGitCl(unittest.TestCase):
def _gerrit_base_calls(cls, issue=None, fetched_description=None,
fetched_status=None, other_cl_owner=None,
custom_cl_base=None, short_hostname='chromium',
change_id=None, default_branch='master'):
change_id=None, default_branch='main'):
calls = []
if custom_cl_base:
ancestor_revision = custom_cl_base
......@@ -807,10 +760,6 @@ class TestGitCl(unittest.TestCase):
[ancestor_revision, 'HEAD']),),
'+dat'),
]
calls += [
((['git', 'show-branch', 'refs/remotes/origin/main'], ),
'1' if default_branch == 'main' else callError(1)),
]
return calls
......@@ -833,7 +782,7 @@ class TestGitCl(unittest.TestCase):
gitcookies_exists=True,
force=False,
edit_description=None,
default_branch='master',
default_branch='main',
push_opts=None):
if post_amend_description is None:
post_amend_description = description
......@@ -1140,7 +1089,7 @@ class TestGitCl(unittest.TestCase):
log_description=None,
edit_description=None,
fetched_description=None,
default_branch='master',
default_branch='main',
push_opts=None):
"""Generic gerrit upload test framework."""
if squash_mode is None:
......@@ -1201,7 +1150,7 @@ class TestGitCl(unittest.TestCase):
lambda prompt: self._mocked_call('ask_for_data', prompt)).start()
self.mockGit.config['gerrit.host'] = 'true'
self.mockGit.config['branch.master.gerritissue'] = (
self.mockGit.config['branch.main.gerritissue'] = (
str(issue) if issue else None)
self.mockGit.config['remote.origin.url'] = (
'https://%s.googlesource.com/my/repo' % short_hostname)
......@@ -1248,7 +1197,7 @@ class TestGitCl(unittest.TestCase):
self.assertIssueAndPatchset(patchset=None)
self.assertEqual(
'abcdef0123456789',
scm.GIT.GetBranchConfig('', 'master', 'gerritsquashhash'))
scm.GIT.GetBranchConfig('', 'main', 'gerritsquashhash'))
def test_gerrit_upload_traces_no_gitcookies(self):
self._run_gerrit_upload_test(
......@@ -1765,10 +1714,6 @@ class TestGitCl(unittest.TestCase):
self.assertEqual(expected, actual)
def test_get_hash_tags(self):
self.calls = [
((['git', 'show-branch', 'refs/remotes/origin/main'], ),
callError(1)),
] * 9
cases = [
('', []),
('a', []),
......@@ -1812,19 +1757,19 @@ class TestGitCl(unittest.TestCase):
expected,
'GetHashTags(%r) == %r, expected %r' % (desc, actual, expected))
self.assertEqual(None, git_cl.GetTargetRef('origin', None, 'master'))
self.assertEqual(None, git_cl.GetTargetRef('origin', None, 'main'))
self.assertEqual(None, git_cl.GetTargetRef(None,
'refs/remotes/origin/master',
'master'))
'refs/remotes/origin/main',
'main'))
# Check default target refs for branches.
self.assertEqual('refs/heads/master',
git_cl.GetTargetRef('origin', 'refs/remotes/origin/master',
self.assertEqual('refs/heads/main',
git_cl.GetTargetRef('origin', 'refs/remotes/origin/main',
None))
self.assertEqual('refs/heads/master',
self.assertEqual('refs/heads/main',
git_cl.GetTargetRef('origin', 'refs/remotes/origin/lkgr',
None))
self.assertEqual('refs/heads/master',
self.assertEqual('refs/heads/main',
git_cl.GetTargetRef('origin', 'refs/remotes/origin/lkcr',
None))
self.assertEqual('refs/branch-heads/123',
......@@ -1845,16 +1790,16 @@ class TestGitCl(unittest.TestCase):
'refs/remotes/branch-heads/123'):
self.assertEqual('refs/branch-heads/123',
git_cl.GetTargetRef('origin',
'refs/remotes/origin/master',
'refs/remotes/origin/main',
branch))
for branch in ('origin/master', 'remotes/origin/master',
'refs/remotes/origin/master'):
self.assertEqual('refs/heads/master',
for branch in ('origin/main', 'remotes/origin/main',
'refs/remotes/origin/main'):
self.assertEqual('refs/heads/main',
git_cl.GetTargetRef('origin',
'refs/remotes/branch-heads/123',
branch))
for branch in ('master', 'heads/master', 'refs/heads/master'):
self.assertEqual('refs/heads/master',
for branch in ('main', 'heads/main', 'refs/heads/main'):
self.assertEqual('refs/heads/main',
git_cl.GetTargetRef('origin',
'refs/remotes/branch-heads/123',
branch))
......@@ -1865,7 +1810,7 @@ class TestGitCl(unittest.TestCase):
self.assertNotEqual(git_cl.main(['patch', '123456']), 0)
def assertIssueAndPatchset(
self, branch='master', issue='123456', patchset='7',
self, branch='main', issue='123456', patchset='7',
git_short_host='chromium'):
self.assertEqual(
issue, scm.GIT.GetBranchConfig('', branch, 'gerritissue'))
......@@ -2016,8 +1961,8 @@ class TestGitCl(unittest.TestCase):
self.mockGit.config['remote.origin.url'] = (
'https://chromium.googlesource.com/my/repo')
cl = git_cl.Changelist()
cl.branch = 'master'
cl.branchref = 'refs/heads/master'
cl.branch = 'main'
cl.branchref = 'refs/heads/main'
return cl
@mock.patch('sys.stderr', StringIO())
......@@ -2082,7 +2027,7 @@ class TestGitCl(unittest.TestCase):
(('logging.warning',
'Ignoring branch %(branch)s with non-https remote '
'%(remote)s', {
'branch': 'master',
'branch': 'main',
'remote': 'custom-scheme://repo'}
), None),
]
......@@ -2091,8 +2036,8 @@ class TestGitCl(unittest.TestCase):
mock.patch('logging.warning',
lambda *a: self._mocked_call('logging.warning', *a)).start()
cl = git_cl.Changelist()
cl.branch = 'master'
cl.branchref = 'refs/heads/master'
cl.branch = 'main'
cl.branchref = 'refs/heads/main'
cl.lookedup_issue = True
self.assertIsNone(cl.EnsureAuthenticated(force=False))
......@@ -2104,7 +2049,7 @@ class TestGitCl(unittest.TestCase):
'Remote "%(remote)s" for branch "%(branch)s" points to "%(url)s", '
'but it doesn\'t exist.', {
'remote': 'origin',
'branch': 'master',
'branch': 'main',
'url': 'git@somehost.example:foo/bar.git'}
), None),
]
......@@ -2113,14 +2058,14 @@ class TestGitCl(unittest.TestCase):
mock.patch('logging.error',
lambda *a: self._mocked_call('logging.error', *a)).start()
cl = git_cl.Changelist()
cl.branch = 'master'
cl.branchref = 'refs/heads/master'
cl.branch = 'main'
cl.branchref = 'refs/heads/main'
cl.lookedup_issue = True
self.assertIsNone(cl.EnsureAuthenticated(force=False))
def _cmd_set_commit_gerrit_common(self, vote, notify=None):
self.mockGit.config['branch.master.gerritissue'] = '123'
self.mockGit.config['branch.master.gerritserver'] = (
self.mockGit.config['branch.main.gerritissue'] = '123'
self.mockGit.config['branch.main.gerritserver'] = (
'https://chromium-review.googlesource.com')
self.mockGit.config['remote.origin.url'] = (
'https://chromium.googlesource.com/infra/infra')
......@@ -2131,8 +2076,8 @@ class TestGitCl(unittest.TestCase):
]
def _cmd_set_quick_run_gerrit(self):
self.mockGit.config['branch.master.gerritissue'] = '123'
self.mockGit.config['branch.master.gerritserver'] = (
self.mockGit.config['branch.main.gerritissue'] = '123'
self.mockGit.config['branch.main.gerritserver'] = (
'https://chromium-review.googlesource.com')
self.mockGit.config['remote.origin.url'] = (
'https://chromium.googlesource.com/infra/infra')
......@@ -2241,7 +2186,7 @@ class TestGitCl(unittest.TestCase):
UpdateDescription).start()
mock.patch('git_cl.gclient_utils.RunEditor', RunEditor).start()
self.mockGit.config['branch.master.gerritissue'] = '123'
self.mockGit.config['branch.main.gerritissue'] = '123'
self.assertEqual(0, git_cl.main(['description']))
def test_description_does_not_append_bug_line_if_fixed_is_present(self):
......@@ -2262,7 +2207,7 @@ class TestGitCl(unittest.TestCase):
lambda *args: current_desc).start()
mock.patch('git_cl.gclient_utils.RunEditor', RunEditor).start()
self.mockGit.config['branch.master.gerritissue'] = '123'
self.mockGit.config['branch.main.gerritissue'] = '123'
self.assertEqual(0, git_cl.main(['description']))
def test_description_set_stdin(self):
......@@ -2275,7 +2220,7 @@ class TestGitCl(unittest.TestCase):
def test_archive(self):
self.calls = [
((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],),
'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'),
'refs/heads/main\nrefs/heads/foo\nrefs/heads/bar'),
((['git', 'for-each-ref', '--format=%(refname)', 'refs/tags'],), ''),
((['git', 'tag', 'git-cl-archived-456-foo', 'foo'],), ''),
((['git', 'branch', '-D', 'foo'],), '')
......@@ -2283,7 +2228,7 @@ class TestGitCl(unittest.TestCase):
mock.patch('git_cl.get_cl_statuses',
lambda branches, fine_grained, max_processes:
[(MockChangelistWithBranchAndIssue('master', 1), 'open'),
[(MockChangelistWithBranchAndIssue('main', 1), 'open'),
(MockChangelistWithBranchAndIssue('foo', 456), 'closed'),
(MockChangelistWithBranchAndIssue('bar', 789), 'open')]).start()
......@@ -2292,7 +2237,7 @@ class TestGitCl(unittest.TestCase):
def test_archive_tag_collision(self):
self.calls = [
((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],),
'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'),
'refs/heads/main\nrefs/heads/foo\nrefs/heads/bar'),
((['git', 'for-each-ref', '--format=%(refname)', 'refs/tags'],),
'refs/tags/git-cl-archived-456-foo'),
((['git', 'tag', 'git-cl-archived-456-foo-2', 'foo'],), ''),
......@@ -2301,7 +2246,7 @@ class TestGitCl(unittest.TestCase):
mock.patch('git_cl.get_cl_statuses',
lambda branches, fine_grained, max_processes:
[(MockChangelistWithBranchAndIssue('master', 1), 'open'),
[(MockChangelistWithBranchAndIssue('main', 1), 'open'),
(MockChangelistWithBranchAndIssue('foo', 456), 'closed'),
(MockChangelistWithBranchAndIssue('bar', 789), 'open')]).start()
......@@ -2310,13 +2255,13 @@ class TestGitCl(unittest.TestCase):
def test_archive_current_branch_fails(self):
self.calls = [
((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],),
'refs/heads/master'),
'refs/heads/main'),
((['git', 'for-each-ref', '--format=%(refname)', 'refs/tags'],), ''),
]
mock.patch('git_cl.get_cl_statuses',
lambda branches, fine_grained, max_processes:
[(MockChangelistWithBranchAndIssue('master', 1),
[(MockChangelistWithBranchAndIssue('main', 1),
'closed')]).start()
self.assertEqual(1, git_cl.main(['archive', '-f']))
......@@ -2324,13 +2269,13 @@ class TestGitCl(unittest.TestCase):
def test_archive_dry_run(self):
self.calls = [
((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],),
'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'),
'refs/heads/main\nrefs/heads/foo\nrefs/heads/bar'),
((['git', 'for-each-ref', '--format=%(refname)', 'refs/tags'],), ''),
]
mock.patch('git_cl.get_cl_statuses',
lambda branches, fine_grained, max_processes:
[(MockChangelistWithBranchAndIssue('master', 1), 'open'),
[(MockChangelistWithBranchAndIssue('main', 1), 'open'),
(MockChangelistWithBranchAndIssue('foo', 456), 'closed'),
(MockChangelistWithBranchAndIssue('bar', 789), 'open')]).start()
......@@ -2339,14 +2284,14 @@ class TestGitCl(unittest.TestCase):
def test_archive_no_tags(self):
self.calls = [
((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],),
'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'),
'refs/heads/main\nrefs/heads/foo\nrefs/heads/bar'),
((['git', 'for-each-ref', '--format=%(refname)', 'refs/tags'],), ''),
((['git', 'branch', '-D', 'foo'],), '')
]
mock.patch('git_cl.get_cl_statuses',
lambda branches, fine_grained, max_processes:
[(MockChangelistWithBranchAndIssue('master', 1), 'open'),
[(MockChangelistWithBranchAndIssue('main', 1), 'open'),
(MockChangelistWithBranchAndIssue('foo', 456), 'closed'),
(MockChangelistWithBranchAndIssue('bar', 789), 'open')]).start()
......@@ -2355,7 +2300,7 @@ class TestGitCl(unittest.TestCase):
def test_archive_tag_cleanup_on_branch_deletion_error(self):
self.calls = [
((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'],),
'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'),
'refs/heads/main\nrefs/heads/foo\nrefs/heads/bar'),
((['git', 'for-each-ref', '--format=%(refname)', 'refs/tags'],), ''),
((['git', 'tag', 'git-cl-archived-456-foo', 'foo'],),
'refs/tags/git-cl-archived-456-foo'),
......@@ -2366,7 +2311,7 @@ class TestGitCl(unittest.TestCase):
mock.patch('git_cl.get_cl_statuses',
lambda branches, fine_grained, max_processes:
[(MockChangelistWithBranchAndIssue('master', 1), 'open'),
[(MockChangelistWithBranchAndIssue('main', 1), 'open'),
(MockChangelistWithBranchAndIssue('foo', 456), 'closed'),
(MockChangelistWithBranchAndIssue('bar', 789), 'open')]).start()
......@@ -2375,7 +2320,7 @@ class TestGitCl(unittest.TestCase):
def test_archive_with_format(self):
self.calls = [
((['git', 'for-each-ref', '--format=%(refname)', 'refs/heads'], ),
'refs/heads/master\nrefs/heads/foo\nrefs/heads/bar'),
'refs/heads/main\nrefs/heads/foo\nrefs/heads/bar'),
((['git', 'for-each-ref', '--format=%(refname)', 'refs/tags'], ), ''),
((['git', 'tag', 'archived/12-foo', 'foo'], ), ''),
((['git', 'branch', '-D', 'foo'], ), ''),
......@@ -2389,19 +2334,19 @@ class TestGitCl(unittest.TestCase):
0, git_cl.main(['archive', '-f', '-p', 'archived/{issue}-{branch}']))
def test_cmd_issue_erase_existing(self):
self.mockGit.config['branch.master.gerritissue'] = '123'
self.mockGit.config['branch.master.gerritserver'] = (
self.mockGit.config['branch.main.gerritissue'] = '123'
self.mockGit.config['branch.main.gerritserver'] = (
'https://chromium-review.googlesource.com')
self.calls = [
((['git', 'log', '-1', '--format=%B'],), 'This is a description'),
]
self.assertEqual(0, git_cl.main(['issue', '0']))
self.assertNotIn('branch.master.gerritissue', self.mockGit.config)
self.assertNotIn('branch.master.gerritserver', self.mockGit.config)
self.assertNotIn('branch.main.gerritissue', self.mockGit.config)
self.assertNotIn('branch.main.gerritserver', self.mockGit.config)
def test_cmd_issue_erase_existing_with_change_id(self):
self.mockGit.config['branch.master.gerritissue'] = '123'
self.mockGit.config['branch.master.gerritserver'] = (
self.mockGit.config['branch.main.gerritissue'] = '123'
self.mockGit.config['branch.main.gerritserver'] = (
'https://chromium-review.googlesource.com')
mock.patch('git_cl.Changelist.FetchDescription',
lambda _: 'This is a description\n\nChange-Id: Ideadbeef').start()
......@@ -2411,12 +2356,12 @@ class TestGitCl(unittest.TestCase):
((['git', 'commit', '--amend', '-m', 'This is a description\n'],), ''),
]
self.assertEqual(0, git_cl.main(['issue', '0']))
self.assertNotIn('branch.master.gerritissue', self.mockGit.config)
self.assertNotIn('branch.master.gerritserver', self.mockGit.config)
self.assertNotIn('branch.main.gerritissue', self.mockGit.config)
self.assertNotIn('branch.main.gerritserver', self.mockGit.config)
def test_cmd_issue_json(self):
self.mockGit.config['branch.master.gerritissue'] = '123'
self.mockGit.config['branch.master.gerritserver'] = (
self.mockGit.config['branch.main.gerritissue'] = '123'
self.mockGit.config['branch.main.gerritserver'] = (
'https://chromium-review.googlesource.com')
self.mockGit.config['remote.origin.url'] = (
'https://chromium.googlesource.com/chromium/src'
......@@ -2483,8 +2428,8 @@ class TestGitCl(unittest.TestCase):
cl._GerritCommitMsgHookCheck(offer_removal=True)
def test_GerritCmdLand(self):
self.mockGit.config['branch.master.gerritsquashhash'] = 'deadbeaf'
self.mockGit.config['branch.master.gerritserver'] = (
self.mockGit.config['branch.main.gerritsquashhash'] = 'deadbeaf'
self.mockGit.config['branch.main.gerritserver'] = (
'chromium-review.googlesource.com')
self.calls += [
((['git', 'diff', 'deadbeaf'],), ''), # No diff.
......@@ -2958,7 +2903,7 @@ class TestGitCl(unittest.TestCase):
'Remote "%(remote)s" for branch "%(branch)s" points to "%(url)s", '
'but it doesn\'t exist.', {
'remote': 'origin',
'branch': 'master',
'branch': 'main',
'url': '/cache/this-dir-doesnt-exist'}
), None),
]
......@@ -2988,7 +2933,7 @@ class TestGitCl(unittest.TestCase):
'"%(remote)s" pointing to the git host.', {
'remote': 'origin',
'cache_path': '/cache/this-dir-exists',
'branch': 'master'}
'branch': 'main'}
), None),
]
cl = git_cl.Changelist(issue=1)
......@@ -3009,7 +2954,7 @@ class TestGitCl(unittest.TestCase):
'Remote "%(remote)s" for branch "%(branch)s" points to "%(url)s", '
'but it doesn\'t exist.', {
'remote': 'origin',
'branch': 'master',
'branch': 'main',
'url': ''}
), None),
]
......
......@@ -197,8 +197,8 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase,
def testHashes(self):
ret = self.repo.run(
self.gc.hash_multi, *[
'master',
'master~3',
'main',
'main~3',
self.repo['E']+'~',
self.repo['D']+'^2',
'tag_C^{}',
......@@ -259,7 +259,7 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase,
def testBranches(self):
# This check fails with git 2.4 (see crbug.com/487172)
self.assertEqual(self.repo.run(set, self.gc.branches()),
{'master', 'branch_D', 'root_A'})
{'main', 'branch_D', 'root_A'})
def testDiff(self):
# Get the names of the blobs being compared (to avoid hard-coding).
......@@ -279,9 +279,9 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase,
self.repo.run(self.gc.diff, 'tag_C', 'tag_D').split('\n'))
def testDormant(self):
self.assertFalse(self.repo.run(self.gc.is_dormant, 'master'))
self.repo.git('config', 'branch.master.dormant', 'true')
self.assertTrue(self.repo.run(self.gc.is_dormant, 'master'))
self.assertFalse(self.repo.run(self.gc.is_dormant, 'main'))
self.repo.git('config', 'branch.main.dormant', 'true')
self.assertTrue(self.repo.run(self.gc.is_dormant, 'main'))
def testBlame(self):
def get_porcelain_for_commit(commit_name, lines):
......@@ -321,8 +321,8 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase,
def testParseCommitrefs(self):
ret = self.repo.run(
self.gc.parse_commitrefs, *[
'master',
'master~3',
'main',
'main~3',
self.repo['E']+'~',
self.repo['D']+'^2',
'tag_C^{}',
......@@ -337,9 +337,9 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase,
]
self.assertEqual(ret, [binascii.unhexlify(h) for h in hashes])
expected_re = r"one of \(u?'master', u?'bananas'\)"
expected_re = r"one of \(u?'main', u?'bananas'\)"
with self.assertRaisesRegexp(Exception, expected_re):
self.repo.run(self.gc.parse_commitrefs, 'master', 'bananas')
self.repo.run(self.gc.parse_commitrefs, 'main', 'bananas')
def testRepoRoot(self):
def cd_and_repo_root(path):
......@@ -356,7 +356,7 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase,
{'tag_'+l for l in 'ABCDE'})
def testTree(self):
tree = self.repo.run(self.gc.tree, 'master:some/files')
tree = self.repo.run(self.gc.tree, 'main:some/files')
file1 = self.COMMIT_A['some/files/file1']['data']
file2 = self.COMMIT_D['some/files/file2']['data']
file3 = self.COMMIT_A['some/files/file3']['data']
......@@ -370,16 +370,16 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase,
tree['file3'],
('100644', 'blob', git_test_utils.git_hash_data(file3)))
tree = self.repo.run(self.gc.tree, 'master:some')
tree = self.repo.run(self.gc.tree, 'main:some')
self.assertEqual(len(tree), 2)
# Don't check the tree hash because we're lazy :)
self.assertEqual(tree['files'][:2], ('040000', 'tree'))
tree = self.repo.run(self.gc.tree, 'master:wat')
tree = self.repo.run(self.gc.tree, 'main:wat')
self.assertEqual(tree, None)
def testTreeRecursive(self):
tree = self.repo.run(self.gc.tree, 'master:some', recurse=True)
tree = self.repo.run(self.gc.tree, 'main:some', recurse=True)
file1 = self.COMMIT_A['some/files/file1']['data']
file2 = self.COMMIT_D['some/files/file2']['data']
file3 = self.COMMIT_A['some/files/file3']['data']
......@@ -448,7 +448,7 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
self.assertEqual(
'cat', self.repo.run(self.gc.get_config, 'dude.bob', 'cat'))
self.assertEqual('origin/master', self.repo.run(self.gc.root))
self.assertEqual('origin/main', self.repo.run(self.gc.root))
self.repo.git('config', 'depot-tools.upstream', 'catfood')
......@@ -460,7 +460,7 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
B D
""", self.getRepoContent)
origin = origin_schema.reify()
# Set the default branch to branch_D instead of master.
# Set the default branch to branch_D instead of main.
origin.git('checkout', 'branch_D')
self.repo.git('remote', 'add', 'origin', origin.repo_path)
......@@ -471,10 +471,10 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
def testUpstream(self):
self.repo.git('commit', '--allow-empty', '-am', 'foooooo')
self.assertEqual(self.repo.run(self.gc.upstream, 'bobly'), None)
self.assertEqual(self.repo.run(self.gc.upstream, 'master'), None)
self.repo.git('checkout', '-tb', 'happybranch', 'master')
self.assertEqual(self.repo.run(self.gc.upstream, 'main'), None)
self.repo.git('checkout', '-tb', 'happybranch', 'main')
self.assertEqual(self.repo.run(self.gc.upstream, 'happybranch'),
'master')
'main')
def testNormalizedVersion(self):
self.assertTrue(all(
......@@ -482,11 +482,11 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
def testGetBranchesInfo(self):
self.repo.git('commit', '--allow-empty', '-am', 'foooooo')
self.repo.git('checkout', '-tb', 'happybranch', 'master')
self.repo.git('checkout', '-tb', 'happybranch', 'main')
self.repo.git('commit', '--allow-empty', '-am', 'foooooo')
self.repo.git('checkout', '-tb', 'child', 'happybranch')
self.repo.git('checkout', '-tb', 'to_delete', 'master')
self.repo.git('checkout', '-tb', 'to_delete', 'main')
self.repo.git('checkout', '-tb', 'parent_gone', 'to_delete')
self.repo.git('branch', '-D', 'to_delete')
......@@ -498,7 +498,7 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
expected = {
'happybranch': (
self.repo.run(self.gc.hash_one, 'happybranch', short=True),
'master',
'main',
1 if supports_track else None,
None
),
......@@ -508,8 +508,8 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
None,
None
),
'master': (
self.repo.run(self.gc.hash_one, 'master', short=True),
'main': (
self.repo.run(self.gc.hash_one, 'main', short=True),
'',
None,
None
......@@ -527,10 +527,10 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
def testGetBranchesInfoWithReset(self):
self.repo.git('commit', '--allow-empty', '-am', 'foooooo')
self.repo.git('checkout','-tb', 'foobarA', 'master')
self.repo.git('checkout','-tb', 'foobarA', 'main')
self.repo.git('config', 'branch.foobarA.base',
self.repo.run(self.gc.hash_one, 'master'))
self.repo.git('config', 'branch.foobarA.base-upstream', 'master')
self.repo.run(self.gc.hash_one, 'main'))
self.repo.git('config', 'branch.foobarA.base-upstream', 'main')
with self.repo.open('foobar1', 'w') as f:
f.write('hello')
......@@ -558,7 +558,7 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
expected = {
'foobarA': (
self.repo.run(self.gc.hash_one, 'foobarA', short=True),
'master',
'main',
2,
None
),
......@@ -568,8 +568,8 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
None,
1
),
'master': (
self.repo.run(self.gc.hash_one, 'master', short=True),
'main': (
self.repo.run(self.gc.hash_one, 'main', short=True),
'',
None,
None
......@@ -695,7 +695,7 @@ class GitMutableStructuredTest(git_test_utils.GitRepoReadWriteTestBase,
def testMergeBaseWithForkPoint(self):
self.repo.git('commit', '--allow-empty', '-am', 'foooooo')
self.repo.git('checkout','-tb', 'foobarA', 'master')
self.repo.git('checkout','-tb', 'foobarA', 'main')
foobarA = self.repo.run(self.gc.hash_one, 'foobarA', short=True)
self.repo.git('checkout','-tb', 'foobarB', 'foobarA')
......@@ -726,7 +726,7 @@ class GitMutableStructuredTest(git_test_utils.GitRepoReadWriteTestBase,
def testGetBranchTree(self):
skipped, tree = self.repo.run(self.gc.get_branch_tree)
# This check fails with git 2.4 (see crbug.com/487172)
self.assertEqual(skipped, {'master', 'root_X', 'branch_DOG', 'root_CAT'})
self.assertEqual(skipped, {'main', 'root_X', 'branch_DOG', 'root_CAT'})
self.assertEqual(tree, {
'branch_G': 'root_A',
'root_A': 'root_X',
......
......@@ -24,11 +24,11 @@ class GitFootersTest(unittest.TestCase):
_message = """
This is my commit message. There are many like it, but this one is mine.
My commit message is my best friend. It is my life. I must master it.
My commit message is my best friend. It is my life.
"""
_position = 'refs/heads/master@{#292272}'
_position = 'refs/heads/main@{#292272}'
_position_footer = 'Cr-Commit-Position: %s\n' % _position
......
......@@ -50,13 +50,13 @@ class GitMapTest(git_test_utils.GitRepoReadOnlyTestBase):
J L
""", self.getRepoContent)
self.origin = origin_schema.reify()
self.origin.git('checkout', 'master')
self.origin.git('checkout', 'main')
self.origin.git('branch', '-d', *['branch_'+l for l in 'KLG'])
self.repo.git('remote', 'add', 'origin', self.origin.repo_path)
self.repo.git('config', '--add', 'remote.origin.fetch',
'+refs/tags/*:refs/tags/*')
self.repo.git('update-ref', 'refs/remotes/origin/master', 'tag_E')
self.repo.git('update-ref', 'refs/remotes/origin/main', 'tag_E')
self.repo.git('branch', '--set-upstream-to', 'branch_G', 'branch_K')
self.repo.git('branch', '--set-upstream-to', 'branch_K', 'branch_L')
......@@ -79,7 +79,7 @@ class GitMapTest(git_test_utils.GitRepoReadOnlyTestBase):
def testGitMap(self):
expected = os.linesep.join([
'* 6e85e877ea (tag_O, origin/master, origin/branch_O) 1970-01-30 ~ O',
'* 6e85e877ea (tag_O, origin/main, origin/branch_O) 1970-01-30 ~ O',
'* 4705470871 (tag_N) 1970-01-28 ~ N',
'* 8761b1a94f (tag_M) 1970-01-26 ~ M',
'* 5e7ce08691 (tag_G) 1970-01-24 ~ G',
......@@ -110,7 +110,7 @@ class GitMapTest(git_test_utils.GitRepoReadOnlyTestBase):
'|/ ',
'* 315457dbe8 (tag_B) 1970-01-04 ~ B',
'* cd589e62d8 (tag_A, origin/root_A) 1970-01-02 ~ A',
'* 7026d3d68e (tag_", root_", master, branch_") 1970-01-02 ~ "',
'* 7026d3d68e (tag_", root_", main, branch_") 1970-01-02 ~ "',
])
outbuf = io.BytesIO()
self.repo.run(git_map.main, [], outbuf)
......
......@@ -54,18 +54,18 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
J L
""", self.getRepoContent)
self.origin = origin_schema.reify()
self.origin.git('checkout', 'master')
self.origin.git('checkout', 'main')
self.origin.git('branch', '-d', *['branch_'+l for l in 'KLG'])
self.repo.git('remote', 'add', 'origin', self.origin.repo_path)
self.repo.git('config', '--add', 'remote.origin.fetch',
'+refs/tags/*:refs/tags/*')
self.repo.git('update-ref', 'refs/remotes/origin/master', 'tag_E')
self.repo.git('update-ref', 'refs/remotes/origin/main', 'tag_E')
self.repo.git('branch', '--set-upstream-to', 'branch_G', 'branch_K')
self.repo.git('branch', '--set-upstream-to', 'branch_K', 'branch_L')
self.repo.git('branch', '--set-upstream-to', 'origin/master', 'branch_G')
self.repo.git('branch', '--set-upstream-to', 'origin/main', 'branch_G')
self.repo.to_schema_refs += ['origin/master']
self.repo.to_schema_refs += ['origin/main']
def tearDown(self):
self.origin.nuke()
......@@ -76,7 +76,7 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
self.repo.run(self.nb.main, ['foobar'])
self.assertEqual(self.repo.git('rev-parse', 'HEAD').stdout,
self.repo.git('rev-parse', 'origin/master').stdout)
self.repo.git('rev-parse', 'origin/main').stdout)
with self.repo.open('foobar', 'w') as f:
f.write('this is the foobar file')
......@@ -109,7 +109,7 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
self.repo.git_commit('old_file')
self.repo.git('config', 'branch.old_branch.dormant', 'true')
self.repo.git('checkout', 'origin/master')
self.repo.git('checkout', 'origin/main')
self.assertSchema("""
A B H I J K sub_K
......@@ -144,7 +144,7 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
self.assertIn('Deleted branch empty_branch2', output)
self.assertIn('Deleted branch int1_foobar', output)
self.assertIn('Deleted branch int2_foobar', output)
self.assertIn('Reparented branch_K to track origin/master', output)
self.assertIn('Reparented branch_K to track origin/main', output)
self.assertIn('Reparented sub_foobar to track foobar', output)
self.assertSchema("""
......@@ -165,14 +165,14 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
self.assertEqual(self.repo.git('status', '--porcelain').stdout, '?? bob\n')
self.repo.git('checkout', 'origin/master')
self.repo.git('checkout', 'origin/main')
_, err = self.repo.capture_stdio(self.rp.main, [])
self.assertIn('Must specify new parent somehow', err)
_, err = self.repo.capture_stdio(self.rp.main, ['foobar'])
self.assertIn('Must be on the branch', err)
self.repo.git('checkout', 'branch_K')
_, err = self.repo.capture_stdio(self.rp.main, ['origin/master'])
_, err = self.repo.capture_stdio(self.rp.main, ['origin/main'])
self.assertIn('Cannot reparent a branch to its existing parent', err)
output, _ = self.repo.capture_stdio(self.rp.main, ['foobar'])
self.assertIn('Rebasing: branch_K', output)
......@@ -205,7 +205,7 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
self.assertEqual(self.repo.git('status', '--porcelain').stdout, '?? bob\n')
branches = self.repo.run(set, self.gc.branches())
self.assertEqual(branches, {'branch_K', 'master', 'sub_K', 'root_A',
self.assertEqual(branches, {'branch_K', 'main', 'sub_K', 'root_A',
'branch_L', 'old_branch', 'foobar',
'sub_foobar'})
......@@ -213,18 +213,18 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
self.repo.run(self.mv.main, ['special_K'])
branches = self.repo.run(set, self.gc.branches())
self.assertEqual(branches, {'special_K', 'master', 'sub_K', 'root_A',
self.assertEqual(branches, {'special_K', 'main', 'sub_K', 'root_A',
'branch_L', 'old_branch', 'foobar',
'sub_foobar'})
self.repo.git('checkout', 'origin/master')
self.repo.git('checkout', 'origin/main')
_, err = self.repo.capture_stdio(self.mv.main, ['special_K', 'cool branch'])
self.assertIn('fatal: \'cool branch\' is not a valid branch name.', err)
self.repo.run(self.mv.main, ['special_K', 'cool_branch'])
branches = self.repo.run(set, self.gc.branches())
# This check fails with git 2.4 (see crbug.com/487172)
self.assertEqual(branches, {'cool_branch', 'master', 'sub_K', 'root_A',
self.assertEqual(branches, {'cool_branch', 'main', 'sub_K', 'root_A',
'branch_L', 'old_branch', 'foobar',
'sub_foobar'})
......@@ -234,7 +234,7 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
def testRebaseConflicts(self):
# Pretend that branch_L landed
self.origin.git('checkout', 'master')
self.origin.git('checkout', 'main')
with self.origin.open('L', 'w') as f:
f.write('L')
self.origin.git('add', 'L')
......@@ -276,11 +276,11 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
self.assertIn('Deleted branch branch_G', output)
self.assertIn('Deleted branch branch_L', output)
self.assertIn('\'branch_G\' was merged', output)
self.assertIn('checking out \'origin/master\'', output)
self.assertIn('checking out \'origin/main\'', output)
def testRebaseConflictsKeepGoing(self):
# Pretend that branch_L landed
self.origin.git('checkout', 'master')
self.origin.git('checkout', 'main')
with self.origin.open('L', 'w') as f:
f.write('L')
self.origin.git('add', 'L')
......@@ -383,7 +383,7 @@ class GitRebaseUpdateTest(git_test_utils.GitRepoReadWriteTestBase):
""")
output, _ = self.repo.capture_stdio(self.rp.main, ['--root'])
self.assertIn('to track origin/master (was lkgr [tag])', output)
self.assertIn('to track origin/main (was lkgr [tag])', output)
self.assertSchema("""
A B C D E F G M N O foobar1 foobar2
......
......@@ -665,7 +665,7 @@ class MetricsUtilsTest(unittest.TestCase):
"""Tests that we extract paths for /changes/."""
# /changes/<change-id>
http_metrics = metrics_utils.extract_http_metrics(
'https://review.example.com/changes/proj%2Fsrc%7Emaster%7EI1234abcd',
'https://review.example.com/changes/proj%2Fsrc%7Emain%7EI1234abcd',
'', 0, 0)
self.assertEqual('changes', http_metrics['path'])
......
......@@ -250,18 +250,18 @@ class RealGitTest(fake_repos.FakeReposTestBase):
scm.GIT.SetBranchConfig(self.cwd, branch, 'remote')
def testGetBranchRef(self):
self.assertEqual('refs/heads/master', scm.GIT.GetBranchRef(self.cwd))
self.assertEqual('refs/heads/main', scm.GIT.GetBranchRef(self.cwd))
HEAD = scm.GIT.Capture(['rev-parse', 'HEAD'], cwd=self.cwd)
scm.GIT.Capture(['checkout', HEAD], cwd=self.cwd)
self.assertIsNone(scm.GIT.GetBranchRef(self.cwd))
scm.GIT.Capture(['checkout', 'master'], cwd=self.cwd)
scm.GIT.Capture(['checkout', 'main'], cwd=self.cwd)
def testGetBranch(self):
self.assertEqual('master', scm.GIT.GetBranch(self.cwd))
self.assertEqual('main', scm.GIT.GetBranch(self.cwd))
HEAD = scm.GIT.Capture(['rev-parse', 'HEAD'], cwd=self.cwd)
scm.GIT.Capture(['checkout', HEAD], cwd=self.cwd)
self.assertIsNone(scm.GIT.GetBranchRef(self.cwd))
scm.GIT.Capture(['checkout', 'master'], cwd=self.cwd)
scm.GIT.Capture(['checkout', 'main'], cwd=self.cwd)
if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment