Commit Graph

1367 Commits

Author SHA1 Message Date
Gennady Tsitovich
90eb3fe8ba Add --allow-conflicts option to git cl cherry-pick
This CL adds a new --allow-conflicts flag to the `git cl cherry-pick`
command. This allows users to create cherry-pick CLs on Gerrit even if
they result in merge conflicts. The created CL will be in a WIP state,
allowing the user to resolve conflicts in the Gerrit UI or locally.

Additionally, this CL:
- Updates `CMDcherry_pick` to print a regex-friendly warning if the
  created cherry-pick contains conflicts:
  "Warning: Change <URL> contains merge conflicts"
  (needed for the Chrome Cherry Picker)
- Fixes some existing test failures in `gerrit_util_test.py` related to
  authentication mocking in the current environment.
- Adds unit tests for the new flag in both `git_cl_test.py`
  and `gerrit_util_test.py`.

Bug: 439992429
Change-Id: I306e21329688a31a63c9996f1405f5ef5ad07108
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7319362
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gennady Tsitovich <gtsitovich@google.com>
2026-01-06 03:47:38 -08:00
Peter Wen
04f3706a63 git_cl.py: Process comments as threads
Refactor GetCommentsSummary to group individual comments into threads. A
thread is considered unresolved if and only if its last comment is
unresolved.

This fixes a bug where a resolved thread (one that had been replied to
and the resolved box checked in the reply) would still appear with the
--unresolved flag, because the initial comment in the thread is
permanently marked as unresolved.

This change also introduces a CommentInfo dataclass to improve
ergonomics for handling comment data from the Gerrit API.

The display of comments have not been made thread-aware to reduce the
scope of this change.

R=agrieve@chromium.org

Bug: 463411949
Fixed: 463411949
Change-Id: I966f011140ee3874b54d8afbbe00caed7bbe14eb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7200823
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Auto-Submit: Peter Wen <wnwen@chromium.org>
Commit-Queue: Peter Wen <wnwen@chromium.org>
2025-12-03 06:16:04 -08:00
Josiah Kiehl
c443d30d39 Suppress stack trace for GitPushError
Change-Id: Idcd1cfb41cf1cf9a3bfb252f6a8c109cbce5a5f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7132480
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Josiah Kiehl <kiehl@google.com>
2025-11-07 14:49:28 -08:00
Allen Li
84cfb15478 git_cl: Add some debug logging for get_cl_statuses
Bug: 420961720
Change-Id: I54280c7f3cfd200e02f63c9cedbf95fc393b8b4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7124755
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-11-05 16:49:40 -08:00
Jiewei Qian
240cd02c29 reauth: implement GitCreds credential pre-flight checks
This CL implements ensure_authenticated() for GitCredsAuthenticator, and
adds ReAuth support.

This check performs best-effort credential checks before performing
expensive operations such as presubmit hooks. This allows us to fail fast when an ReAuth token is missing for a contributor subject to
ReAuth requirements.

If you suspect this CL has caused a breakage on CL upload, please
revert.

Bug: 451651615
Change-Id: I42f3ffe3c830ed7bd2322f6cf2ad8adbba7e7251
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7036772
Reviewed-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Jiewei Qian <qjw@chromium.org>
2025-11-04 11:38:19 -08:00
Andrew Grieve
33744dc6bc Make google-java-format easier to use for non-chromium checkouts like R8
1. Use "codereview.settings" in addition to "buildtools" as the marker
   that identifies a project root.
2. Allow the presence of any .jar file to indicate the availability of
   google-java-format.
3. Do not pass --aosp when running google-java-format

Bug: 456461246
Change-Id: Id27b3c03f592a0ed73fb7a6b4dd662707a649166
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7102758
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
2025-10-30 12:05:33 -07:00
Jiewei Qian
cd260a79de git-cl: fix gerrit_host and git_host ordering in ensure_authenticated
ensure_authenticated was defined to take gerrit_host then git_host,
but the callsite got it flipped in https://crrev.com/c/5665455

This CL fixes the mistake, and also changed the method signature to
require kwargs argument (and hopefully make it easier to spot and avoid
such mistakes).

Note, this change shouldn't impact normal operation. Only the deprecated
CookiesAuthenticator relies on git_host and gerrit_host, which is not
used when New Auth Stack is enabled.

Bug: 451651615
Change-Id: I8157f3bd4cd51cc78dc4e1c2a917682ced91da86
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7077739
Auto-Submit: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Scott Lee <ddoman@chromium.org>
2025-10-23 10:07:32 -07:00
Aleksei Khoroshilov
3ed583625f Fix _RunRustFmt command line length issues and Windows compatibility
* Split file paths into batches using _SplitArgsByCmdLineLimit to avoid
  command line length limits.
* Add shell=False to subprocess call, because depot_tools-bundled
  subprocess2 wrapper sets it to True on Windows which prevents the use
  of full 32k command line limit.

Change-Id: Ifdd470087e34b1d9de54309c7915691e3e624f0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7062914
Reviewed-by: Scott Lee <ddoman@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Aleksei Khoroshilov <akhoroshilov@brave.com>
2025-10-21 23:37:56 -07:00
Jiewei Qian
390653d066 git-cl: remove newauthstack early return in EnsureAuthenticated
This CL removes an early return when new auth stack is enabled in
EnsureAuthenticated.

The early returned was added to make dogfood UX better. Now that
the new auth stack is shipped and enabled, this early return
shouldn't be necessary.

Removing this early return would allow us to check ReAuth state and
early fail `git cl upload` when a committer hasn't ReAuth-ed for
the day.

Bug: 451651615
Change-Id: I7ed728c3625c712c9fe3582cdd035b6940aeb062
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7064039
Auto-Submit: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
Commit-Queue: Jiewei Qian <qjw@chromium.org>
2025-10-21 15:54:10 -07:00
Scott Lee
f39ee3c673 format: pass --no-renames to git-diff
git cl presubmit runs git diff with `--no-renames` when it computes
the diff to find what sections to format.

In contrast, git cl format doesn't pass the param, causing the diff
computation producing unmatched lines to the diffs produced by
git cl presubmit, which gets generated with --no-renames.

This CL updates `git cl format` to generate diffs with --no-renames
to match the results with git cl presubmit. Find the bug for more info

Bug: 450323464
Change-Id: I854061f53887b36a2a860542a56e1f40f9e674c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7038553
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Reviewed-by: Brian Sheedy <bsheedy@chromium.org>
Auto-Submit: Scott Lee <ddoman@chromium.org>
Commit-Queue: Scott Lee <ddoman@chromium.org>
2025-10-13 15:08:05 -07:00
Gavin Mak
8d28f8ce96 Fix git cl patch for sso:// URLs
URL normalization logic incorrectly compares sso:// and https:// URLs.
Unify the logic to treat both schemes identically.

Bug: 450461206, 429002243
Change-Id: I912b286d787a43b34304ed3be521d9d6927ba414
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7031038
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Scott Lee <ddoman@chromium.org>
2025-10-13 13:29:42 -07:00
Jiewei Qian
73e46667ed Reland "git-cl: make SetReview ReAuth capable"
This is a reland of commit 6da6aecbb4

There's no change from the original CL and this reland. The revert was
addressed by adding ReAuth support to machine / bot authenticators,
namely GceAuthenticator (https://crrev.com/c/6965527) and
LuciContextAuthenticator (https://crrev.com/c/6967915).

The above changes should stop gerrit_util.SetReview from raising ReAuthRequired errors.

Bug: 442666611

Original change's description:
> git-cl: make SetReview ReAuth capable
>
> This CL changes SetReview to be ReAuth capable.
>
> This is a potential breaking change if an downstream script relies on
> gerrit_util.SetReview but hasn't implemented ReAuth.
>
> If this caused breakage, please refer to https://chromium.googlesource.com/chromium/src.git/+/HEAD/docs/gerrit_reauth.md#Troubleshooting for troubleshooting instructions.
>
> If the above doesn't work, please report a bug, then add `LUCI_BYPASS_REAUTH=1` to the environment to disable ReAuth for now.
>
> Bug: 442666611
> Change-Id: I7724f15f166f9975fc88be5d8e1c93be4e1ec302
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6939308
> Reviewed-by: Allen Li <ayatane@chromium.org>
> Reviewed-by: Scott Lee <ddoman@chromium.org>
> Commit-Queue: Jiewei Qian <qjw@chromium.org>

Bug: 442666611
Change-Id: I53636e54c732ec399b053500d664097ebacca05e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6967916
Commit-Queue: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
2025-09-24 20:59:02 -07:00
Allen Li
06da8b2a8f git_cl: Delete usages of AutoConfigure
Has been no-op for a while, remove it now

Bug: 446999231
Change-Id: I9f4e5b9cbd6a5cb8e84fba2f0ebb949b2a88d9ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6981220
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-09-24 16:06:55 -07:00
Allen Li
838e4c6aa7 [git_cl] Remove the auto cleanup from disabled new auth
This is in preparation for removing the old auto config code.  New
auth has been rolled out stably for a long time now, and in any case
the auto config/cleanup code isn't super reliable (hence why we're
removing it).

We remove this final callsite before deleting all of the relevant
code, and leave a message of assistance in case anyone needs it.

Bug: 446999231
Change-Id: Ia13e5d75a89a4ddfb178ee9e4fe2090596493218
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6976601
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
2025-09-23 19:52:53 -07:00
Jiewei Qian
9b361d9c09 git-cl: catch "ReAuth is required" error and re-raise is properly
This CL updates _RunGitPushWithTraces to detect git credential-luci
"ReAuth is required" error and propagate it nicely to the caller.

Previously, the error is uncaught, and re-raised with nested exception
stacktrace. The result was an unhelpful traceback, where the true error
is at the top (part of git push stdout/stderr).

This CL now propagate the error with a clear GitPushError printed last
(which hopefully gets developer's attention).

Fixed: 445532843
Change-Id: I789a6902b59af2c9df92fc7d013829afc4154dc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6954695
Commit-Queue: Scott Lee <ddoman@chromium.org>
Reviewed-by: Allen Li <ayatane@chromium.org>
Auto-Submit: Jiewei Qian <qjw@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
2025-09-22 15:06:26 -07:00
Andrew Grieve
9d57bd01e8 git cl comments: Add --unresolved & improve --json-file
* Don't output to non-json format when --json-file is passed
* Format individual comments as JSON when --json-file is used
* Add "unresolved" field to comments
* --unresolved flag will show only unresolved comments
* Better error message when no issue is associated with the branch

I intend to use this to have gemini-cli fix comments:
https://chromium-review.googlesource.com/c/chromium/src/+/6944524

Change-Id: I3b4d594b065751a600661a89925c69ffbf22aed5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6944465
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
2025-09-17 11:28:23 -07:00
Jacek Dobrowolski
c932af8f97 Revert "git-cl: make SetReview ReAuth capable"
This reverts commit 6da6aecbb4.

Reason for revert: Breaks official chrome release.

Original change's description:
> git-cl: make SetReview ReAuth capable
>
> This CL changes SetReview to be ReAuth capable.
>
> This is a potential breaking change if an downstream script relies on
> gerrit_util.SetReview but hasn't implemented ReAuth.
>
> If this caused breakage, please refer to https://chromium.googlesource.com/chromium/src.git/+/HEAD/docs/gerrit_reauth.md#Troubleshooting for troubleshooting instructions.
>
> If the above doesn't work, please report a bug, then add `LUCI_BYPASS_REAUTH=1` to the environment to disable ReAuth for now.
>
> Bug: 442666611
> Change-Id: I7724f15f166f9975fc88be5d8e1c93be4e1ec302
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6939308
> Reviewed-by: Allen Li <ayatane@chromium.org>
> Reviewed-by: Scott Lee <ddoman@chromium.org>
> Commit-Queue: Jiewei Qian <qjw@chromium.org>

Bug: 442666611
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I7b7e769b5a8011d45e976e471d0f2e43f186e0c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6955930
Commit-Queue: Alex Kravchuk <alexanderkr@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Owners-Override: Ben Mason <benmason@chromium.org>
2025-09-17 03:52:50 -07:00
Jiewei Qian
6da6aecbb4 git-cl: make SetReview ReAuth capable
This CL changes SetReview to be ReAuth capable.

This is a potential breaking change if an downstream script relies on
gerrit_util.SetReview but hasn't implemented ReAuth.

If this caused breakage, please refer to https://chromium.googlesource.com/chromium/src.git/+/HEAD/docs/gerrit_reauth.md#Troubleshooting for troubleshooting instructions.

If the above doesn't work, please report a bug, then add `LUCI_BYPASS_REAUTH=1` to the environment to disable ReAuth for now.

Bug: 442666611
Change-Id: I7724f15f166f9975fc88be5d8e1c93be4e1ec302
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6939308
Reviewed-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Jiewei Qian <qjw@chromium.org>
2025-09-16 17:00:01 -07:00
Ergun Erdogmus
6b4f0bfc22 [DevToolsGardener] Fix git cl format --js --full causing an error
`RunGitDiffCmd` with `--name-only` returns the files separated
by a new line as a string and then `FindFilesToFormat` splits it
to convert it to a files list.

Previously, we were calling `keys()` on this list and it
was throwing an error. Simply returning the file names
should be enough.

See the failure in:
https://logs.chromium.org/logs/devtools-frontend/buildbucket/cr-buildbucket/8703934325829680961/+/u/Scripted_rolls/Update_Browser_Protocol_deps/Run_Browser_Protocol_script/stdout

Bug: 386840832
Change-Id: I7bf54089726a66867c9126b1c398e8e57cc6eb26
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6943433
Reviewed-by: Scott Lee <ddoman@chromium.org>
Reviewed-by: Alex Rudenko <alexrudenko@chromium.org>
Auto-Submit: Ergün Erdoğmuş <ergunsh@chromium.org>
Commit-Queue: Scott Lee <ddoman@chromium.org>
2025-09-12 08:41:52 -07:00
Scott Lee
363e910475 git_cl: update the clang, java, and yapf formatters to be git-free
This makes the formatter runners to be git-free if --input_diff_file
is given. They still run `git diff`, if --diff is given. However,
for the purpose of making the presubmit check for format verification
git-free, it's ok as --diff is not used by the presubmit check.


Bug: 386840832
Change-Id: If5ab68fa4e2fec1aafa22e15ddeabb744993342b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6931775
Commit-Queue: Scott Lee <ddoman@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
2025-09-11 10:28:39 -07:00
Scott Lee
5ed7fd0ea5 git_cl: add --input_diff_file for git cl format
If the option is given, git cl format uses the input diff file to
determine the files and sections to format instead of git-diff.

The intended use case is to remove git dependencies in case
presubmit_support.py is executed with a diff file and it calls
presubmit_canned_checks.CheckPatchFormatted().

Bug: 386840832
Change-Id: Ia1eacd1bdb81731e07753df19ebf1d2470c9f1aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6912693
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Scott Lee <ddoman@chromium.org>
2025-09-10 14:38:11 -07:00
Jiewei Qian
958e89cc41 git-cl: disable git ASKPASS and TERMINAL_PROMPT
Disable interactive authentication so that git won't prompt for username
/ password when the LUCI access token or ReAuth token expired.

Bug: 443632112
Change-Id: Ie347042178facd113df0d96b1909097cebdbb400
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6918922
Reviewed-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Jiewei Qian <qjw@chromium.org>
2025-09-09 16:42:12 -07:00
Scott Lee
9c3171ffea git_cl: rename params and reduce indent
Cosmetic changes for consistent param names and unnecessary indents.

Bug: 400759419
Change-Id: I7845f0b059c66f4d6ceb8c4055d71b8704ff29fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6918336
Auto-Submit: Scott Lee <ddoman@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
2025-09-05 11:26:00 -07:00
Allen Li
e46459f0d3 git cl: Handle URL variations more robustly
Bug: 429002243
Change-Id: I0638da9f7ddf8f82078b13331d5890ad8b2421ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6917276
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-09-04 15:41:18 -07:00
Andy Perelson
615f4a2f03 Remove support for RobotComments, which have been removed from Gerrit.
Bug: 428171766
Change-Id: I38ddbf4a934f80897301d2fd04d8b83a799b1bd7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6690195
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Andy Perelson <ajp@google.com>
2025-07-01 14:23:35 -07:00
Gavin Mak
d0540cbe13 Add rev to rootRepo push option
Bug: 401148931
Change-Id: I19dd68ef56e07b24a442ec964dd49e52fa3a8385
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6579730
Reviewed-by: Scott Lee <ddoman@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
2025-05-28 11:59:51 -07:00
Michael Cui
332e5f1815 git_cl: Use tuple argument to str.endswith in CMDformat
This greatly simplifies `MatchingFileType`, so it is now inlined.

Bug: None
Change-Id: I6a6a21009aa2193a85383fe1db7c401b8fd9c4fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6508213
Commit-Queue: Michael Cui <mlcui@google.com>
Reviewed-by: Scott Lee <ddoman@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
2025-05-27 17:18:27 -07:00
Aleksey Khoroshilov
a9cc320bf7 git cl format: Fix return code when using both --dry-run and --diff
When running `git cl format` with both --dry-run and --diff flags, some
formatters weren't returning exit code 2 when files needed formatting.
This made it impossible to detect formatting issues when using both
flags together.

Modified the following formatters to consistently return exit code 2
when files need formatting under --dry-run --diff flags:
- java
- rustfmt
- swift-format
- yapf
- gn

Also fixed incorrect usage of --presubmit flag in rustfmt and
swift-format. This flag is only intended to filter out formatters that
have dedicated presubmit checks, not to control their return codes.
Since CheckPatchFormatted in presubmit_canned_checks.py always passes
both --dry-run and --presubmit flags, the presubmit behavior remains
unchanged.

Change-Id: I4c26f22fc197c700a5c08d42b96ea4fc535ce293
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6509717
Commit-Queue: Aleksei Khoroshilov <akhoroshilov@brave.com>
Auto-Submit: Aleksei Khoroshilov <akhoroshilov@brave.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Reviewed-by: Scott Lee <ddoman@chromium.org>
2025-05-14 01:13:36 -07:00
Fumitoshi Ukai
208d245ee8 git_cl: run gn.py instead of gn
fix for https://ci.chromium.org/ui/p/devtools-frontend/builders/try/dtf_presubmit_linux/b8715095169268935393/overview

Change-Id: I1fa4565ffe44ea0ed29b4b8710ddf933d19f9f44
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6536211
Commit-Queue: Brian Ryner <bryner@google.com>
Reviewed-by: Brian Ryner <bryner@google.com>
Auto-Submit: Fumitoshi Ukai <ukai@google.com>
Reviewed-by: Takuto Ikuta <tikuta@chromium.org>
Reviewed-by: Liviu Rau <liviurau@chromium.org>
2025-05-12 06:22:14 -07:00
Michael Cui
8c9aa83747 git_cl: Add type annotations to CMDformat and related functions
This should not change any runtime behaviour.

Bug: None
Change-Id: I6a6a2100826919ea8675b743adbcf3d4fbf05b66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6508212
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Michael Cui <mlcui@google.com>
2025-05-06 17:55:50 -07:00
Michael Cui
e760b35cbc git_cl: Replace += [...] with .append(...) in CMDformat
This should be a bit more understandable, especially as `formatters` is
a list of tuples.

Bug: None
Change-Id: I6a6a2100e5169f1270bc3167a584274f67b80ae8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6508211
Commit-Queue: Michael Cui <mlcui@google.com>
Reviewed-by: Scott Lee <ddoman@chromium.org>
2025-05-06 17:50:15 -07:00
Gavin Mak
4edb194e91 Set rootRepo custom-keyed-value push option on upload
This associates a CL with its superproject.

Bug: 401148931
Change-Id: I7fe7bd91485e6e1066963b25f1b95980db6d3381
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6476918
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
2025-04-29 09:30:41 -07:00
Allen Li
3b66d05bd8 [git_auth] Inject Changelist dependency into ConfigWizard
Otherwise it creates a dependency cycle.  This is needed if we want to
recurse into submodules.  Maybe this should be refactored more, but
this should be an improvement for now.

Change-Id: I4641e9ce1952bba81f717acbeefd59dd687d87ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6448579
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-04-14 13:33:58 -07:00
Allen Li
f5b53c0e98 [git_cl] Add --global to creds-check
The UX of cd'ing to a non-Gerrit repo to setup common repo auth is not
good.  Also people don't read.

Bug: 408501013
Change-Id: Ia31914cf8672d0b5a6033de11c928140fd34a95c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6442235
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-04-08 15:16:09 -07:00
Yiwei Zhang
718c314171 git-cl: use latest commit message in no-squash mode for presubmit
In no-squash mode, when uploading the change, the latest commit message
will be used as the CL description based on my experiment ([1] is never
honored). Therefore, no-squash mode should always use the commit message
as the CL description to run presubmit rather the current description in
the CL

[1]:
https://source.chromium.org/chromium/chromium/tools/depot_tools/+/main:git_cl.py;l=3232;drc=2bfa28f442009c4db0735c8789c611f3cfb3031c

Change-Id: I0ca45189095817dbedc916c7b882549c8f0868a1
Bug: 404309440
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6426443
Commit-Queue: Yiwei Zhang <yiwzhang@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
2025-04-08 10:51:21 -07:00
Allen Li
47701fdcd0 [git_cl] Fix creds_check new auth switch logic pt 3
Third time's the charm.  The issue is still the "multi-valued boolean"
logic.  I introduce a new "switched on" concept to clarify things.

If new auth is "switched off", then all new auth related things are
off.  Simple enough.

There are two ways for new auth to be "switched on".  Either it is
explicitly enabled in the user's config, or we rolled out the default
to on.

When it is "switched on", we still rely on the presence of .gitcookies
to determine whether we enable new auth for depot_tools.  HOWEVER, we
must use the new git cl creds-check, because that is the intended way
for users to remove their .gitcookies file.

                     | auth logic | creds-check |
switched off         | old        | old         |
switched on +cookies | old        | new         |
switched on -cookies | new        | new         |

Change-Id: I311089960d78d8be2cdffd00e4515bfebf0f8f58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6439385
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
2025-04-07 15:14:41 -07:00
Allen Li
50e0120582 [git_cl] Fix creds_check new auth switch logic pt 2
I got greedy with the first fix, with the assumption that the flag
enablement would not get rolled back.  As it would be easier to not
worry about this logic flip-flopping based on the default flag
flip-flopping.

Spoilers: it did get rolled back, so we end up with the new
creds-check with the newauth flag defaulting to off.  And this causes
a UX problem because new users would get prompted to run creds-check
to set up a gitcookies file, but the new creds-check logic doesn't do
that.

Based on our newfound experience, this should just follow the default
value.  There'll still be some friction whenever we flip-flop the default
value, but that's kind of unavoidable.

Change-Id: I0d81ed4123a8a9bced2fc4300214376cd3f1c9d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6434738
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-04-04 17:02:49 -07:00
Gennady Tsitovich
6cc266569e git cl cherry-pick: Use base parameter to fix identical tree errors
The `git cl cherry-pick` command previously created chained CLs by
first cherry-picking a change onto the destination branch tip and then
rebasing the result onto the parent CL created in the previous step.

This approach failed when a sequence of cherry-picks resulted in an
intermediate state having an identical tree compared to its intended
base (e.g., commit 1 changes X->Y, commit 2 changes Y->X). Gerrit
would reject the second cherry-pick with an "identical tree" error
because the rebase is done after the cherry pick.

This change modifies the process to use the `base` parameter of the
Gerrit `cherrypick` REST API endpoint.

Changes:
- Modify `gerrit_util.CherryPick` to accept and pass an optional `base`
  commit hash in the API request body.
- Update `git_cl.CMDcherry_pick`:
  - Before each cherry-pick operation in the loop, fetch the commit hash
    of the latest patchset from the previously processed parent CL.
  - Pass this commit hash as the `base` parameter to `gerrit_util.CherryPick`.
  - Remove the subsequent, now redundant, call to `gerrit_util.RebaseChange`.

This ensures the correct parent commit is specified during the
cherry-pick operation itself, allowing Gerrit to handle the chaining
correctly and avoid failures caused by identical tree states in
intermediate steps.

Bug: 408388488
Change-Id: I84066d65bd6bb127b253bee6564dd0622148a0e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6433112
Commit-Queue: Gennady Tsitovich <gtsitovich@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
2025-04-04 11:44:55 -07:00
Allen Li
9e7aa23589 [git_cl] Fix creds_check new auth switch logic
The three-way logic here (explicitly on, default (which is now on),
explicitly off) was slightly off.

Bug: 408243787
Change-Id: Idc0b55e63627708fe257ea7ca5a7f5f5dd5e1c08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6431386
Reviewed-by: Gavin Mak <gavinmak@google.com>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-04-03 17:50:27 -07:00
Allen Li
2bfa28f442 [newauth] Print warning for .gitcookies file
This will print a warning and disable new auth if .gitcookies file
exists.

This ensures we don't break bots once we default new auth on while
pushing human users away from .gitcookies.

Bug: b/404613530
Change-Id: Ia2d05bb7e5d2bf11e5605a26ef492954acbd9833
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6367723
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-03-19 15:44:36 -07:00
Allen Li
a2c6f107c3 [git_auth] Move config wizard to creds-check
Bug: b/404613530
Change-Id: Ie0b8fd675b66739a129d5eeeda895473a8a49eeb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6368999
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
2025-03-19 14:01:37 -07:00
Allen Li
8fecc592a2 Add auth config wizard
Make this available for testing first.

This should be functionally roughly analogous with the current auto
configuration logic, and it prints all actions it performs so it
should be pretty safe to play with, even if it hypothetically
misbehaves.

Bug: b/401338175
Change-Id: I803c7e167e355ec8cca1f5959099138c2fee305e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6334614
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Allen Li <ayatane@chromium.org>
2025-03-14 17:00:13 -07:00
Scott Lee
330c155fd0 Revert "pass -sort-includes to clang-format-diff.py by default"
This reverts commit 764c8c0616.

Reason for revert: Please find https://g-issues.chromium.org/issues/402201301#comment10

Original change's description:
> pass -sort-includes to clang-format-diff.py by default
>
> clang-format-diff takes a diff output as input, and formats
> the input file, but the changed lines only.
>
> In crbug.com/402201301, it was found that it sometimes breaks
> includes grouping because it tries to format the changed include
> lines only.
>
> This CL is to pass "-sort-includes" to clang-format-diff.py so that
> it always formats the include blocks, even if they are not part of
> the changes included.
> https://source.chromium.org/chromium/chromium/src/+/main:third_party/clang-format/script/clang-format-diff.py;l=70-75;drc=d2bee6477349e500ed274b15a9da8e062a0fcf27
>
> Bug: 402201301
> Change-Id: I214ae15202469dd5c7d55c2eb43c4cce39ad731b
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6343956
> Commit-Queue: Scott Lee <ddoman@chromium.org>
> Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>

Bug: 402201301
Change-Id: Ibfc70b68a9153d242bc011dfe17a73d671760842
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6355303
Commit-Queue: Scott Lee <ddoman@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
2025-03-13 16:07:58 -07:00
Scott Lee
764c8c0616 pass -sort-includes to clang-format-diff.py by default
clang-format-diff takes a diff output as input, and formats
the input file, but the changed lines only.

In crbug.com/402201301, it was found that it sometimes breaks
includes grouping because it tries to format the changed include
lines only.

This CL is to pass "-sort-includes" to clang-format-diff.py so that
it always formats the include blocks, even if they are not part of
the changes included.
https://source.chromium.org/chromium/chromium/src/+/main:third_party/clang-format/script/clang-format-diff.py;l=70-75;drc=d2bee6477349e500ed274b15a9da8e062a0fcf27

Bug: 402201301
Change-Id: I214ae15202469dd5c7d55c2eb43c4cce39ad731b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6343956
Commit-Queue: Scott Lee <ddoman@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
2025-03-11 16:22:11 -07:00
Peter Wen
5d5ea66f01 git_cl: Add flag for owners override
This allows setting OO+1 with `git cl upload --enable-owners-override`.

R=sokcevic@chromium.org

Bug: None
Change-Id: Iddac69653a539a15beee38ea4957be1a9b19b57a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6340467
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Peter Wen <wnwen@chromium.org>
Auto-Submit: Peter Wen <wnwen@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
2025-03-10 12:20:08 -07:00
Devon Loehr
9dc0551d52 [git cl split] Add new cluster-based splitting algorithm
This CL adds a new way of generating splittings, which clusters files
based on their directory structure (while respecting `set noparent` in
OWNERS files). The user provides a minimum and maximum acceptable
number of files per CL, and the algorithm attempts to create CLs in
that range with a single unique reviewer for each. I've tested it on
some example CLs, and it seems to work well -- certainly better than
the existing algorithm.

Usage of the new algorithm is triggered by passing the
`--target-range` option to `git cl split`. A second new argument,
`--expect-owners-override`, may also be used to ignore OWNERS during
the clustering algorithm.

Bug: 389069356
Change-Id: I321e6424b2bdb7624b370af23b73759fda261161
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6324373
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Devon Loehr <dloehr@google.com>
2025-03-10 07:15:06 -07:00
Josip Sokcevic
dbfdedfa08 Fix root path on Windows
User may use lowercase drive letter when entering gclient workspace.
In such case, path should be corrected to real path value.

R=wfh@chromium.org

Fixed: 401141847
Change-Id: I0b08985ec5c911a315922858d248ff53a10ed682
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6336450
Auto-Submit: Josip Sokcevic <sokcevic@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Yiwei Zhang <yiwzhang@google.com>
2025-03-07 14:00:32 -08:00
Devon Loehr
f0b8c3b16c [git cl split]: Allow users to override reviewer assignment
This CL adds a --reviewers flag, which allows users to specify that CLs
should all be sent to the same (possibly empty) set of reviewers. This
can be useful for LSCs where OO+1 is available.

Bug: 389069356, 40269201
Change-Id: Ic6202b280bb676f75a71c4ccf0c41b32483d5c6e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6298664
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Devon Loehr <dloehr@google.com>
2025-02-25 11:36:51 -08:00
Devon Loehr
4629c3474e [git cl split]: Deprecate $directory in favor of $description
`git cl split` allows users to parameterize their CL descriptions
by including the string $directory, which is replaced by the list of
directories covered by each generated CL. However, as we add more ways
of generating splittings, a list of directories may not always be the
most appropriate description. For example, the --from-file option lets
users write arbitrary description strings.

This CL renames the $directory string to $description, to reflect this
new generality, and refactors all places in the code that expected a
directory list instead of a string. Since users may beused to the
current version, it does not remove $directory, but instead notes that
it is deprecated and emits a warning when it is used. After some time,
we can remove it entirely.

Bug: 389069356
Change-Id: If8c947fdcbbb4897675b015a377cf21123e51467
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6299688
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Devon Loehr <dloehr@google.com>
2025-02-24 11:08:30 -08:00
Devon Loehr
158b6837dc [git cl split] Add summarize option during dry runs
Currently, the dry run setting causes the script to print out extremely
detailed information about the splitting it generated. While this is
sometimes useful, often users only care about the overall shape of the
splitting. This CL adds a flag which lets them see the same brief
summary that's printed during full runs.

Bug: 389069356
Change-Id: I473740e50f382e63b1289101f3253ff8ae9e6bbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6298096
Commit-Queue: Devon Loehr <dloehr@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
2025-02-24 10:32:27 -08:00