-
Notifications
You must be signed in to change notification settings - Fork 893
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 fmt should not run on a dirty repository by default #3862
Comments
Disallowing |
I realise finding a solution which makes everyone happy here is tough! Possibly though there are a couple of options:
... but I'm also a realist, and recognise that maintaining the status quo may be the best feasible solution. |
Just wanted to add my two cents here, fully aware that this seems like a topic where reasonable folks will disagree. IMHO formatting-related problems like the example tend to surface in certain contexts with certain user behaviors, and I think the most feasible solution is to address those behaviors/contexts. For example:
That being said, as it relates to the proposed solutions in the OP:
I don't think that'd be viable either, and I also think that the responsibility of undo/rollback of changes belongs to the VCS. Once finished,
I personally wouldn't like this, and agree with @topecongiro that it would be a big change. Refusing to run on a dirty repo by default or adding a
|
It seems the previous discussion got missed, so I'll copy it here. From @ehuss:
From myself:
In reply to @calebcartwright:
So enable-by-default with an opt-out? I generally prefer the other way around, but this is partially workable. Either way though, auto-detection would be much easier (saves project owners remembering to configure
|
I'm going to close this because the current behavior is expected, and desirable from the rustfmt perspective. If you want to prevent rustfmt from being executed against your project, then you can add a rustfmt config file to your project as discussed above. The version of rustfmt that'll ship with rust v1.58 will have stabilized options you can use to turn rustfmt off, and/or you can consider making the rustfmt config file invalid/unparseable if you want to account for contributors on earlier stable versions. |
I don't want to disable rustfmt. I want to use it, but only when there are no changes between the working directory and the "git index", so that and changes made by rustfmt can be checked. |
Fair enough, but that's still not something I want to bake into rustfmt directly. For the interim, I think that use case would be best handled by a higher level script/task runner that makes the conditional check for whether or not to invoke rustfmt. If such a feature is sufficiently widely desired then perhaps we'd consider incorporating it into a new binary we ship with the existing set, or perhaps integrating it with the existing |
Good point. This ought to do it. |
Moved from rust-lang/cargo#7509
Problem
cargo fmt
; find formatting changes to old code + new code all mixed up(Yes, I am fully aware that some people frequently do this on purpose. More than once I have received PRs with commits mixing up significant amounts of reformatting and new code.)
Possible Solution(s)
cargo fix
,cargo publish
etc. refuse to run on a dirty repository by default (but allow override with--allow-dirty
). Please do the same forcargo fmt
.The above is only really a problem when significant amounts of old code were not previously formatted, so possibly Cargo+rustfmt could try to detect this first.
An alternative solution might be to make it possible to undo
cargo fmt
, but I don't see a clean way to do this.The text was updated successfully, but these errors were encountered: