Skip to content

Commit

Permalink
Include untracked files
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed Nov 26, 2022
1 parent e525dd3 commit 2abaace
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
9 changes: 1 addition & 8 deletions src/cargo/ops/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,7 @@ fn check_version_control(config: &Config, opts: &FixOptions) -> CargoResult<()>
if let Ok(repo) = git2::Repository::discover(config.cwd()) {
let mut repo_opts = git2::StatusOptions::new();
repo_opts.include_ignored(false);
if repo.is_empty()? && !opts.allow_dirty {
bail!(
"no commits found in the git repository, and \
`cargo fix` can potentially perform destructive changes; if you'd \
like to suppress this error pass `--allow-dirty`, \
or commit your changes"
)
}
repo_opts.include_untracked(true);
for status in repo.statuses(Some(&mut repo_opts))?.iter() {
if let Some(path) = status.path() {
match status.status() {
Expand Down
15 changes: 10 additions & 5 deletions tests/testsuite/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ commit the changes to these files:
}

#[cargo_test]
fn errors_on_empty_repo() {
fn errors_about_untracked_files() {
let mut git_project = project().at("foo");
git_project = git_project.file("src/lib.rs", "pub fn foo() {}");
let p = git_project.build();
Expand All @@ -782,10 +782,15 @@ fn errors_on_empty_repo() {
.with_status(101)
.with_stderr(
"\
error: no commits found in the git repository, \
and `cargo fix` can potentially perform destructive changes; \
if you'd like to suppress this error pass `--allow-dirty`, \
or commit your changes
error: the working directory of this package has uncommitted changes, \
and `cargo fix` can potentially perform destructive changes; if you'd \
like to suppress this error pass `--allow-dirty`, `--allow-staged`, or \
commit the changes to these files:
* Cargo.toml (dirty)
* src/ (dirty)
",
)
.run();
Expand Down

0 comments on commit 2abaace

Please sign in to comment.