Skip to content

Commit 802dcfc

Browse files
authored
Merge pull request #2285 from senekor/senekor/kvtomxvosvvx
Avoid initializing nested Git repository
2 parents ceb9847 + 17ff889 commit 802dcfc

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/init.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ pub fn init() -> Result<()> {
2929
bail!(RUSTLINGS_DIR_ALREADY_EXISTS_ERR);
3030
}
3131

32+
let is_inside_vcs_repository = 'detect_repo: {
33+
let Ok(mut dir) = std::env::current_dir() else {
34+
break 'detect_repo false;
35+
};
36+
loop {
37+
if dir.join(".git").exists() || dir.join(".jj").exists() {
38+
break 'detect_repo true;
39+
}
40+
match dir.parent() {
41+
Some(parent) => dir = parent.into(),
42+
None => break 'detect_repo false,
43+
}
44+
}
45+
};
46+
3247
let locate_project_output = Command::new("cargo")
3348
.arg("locate-project")
3449
.arg("-q")
@@ -59,7 +74,7 @@ pub fn init() -> Result<()> {
5974
}
6075

6176
let mut stdout = io::stdout().lock();
62-
let mut init_git = true;
77+
let mut init_git = !is_inside_vcs_repository;
6378

6479
if locate_project_output.status.success() {
6580
if Path::new("exercises").exists() && Path::new("solutions").exists() {

0 commit comments

Comments
 (0)