mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-03-31 11:39:19 +00:00
Avoid initializing nested Git repository
Previously a Git repository was initialized if a Cargo workspace was detected. However, it's also possible for users to initialize rustlings in an existing Git repository that doesn't contain a Cargo workspace. In that case, it's still undesirable to initialize a nested Git repository for rustlings. We therefore search all ancestors of the current working directory for `.git` or `.jj` directories to determine if rustlings is being initialized in an existing Git repository.
This commit is contained in:
parent
75c06bb7f4
commit
17ff88902b
17
src/init.rs
17
src/init.rs
@ -29,6 +29,21 @@ pub fn init() -> Result<()> {
|
|||||||
bail!(RUSTLINGS_DIR_ALREADY_EXISTS_ERR);
|
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")
|
let locate_project_output = Command::new("cargo")
|
||||||
.arg("locate-project")
|
.arg("locate-project")
|
||||||
.arg("-q")
|
.arg("-q")
|
||||||
@ -59,7 +74,7 @@ pub fn init() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut stdout = io::stdout().lock();
|
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 locate_project_output.status.success() {
|
||||||
if Path::new("exercises").exists() && Path::new("solutions").exists() {
|
if Path::new("exercises").exists() && Path::new("solutions").exists() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user