Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make --allow-dirty imply --allow-staged #15013

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/bin/cargo/commands/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn cli() -> Command {
))
.arg(flag(
"allow-dirty",
"Fix code even if the working directory is dirty",
"Fix code even if the working directory is dirty or has staged changes",
))
.arg(flag(
"allow-staged",
Expand Down Expand Up @@ -86,6 +86,8 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
opts.filter = ops::CompileFilter::new_all_targets();
}

let allow_dirty = args.flag("allow-dirty");

ops::fix(
gctx,
&ws,
Expand All @@ -94,9 +96,9 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
edition: args.flag("edition"),
idioms: args.flag("edition-idioms"),
compile_opts: opts,
allow_dirty: args.flag("allow-dirty"),
allow_dirty,
allow_staged: allow_dirty || args.flag("allow-staged"),
allow_no_vcs: args.flag("allow-no-vcs"),
allow_staged: args.flag("allow-staged"),
broken_code: args.flag("broken-code"),
requested_lockfile_path: lockfile_path,
},
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ fn check_version_control(gctx: &GlobalContext, opts: &FixOptions) -> CargoResult
bail!(
"the working directory of this package has uncommitted changes, and \
`cargo fix` can potentially perform destructive changes; if you'd \
like to suppress this error pass `--allow-dirty`, `--allow-staged`, \
like to suppress this error pass `--allow-dirty`, \
or commit the changes to these files:\n\
\n\
{}\n\
Expand Down
2 changes: 1 addition & 1 deletion src/doc/man/cargo-fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Fix code even if a VCS was not detected.
{{/option}}

{{#option "`--allow-dirty`" }}
Fix code even if the working directory has changes.
Fix code even if the working directory has changes (including staged changes).
{{/option}}

{{#option "`--allow-staged`" }}
Expand Down
3 changes: 2 additions & 1 deletion src/doc/man/generated_txt/cargo-fix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ OPTIONS
Fix code even if a VCS was not detected.

--allow-dirty
Fix code even if the working directory has changes.
Fix code even if the working directory has changes (including staged
changes).

--allow-staged
Fix code even if the working directory has staged changes.
Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/commands/cargo-fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ edition.</dd>


<dt class="option-term" id="option-cargo-fix---allow-dirty"><a class="option-anchor" href="#option-cargo-fix---allow-dirty"></a><code>--allow-dirty</code></dt>
<dd class="option-desc">Fix code even if the working directory has changes.</dd>
<dd class="option-desc">Fix code even if the working directory has changes (including staged changes).</dd>


<dt class="option-term" id="option-cargo-fix---allow-staged"><a class="option-anchor" href="#option-cargo-fix---allow-staged"></a><code>--allow-staged</code></dt>
Expand Down
2 changes: 1 addition & 1 deletion src/etc/man/cargo-fix.1
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Fix code even if a VCS was not detected.
.sp
\fB\-\-allow\-dirty\fR
.RS 4
Fix code even if the working directory has changes.
Fix code even if the working directory has changes (including staged changes).
.RE
.sp
\fB\-\-allow\-staged\fR
Expand Down
110 changes: 56 additions & 54 deletions tests/testsuite/cargo_fix/help/stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ fn warns_about_dirty_working_directory() {
p.cargo("fix")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] the working directory of this package has uncommitted changes, and `cargo fix` can potentially perform destructive changes; if you'd like to suppress this error pass `--allow-dirty`, `--allow-staged`, or commit the changes to these files:
[ERROR] the working directory of this package has uncommitted changes, and `cargo fix` can potentially perform destructive changes; if you'd like to suppress this error pass `--allow-dirty`, or commit the changes to these files:

* src/lib.rs (dirty)

Expand All @@ -656,7 +656,7 @@ fn warns_about_staged_working_directory() {
p.cargo("fix")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] the working directory of this package has uncommitted changes, and `cargo fix` can potentially perform destructive changes; if you'd like to suppress this error pass `--allow-dirty`, `--allow-staged`, or commit the changes to these files:
[ERROR] the working directory of this package has uncommitted changes, and `cargo fix` can potentially perform destructive changes; if you'd like to suppress this error pass `--allow-dirty`, or commit the changes to these files:

* src/lib.rs (staged)

Expand All @@ -677,7 +677,7 @@ fn errors_about_untracked_files() {
p.cargo("fix")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] the working directory of this package has uncommitted changes, and `cargo fix` can potentially perform destructive changes; if you'd like to suppress this error pass `--allow-dirty`, `--allow-staged`, or commit the changes to these files:
[ERROR] the working directory of this package has uncommitted changes, and `cargo fix` can potentially perform destructive changes; if you'd like to suppress this error pass `--allow-dirty`, or commit the changes to these files:

* Cargo.toml (dirty)
* src/ (dirty)
Expand Down
Loading