Skip to content

Commit 22690a3

Browse files
committed
Make --allow-dirty imply --allow-staged
1 parent fd78487 commit 22690a3

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

src/bin/cargo/commands/fix.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn cli() -> Command {
2121
))
2222
.arg(flag(
2323
"allow-dirty",
24-
"Fix code even if the working directory is dirty",
24+
"Fix code even if the working directory is dirty or has staged changes",
2525
))
2626
.arg(flag(
2727
"allow-staged",
@@ -86,6 +86,8 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
8686
opts.filter = ops::CompileFilter::new_all_targets();
8787
}
8888

89+
let allow_dirty = args.flag("allow-dirty");
90+
8991
ops::fix(
9092
gctx,
9193
&ws,
@@ -94,9 +96,9 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
9496
edition: args.flag("edition"),
9597
idioms: args.flag("edition-idioms"),
9698
compile_opts: opts,
97-
allow_dirty: args.flag("allow-dirty"),
99+
allow_dirty,
100+
allow_staged: allow_dirty || args.flag("allow-staged"),
98101
allow_no_vcs: args.flag("allow-no-vcs"),
99-
allow_staged: args.flag("allow-staged"),
100102
broken_code: args.flag("broken-code"),
101103
requested_lockfile_path: lockfile_path,
102104
},

src/cargo/ops/fix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn check_version_control(gctx: &GlobalContext, opts: &FixOptions) -> CargoResult
242242
bail!(
243243
"the working directory of this package has uncommitted changes, and \
244244
`cargo fix` can potentially perform destructive changes; if you'd \
245-
like to suppress this error pass `--allow-dirty`, `--allow-staged`, \
245+
like to suppress this error pass `--allow-dirty`, \
246246
or commit the changes to these files:\n\
247247
\n\
248248
{}\n\

src/doc/man/cargo-fix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Fix code even if a VCS was not detected.
9393
{{/option}}
9494

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

9999
{{#option "`--allow-staged`" }}

tests/testsuite/fix.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ fn warns_about_dirty_working_directory() {
635635
p.cargo("fix")
636636
.with_status(101)
637637
.with_stderr_data(str![[r#"
638-
[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:
638+
[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:
639639
640640
* src/lib.rs (dirty)
641641
@@ -656,7 +656,7 @@ fn warns_about_staged_working_directory() {
656656
p.cargo("fix")
657657
.with_status(101)
658658
.with_stderr_data(str![[r#"
659-
[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:
659+
[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:
660660
661661
* src/lib.rs (staged)
662662
@@ -677,7 +677,7 @@ fn errors_about_untracked_files() {
677677
p.cargo("fix")
678678
.with_status(101)
679679
.with_stderr_data(str![[r#"
680-
[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:
680+
[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:
681681
682682
* Cargo.toml (dirty)
683683
* src/ (dirty)

0 commit comments

Comments
 (0)