split_cl: Make description file optional during dry runs

I frequently find myself running `git cl split` just to see how the
files are going to be split up, without actually intending to submit the
resulting CLs immediately. Doing so requires creating a file, putting a
dummy description in it, and passing that to the command line, which is
unnecessary work. This CL simply allows dry runs to use a dummy
description if none is provided, to make checking the tool's output
easier.

Bug: None
Change-Id: I47e06c6e6da26701e07dcae81ab605edac2e2ca6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6163904
Reviewed-by: Andy Perelson <ajp@google.com>
Commit-Queue: Devon Loehr <dloehr@google.com>
Reviewed-by: Brian Ryner <bryner@google.com>
This commit is contained in:
Devon Loehr
2025-01-10 12:57:14 -08:00
committed by LUCI CQ
parent 0929ef8d84
commit 24d9ad69fa
4 changed files with 56 additions and 5 deletions

View File

@@ -218,6 +218,14 @@ def PrintClInfo(cl_index, num_cls, directories, file_paths, description,
print()
def LoadDescription(description_file):
if not description_file:
return ('Dummy description for dry run.\n'
'directory = $directory')
return gclient_utils.FileRead(description_file)
def SplitCl(description_file, comment_file, changelist, cmd_upload, dry_run,
cq_dry_run, enable_auto_submit, max_depth, topic, repository_root):
""""Splits a branch into smaller branches and uploads CLs.
@@ -237,8 +245,10 @@ def SplitCl(description_file, comment_file, changelist, cmd_upload, dry_run,
Returns:
0 in case of success. 1 in case of error.
"""
description = AddUploadedByGitClSplitToDescription(
gclient_utils.FileRead(description_file))
description = LoadDescription(description_file, dry_run)
description = AddUploadedByGitClSplitToDescription(description)
comment = gclient_utils.FileRead(comment_file) if comment_file else None
try:
@@ -262,7 +272,7 @@ def SplitCl(description_file, comment_file, changelist, cmd_upload, dry_run,
assert refactor_branch_upstream, \
"Branch %s must have an upstream." % refactor_branch
if not CheckDescriptionBugLink(description):
if not dry_run and not CheckDescriptionBugLink(description):
return 0
files_split_by_reviewers = SelectReviewersForFiles(