Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,9 @@ pub fn init(opts: &NewOptions, gctx: &GlobalContext) -> CargoResult<NewProjectKi
num_detected_vcses += 1;
}

if path.join(".fossil").exists() {
// .fslckout tracks your active, local work.
// ~/.fossil is the Configuration Database
if path.join(".fslckout").exists() {
version_control = Some(VersionControl::Fossil);
num_detected_vcses += 1;
}
Expand All @@ -579,7 +581,7 @@ pub fn init(opts: &NewOptions, gctx: &GlobalContext) -> CargoResult<NewProjectKi

if num_detected_vcses > 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"
);
Expand Down
23 changes: 20 additions & 3 deletions src/cargo/util/vcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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<FossilRepo> {
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")
}
}
}
4 changes: 2 additions & 2 deletions tests/testsuite/cargo_init/fossil_autodetect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Loading