Skip to content

Commit 3189dc3

Browse files
committed
Include untracked files
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
1 parent 25f7d4b commit 3189dc3

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/cargo/ops/fix.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,7 @@ 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()? && !opts.allow_dirty {
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`, \
162-
or commit your changes"
163-
)
164-
}
157+
repo_opts.include_untracked(true);
165158
for status in repo.statuses(Some(&mut repo_opts))?.iter() {
166159
if let Some(path) = status.path() {
167160
match status.status() {

tests/testsuite/fix.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ commit the changes to these files:
772772
}
773773

774774
#[cargo_test]
775-
fn errors_on_empty_repo() {
775+
fn errors_about_untracked_files() {
776776
let mut git_project = project().at("foo");
777777
git_project = git_project.file("src/lib.rs", "pub fn foo() {}");
778778
let p = git_project.build();
@@ -782,10 +782,15 @@ fn errors_on_empty_repo() {
782782
.with_status(101)
783783
.with_stderr(
784784
"\
785-
error: no commits found in the git repository, \
786-
and `cargo fix` can potentially perform destructive changes; \
787-
if you'd like to suppress this error pass `--allow-dirty`, \
788-
or commit your changes
785+
error: the working directory of this package has uncommitted changes, \
786+
and `cargo fix` can potentially perform destructive changes; if you'd \
787+
like to suppress this error pass `--allow-dirty`, `--allow-staged`, or \
788+
commit the changes to these files:
789+
790+
* Cargo.toml (dirty)
791+
* src/ (dirty)
792+
793+
789794
",
790795
)
791796
.run();

0 commit comments

Comments
 (0)