Merge pull request #2285 from senekor/senekor/kvtomxvosvvx

Avoid initializing nested Git repository
This commit is contained in:
Mo Bitar 2026-03-14 18:00:03 +01:00 committed by GitHub
commit 802dcfc987
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -29,6 +29,21 @@ pub fn init() -> Result<()> {
bail!(RUSTLINGS_DIR_ALREADY_EXISTS_ERR);
}
let is_inside_vcs_repository = 'detect_repo: {
let Ok(mut dir) = std::env::current_dir() else {
break 'detect_repo false;
};
loop {
if dir.join(".git").exists() || dir.join(".jj").exists() {
break 'detect_repo true;
}
match dir.parent() {
Some(parent) => dir = parent.into(),
None => break 'detect_repo false,
}
}
};
let locate_project_output = Command::new("cargo")
.arg("locate-project")
.arg("-q")
@ -59,7 +74,7 @@ pub fn init() -> Result<()> {
}
let mut stdout = io::stdout().lock();
let mut init_git = true;
let mut init_git = !is_inside_vcs_repository;
if locate_project_output.status.success() {
if Path::new("exercises").exists() && Path::new("solutions").exists() {