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

cargo fix does not warn about modifying untracked files #11380

Closed
TonalidadeHidrica opened this issue Nov 15, 2022 · 6 comments · Fixed by #11400
Closed

cargo fix does not warn about modifying untracked files #11380

TonalidadeHidrica opened this issue Nov 15, 2022 · 6 comments · Fixed by #11400
Assignees

Comments

@TonalidadeHidrica
Copy link

TonalidadeHidrica commented Nov 15, 2022

Transferred from rust-lang/rust-clippy#9838.

Summary

When cargo clippy --fix is ran on a crate that is not managed by a VCS, it warns about it and does not modify the code. This also happens if cargo clippy --fix is ran in a git repository that has uncommiteed changes. However, when it is ran on a repository with uncommited changes but without any commit, it modifies the code without an error or a warning.

Reproducer

set -eux

cargo +nightly new repro
cd repro
echo "fn main() { let _ = 0.clone(); }" > src/main.rs
cargo +nightly clippy --fix
cat src/main.rs
+ cargo +nightly new repro
     Created binary (application) `repro` package
+ cd repro
+ echo 'fn main() { let _ = 0.clone(); }'
+ cargo +nightly clippy --fix
    Checking repro v0.1.0 (/home/username/repro)
       Fixed src/main.rs (1 fix)
    Finished dev [unoptimized + debuginfo] target(s) in 0.19s
+ cat src/main.rs
fn main() { let _ = 0; }

Version

rustc 1.67.0-nightly (42325c525 2022-11-11)
binary: rustc
commit-hash: 42325c525b9d3885847a3f803abe53c562d289da
commit-date: 2022-11-11
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Additional Labels

No response

@ehuss ehuss changed the title cargo clippy --fix runs without warns on git repository without commit cargo fix does not warn about modifying untracked files Nov 15, 2022
@ehuss ehuss transferred this issue from rust-lang/rustfix Nov 15, 2022
@ehuss
Copy link
Contributor

ehuss commented Nov 15, 2022

Transferred to rust-lang/cargo, as the rustfix repo is only for the library which is not responsible for the determination of what to modify.

@Rustin170506
Copy link
Member

@rustbot claim

I'll try to fix it.

@Rustin170506
Copy link
Member

@ehuss Do you mind giving some tips about which code causes this issue? I read cargo fix code, but it seems for cargo fix instead of cargo clippy --fix?

@Rustin170506
Copy link
Member

I think the real root cause is these files are untracked files. So

for status in repo.statuses(Some(&mut repo_opts))?.iter() {
this code can not find these files.

For example, you can try this to test this behavior:

set -eux

cargo +nightly new repro
cd repro
echo "fn main() { let _ = 0.clone(); }" > src/main.rs
git add .
git commit -m "test"
echo "fn main() { let _ = 0.clone(); }" > src/main1.rs
cargo +nightly clippy --fix
cat src/main.rs

You will find cargo clippy fix will ignore src/main1.rs because this file is untracked.

So I think this is probably not a bug.

@ehuss
Copy link
Contributor

ehuss commented Nov 25, 2022

I think the StatusOpts needs to set include_untracked(true).

@Rustin170506
Copy link
Member

I think the StatusOpts needs to set include_untracked(true).

It works! Thanks!

@bors bors closed this as completed in a2ea66b Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants