Skip to content

Commit a1f2f5a

Browse files
committed
Add error message when cargo fix on an empty repo
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
1 parent 1382b44 commit a1f2f5a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/cargo/ops/fix.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ fn check_version_control(config: &Config, opts: &FixOptions) -> CargoResult<()>
154154
if let Ok(repo) = git2::Repository::discover(config.cwd()) {
155155
let mut repo_opts = git2::StatusOptions::new();
156156
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+
}
157165
for status in repo.statuses(Some(&mut repo_opts))?.iter() {
158166
if let Some(path) = status.path() {
159167
match status.status() {

0 commit comments

Comments
 (0)