Allow existent branch when creating branches via recipe

BUG=1433047
TEST=train

Change-Id: Iafa16840f7ead393ccd09dd483e45e9098358755
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4629867
Commit-Queue: Xinan Lin <linxinan@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
changes/67/4629867/2
Xinan Lin 2 years ago committed by LUCI CQ
parent fc75af35d4
commit 66ab0a5131

@ -255,7 +255,7 @@ Module for interact with Gerrit endpoints
Wrapper for easy calling of gerrit_utils steps.
&mdash; **def [abandon\_change](/recipes/recipe_modules/gerrit/api.py#257)(self, host, change, message=None, name=None, step_test_data=None):**
&mdash; **def [abandon\_change](/recipes/recipe_modules/gerrit/api.py#260)(self, host, change, message=None, name=None, step_test_data=None):**
&mdash; **def [call\_raw\_api](/recipes/recipe_modules/gerrit/api.py#31)(self, host, path, method=None, body=None, accept_statuses=None, name=None, \*\*kwargs):**
@ -271,14 +271,14 @@ Creates a new branch from given project and commit
Returns:
The ref of the branch created
&mdash; **def [create\_gerrit\_tag](/recipes/recipe_modules/gerrit/api.py#79)(self, host, project, tag, commit, \*\*kwargs):**
&mdash; **def [create\_gerrit\_tag](/recipes/recipe_modules/gerrit/api.py#82)(self, host, project, tag, commit, \*\*kwargs):**
Creates a new tag at the given commit.
Returns:
The ref of the tag created.
&mdash; **def [get\_change\_description](/recipes/recipe_modules/gerrit/api.py#118)(self, host, change, patchset, timeout=None, step_test_data=None):**
&mdash; **def [get\_change\_description](/recipes/recipe_modules/gerrit/api.py#121)(self, host, change, patchset, timeout=None, step_test_data=None):**
Gets the description for a given CL and patchset.
@ -290,7 +290,7 @@ Args:
Returns:
The description corresponding to given CL and patchset.
&mdash; **def [get\_changes](/recipes/recipe_modules/gerrit/api.py#178)(self, host, query_params, start=None, limit=None, o_params=None, step_test_data=None, \*\*kwargs):**
&mdash; **def [get\_changes](/recipes/recipe_modules/gerrit/api.py#181)(self, host, query_params, start=None, limit=None, o_params=None, step_test_data=None, \*\*kwargs):**
Queries changes for the given host.
@ -309,14 +309,14 @@ Returns:
A list of change dicts as documented here:
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
&mdash; **def [get\_gerrit\_branch](/recipes/recipe_modules/gerrit/api.py#100)(self, host, project, branch, \*\*kwargs):**
&mdash; **def [get\_gerrit\_branch](/recipes/recipe_modules/gerrit/api.py#103)(self, host, project, branch, \*\*kwargs):**
Gets a branch from given project and commit
Returns:
The revision of the branch
&mdash; **def [get\_related\_changes](/recipes/recipe_modules/gerrit/api.py#221)(self, host, change, revision='current', step_test_data=None):**
&mdash; **def [get\_related\_changes](/recipes/recipe_modules/gerrit/api.py#224)(self, host, change, revision='current', step_test_data=None):**
Queries related changes for a given host, change, and revision.
@ -335,7 +335,7 @@ Returns:
A related changes dictionary as documented here:
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#related-changes-info
&mdash; **def [get\_revision\_info](/recipes/recipe_modules/gerrit/api.py#137)(self, host, change, patchset, timeout=None, step_test_data=None):**
&mdash; **def [get\_revision\_info](/recipes/recipe_modules/gerrit/api.py#140)(self, host, change, patchset, timeout=None, step_test_data=None):**
Returns the info for a given patchset of a given change.
@ -348,11 +348,11 @@ Returns:
A dict for the target revision as documented here:
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
&mdash; **def [move\_changes](/recipes/recipe_modules/gerrit/api.py#295)(self, host, project, from_branch, to_branch, step_test_data=None):**
&mdash; **def [move\_changes](/recipes/recipe_modules/gerrit/api.py#298)(self, host, project, from_branch, to_branch, step_test_data=None):**
&mdash; **def [set\_change\_label](/recipes/recipe_modules/gerrit/api.py#277)(self, host, change, label_name, label_value, name=None, step_test_data=None):**
&mdash; **def [set\_change\_label](/recipes/recipe_modules/gerrit/api.py#280)(self, host, change, label_name, label_value, name=None, step_test_data=None):**
&mdash; **def [update\_files](/recipes/recipe_modules/gerrit/api.py#319)(self, host, project, branch, new_contents_by_file_path, commit_msg, params=frozenset(['status=NEW']), cc_list=frozenset([]), submit=False, submit_later=False, step_test_data_create_change=None, step_test_data_submit_change=None):**
&mdash; **def [update\_files](/recipes/recipe_modules/gerrit/api.py#322)(self, host, project, branch, new_contents_by_file_path, commit_msg, params=frozenset(['status=NEW']), cc_list=frozenset([]), submit=False, submit_later=False, step_test_data_create_change=None, step_test_data_submit_change=None):**
Update a set of files by creating and submitting a Gerrit CL.

@ -71,6 +71,9 @@ class GerritApi(recipe_api.RecipeApi):
'--commit', commit,
'--json_file', self.m.json.output()
]
allow_existent_branch = kwargs.pop('allow_existent_branch', False)
if allow_existent_branch:
args.append('--allow-existent-branch')
step_name = 'create_gerrit_branch (%s %s)' % (project, branch)
step_result = self(step_name, args, **kwargs)
ref = step_result.json.output.get('ref')

@ -13,7 +13,8 @@
"--commit",
"67ebf73496383c6777035e374d2d664009e2aa5c",
"--json_file",
"/path/to/tmp/json"
"/path/to/tmp/json",
"--allow-existent-branch"
],
"env": {
"PATH": "<PATH>:RECIPE_REPO[depot_tools]"

@ -17,7 +17,11 @@ def RunSteps(api):
branch = 'test'
commit = '67ebf73496383c6777035e374d2d664009e2aa5c'
data = api.gerrit.create_gerrit_branch(host, project, branch, commit)
data = api.gerrit.create_gerrit_branch(host,
project,
branch,
commit,
allow_existent_branch=True)
assert data == 'refs/heads/test'
data = api.gerrit.get_gerrit_branch(host, project, 'main')

Loading…
Cancel
Save