upload: add a --topic option for setting topic explicitly

Let people specify the exact topic when uploading CLs.  The existing
-t option only supports setting the topic to the current local branch.

Add a --topic-branch long option to the existing -t to align it a bit
better with --hashtag & --hashtag-branch.

Change-Id: I010abc4a7f3c685021cae776dd1e597c22b79135
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/431997
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger
2024-06-30 20:12:07 -04:00
committed by LUCI
parent 562cea7758
commit 87f52f308c
3 changed files with 24 additions and 13 deletions

View File

@ -218,9 +218,14 @@ Gerrit Code Review: https://www.gerritcodereview.com/
def _Options(self, p):
p.add_option(
"-t",
"--topic-branch",
dest="auto_topic",
action="store_true",
help="send local branch name to Gerrit Code Review",
help="set the topic to the local branch name",
)
p.add_option(
"--topic",
help="set topic for the change",
)
p.add_option(
"--hashtag",
@ -551,9 +556,12 @@ Gerrit Code Review: https://www.gerritcodereview.com/
# Check if topic branches should be sent to the server during
# upload.
if opt.auto_topic is not True:
key = "review.%s.uploadtopic" % branch.project.remote.review
opt.auto_topic = branch.project.config.GetBoolean(key)
if opt.topic is None:
if opt.auto_topic is not True:
key = "review.%s.uploadtopic" % branch.project.remote.review
opt.auto_topic = branch.project.config.GetBoolean(key)
if opt.auto_topic:
opt.topic = branch.name
def _ExpandCommaList(value):
"""Split |value| up into comma delimited entries."""
@ -620,7 +628,7 @@ Gerrit Code Review: https://www.gerritcodereview.com/
branch.UploadForReview(
people,
dryrun=opt.dryrun,
auto_topic=opt.auto_topic,
topic=opt.topic,
hashtags=hashtags,
labels=labels,
private=opt.private,