diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index d2442a5b64b..51f85c2fceb 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -570,7 +570,9 @@ pub fn init(opts: &NewOptions, gctx: &GlobalContext) -> CargoResult CargoResult 1 { anyhow::bail!( - "more than one of .hg, .git, .pijul, .fossil configurations \ + "more than one of .hg, .git, .pijul, .fslckout configurations \ found and the ignore file can't be filled in as \ a result. specify --vcs to override detection" ); diff --git a/src/cargo/util/vcs.rs b/src/cargo/util/vcs.rs index 2d747e10801..984a456e399 100644 --- a/src/cargo/util/vcs.rs +++ b/src/cargo/util/vcs.rs @@ -8,6 +8,7 @@ use std::path::Path; // 1. We are in a git repo and the path to the new package is not an ignored // path in that repo. // 2. We are in an HG repo. +// 3. We are in a fossil repo. pub fn existing_vcs_repo(path: &Path, cwd: &Path) -> bool { fn in_git_repo(path: &Path, cwd: &Path) -> bool { if let Ok(repo) = GitRepo::discover(path, cwd) { @@ -22,7 +23,9 @@ pub fn existing_vcs_repo(path: &Path, cwd: &Path) -> bool { } } - in_git_repo(path, cwd) || HgRepo::discover(path, cwd).is_ok() + in_git_repo(path, cwd) + || HgRepo::discover(path, cwd).is_ok() + || FossilRepo::discover(path, cwd).is_ok() } pub struct HgRepo; @@ -93,12 +96,26 @@ impl FossilRepo { // open it in that new directory ProcessBuilder::new("fossil") - .cwd(&path) + .cwd(cwd) .arg("open") .arg("--") - .arg(db_fname) + .arg(db_path) .exec()?; Ok(FossilRepo) } + + pub fn discover(_path: &Path, cwd: &Path) -> CargoResult { + let output = ProcessBuilder::new("fossil") + .cwd(cwd) + .arg("info") + .output()?; + let stdout = String::from_utf8(output.stdout)?; + let has_local_root = stdout.lines().any(|line| line.starts_with("local-root:")); + if has_local_root { + Ok(FossilRepo) + } else { + anyhow::bail!("not in a fossil repository") + } + } } diff --git a/tests/testsuite/cargo_init/fossil_autodetect/in/.fossil/.keep b/tests/testsuite/cargo_init/fossil_autodetect/in/.keep similarity index 100% rename from tests/testsuite/cargo_init/fossil_autodetect/in/.fossil/.keep rename to tests/testsuite/cargo_init/fossil_autodetect/in/.keep diff --git a/tests/testsuite/cargo_init/fossil_autodetect/mod.rs b/tests/testsuite/cargo_init/fossil_autodetect/mod.rs index 7b59945a550..22aaddbcf89 100644 --- a/tests/testsuite/cargo_init/fossil_autodetect/mod.rs +++ b/tests/testsuite/cargo_init/fossil_autodetect/mod.rs @@ -18,6 +18,6 @@ fn case() { .stdout_eq(str![""]) .stderr_eq(file!["stderr.term.svg"]); - assert_ui().subset_matches(current_dir!().join("out"), project_root); - assert!(!project_root.join(".git").is_dir()); + assert_ui().subset_matches(current_dir!().join("in"), project_root); + assert!(!project_root.join(".fslckout").is_file()); }