We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
cargo fix
1 parent 6553589 commit 4c6ed37Copy full SHA for 4c6ed37
src/cargo/ops/fix.rs
@@ -154,6 +154,14 @@ fn check_version_control(config: &Config, opts: &FixOptions) -> CargoResult<()>
154
if let Ok(repo) = git2::Repository::discover(config.cwd()) {
155
let mut repo_opts = git2::StatusOptions::new();
156
repo_opts.include_ignored(false);
157
+ if repo.is_empty()? {
158
+ bail!(
159
+ "no commits found in the git repository, and \
160
+ `cargo fix` can potentially perform destructive changes; if you'd \
161
+ like to suppress this error pass `--allow-dirty`, `--allow-staged`, \
162
+ or commit your changes"
163
+ )
164
+ }
165
for status in repo.statuses(Some(&mut repo_opts))?.iter() {
166
if let Some(path) = status.path() {
167
match status.status() {
0 commit comments