Add "git cl cherry-pick" for cherry picking a chain of CLs via Gerrit

Users who want to upload multiple cherry picks usually run "git
cherry-pick" locally, multiple times. Gerrit does not recognize
these changes as cherry picks and neither do other services that
query cherry pick info from Gerrit, e.g. rubber stamper.

For Gerrit to identify a change as a true cherry pick, you need to
use their Cherry Pick Revision REST API endpoint. This new command
uses it to create a chain of cherry pick CLs recognized by Gerrit.

Bug: b/341792235
Change-Id: I4ba75da3901f6ea68c1debd65820e802da681798
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5756161
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
This commit is contained in:
Gavin Mak
2024-08-08 17:34:09 +00:00
committed by LUCI CQ
parent 75932421da
commit ec800aa077
3 changed files with 163 additions and 1 deletions

View File

@@ -1326,6 +1326,14 @@ def RestoreChange(host, change, msg=''):
return ReadHttpJsonResponse(conn)
def RebaseChange(host, change, base=None):
"""Rebases a change."""
path = f'changes/{change}/rebase'
body = {'base': base} if base else {}
conn = CreateHttpConn(host, path, reqtype='POST', body=body)
return ReadHttpJsonResponse(conn)
def SubmitChange(host, change):
"""Submits a Gerrit change via Gerrit."""
path = 'changes/%s/submit' % change
@@ -1387,12 +1395,14 @@ def DeletePendingChangeEdit(host, change):
ReadHttpResponse(conn, accept_statuses=[204, 404])
def CherryPick(host, change, destination, revision='current'):
def CherryPick(host, change, destination, revision='current', message=None):
"""Create a cherry-pick commit from the given change, onto the given
destination.
"""
path = 'changes/%s/revisions/%s/cherrypick' % (change, revision)
body = {'destination': destination}
if message:
body['message'] = message
conn = CreateHttpConn(host, path, reqtype='POST', body=body)
return ReadHttpJsonResponse(conn)