From b0e2e28a957d668a05b3bc6c88edd411527035e9 Mon Sep 17 00:00:00 2001 From: Alexander Schulze Date: Mon, 22 Apr 2024 16:52:17 +0000 Subject: [PATCH] Support --target_branch=refs/meta/config branch This simplifies the administration of repositories which is currently done via the Gerrit UI instead of the CLI. Bug: None Change-Id: I0af3d77fb611e0c89dc455a5a215129b5c51c5ea Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5472843 Commit-Queue: Gavin Mak Reviewed-by: Gavin Mak Auto-Submit: Alexander Schulze --- git_cl.py | 3 ++- tests/git_cl_test.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/git_cl.py b/git_cl.py index 97cf55427..2f7570bc5 100755 --- a/git_cl.py +++ b/git_cl.py @@ -1320,7 +1320,8 @@ class Changelist(object): self.branchref = branchref if self.branchref: - assert branchref.startswith(('refs/heads/', 'refs/branch-heads/')) + assert (branchref.startswith(('refs/heads/', 'refs/branch-heads/')) + or branchref == 'refs/meta/config') self.branch = scm.GIT.ShortBranchName(self.branchref) else: self.branch = None diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index 11c72e087..06f792532 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -260,6 +260,30 @@ class TestGitClBasic(unittest.TestCase): self.assertFalse(hasattr(options, 'force')) self.assertFalse(hasattr(options, 'edit_description')) + def test_upload_to_meta_config_branch_no_retry(self): + m = mock.patch('git_cl.Changelist._CMDUploadChange', + side_effect=[git_cl.GitPushError(), None]).start() + mock.patch('git_cl.Changelist.GetRemoteBranch', + return_value=('foo', 'bar')).start() + mock.patch('git_cl.Changelist.GetGerritProject', + return_value='foo').start() + mock.patch('git_cl.gerrit_util.GetProjectHead', + return_value='refs/heads/main').start() + + cl = git_cl.Changelist() + options = optparse.Values() + options.target_branch = 'refs/meta/config' + with self.assertRaises(SystemExitMock): + cl.CMDUploadChange(options, [], 'foo', + git_cl.ChangeDescription('bar')) + + # ensure upload is called once + self.assertEqual(len(m.mock_calls), 1) + sys.exit.assert_called_once_with(1) + # option not set as retry didn't happen + self.assertFalse(hasattr(options, 'force')) + self.assertFalse(hasattr(options, 'edit_description')) + def test_upload_to_old_default_still_active(self): m = mock.patch('git_cl.Changelist._CMDUploadChange', side_effect=[git_cl.GitPushError(), None]).start()