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>
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>
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>
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>
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>
* 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
`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>
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>