From 22690a32367b27910c805583025ea6fd59dc3293 Mon Sep 17 00:00:00 2001 From: Kornel Date: Sat, 4 Jan 2025 00:22:53 +0000 Subject: [PATCH 1/2] Make --allow-dirty imply --allow-staged --- src/bin/cargo/commands/fix.rs | 8 +++++--- src/cargo/ops/fix.rs | 2 +- src/doc/man/cargo-fix.md | 2 +- tests/testsuite/fix.rs | 6 +++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/bin/cargo/commands/fix.rs b/src/bin/cargo/commands/fix.rs index a4471d7b148..38bd75497a4 100644 --- a/src/bin/cargo/commands/fix.rs +++ b/src/bin/cargo/commands/fix.rs @@ -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", @@ -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, @@ -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, }, diff --git a/src/cargo/ops/fix.rs b/src/cargo/ops/fix.rs index 1530e77f48e..fdd2b33f1df 100644 --- a/src/cargo/ops/fix.rs +++ b/src/cargo/ops/fix.rs @@ -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\ diff --git a/src/doc/man/cargo-fix.md b/src/doc/man/cargo-fix.md index 2c25720db48..efb116d69a8 100644 --- a/src/doc/man/cargo-fix.md +++ b/src/doc/man/cargo-fix.md @@ -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`" }} diff --git a/tests/testsuite/fix.rs b/tests/testsuite/fix.rs index f475fe5ba21..cd2de1d75d4 100644 --- a/tests/testsuite/fix.rs +++ b/tests/testsuite/fix.rs @@ -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) @@ -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) @@ -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) From 973cd5338e31ecb266c5f97df3ce8149c2f205b1 Mon Sep 17 00:00:00 2001 From: Kornel Date: Sat, 4 Jan 2025 14:37:39 +0000 Subject: [PATCH 2/2] Update autogenerated files --- src/doc/man/generated_txt/cargo-fix.txt | 3 +- src/doc/src/commands/cargo-fix.md | 2 +- src/etc/man/cargo-fix.1 | 2 +- .../testsuite/cargo_fix/help/stdout.term.svg | 110 +++++++++--------- 4 files changed, 60 insertions(+), 57 deletions(-) diff --git a/src/doc/man/generated_txt/cargo-fix.txt b/src/doc/man/generated_txt/cargo-fix.txt index 9b056183afa..f15544bfa29 100644 --- a/src/doc/man/generated_txt/cargo-fix.txt +++ b/src/doc/man/generated_txt/cargo-fix.txt @@ -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. diff --git a/src/doc/src/commands/cargo-fix.md b/src/doc/src/commands/cargo-fix.md index eefcd8a51b9..1a05599b488 100644 --- a/src/doc/src/commands/cargo-fix.md +++ b/src/doc/src/commands/cargo-fix.md @@ -89,7 +89,7 @@ edition.
--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
diff --git a/src/etc/man/cargo-fix.1 b/src/etc/man/cargo-fix.1 index b96c1e46ad1..f9896b8025a 100644 --- a/src/etc/man/cargo-fix.1 +++ b/src/etc/man/cargo-fix.1 @@ -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 diff --git a/tests/testsuite/cargo_fix/help/stdout.term.svg b/tests/testsuite/cargo_fix/help/stdout.term.svg index 3268041f100..1c860989650 100644 --- a/tests/testsuite/cargo_fix/help/stdout.term.svg +++ b/tests/testsuite/cargo_fix/help/stdout.term.svg @@ -1,4 +1,4 @@ - +