Skip to content

Commit

Permalink
Make --allow-dirty imply --allow-staged
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Jan 4, 2025
1 parent fd78487 commit 22690a3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
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
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

0 comments on commit 22690a3

Please sign in to comment.