fix(cli): aura new skips git init inside an existing work tree (0107 fieldtest, orthogonal)
The cargo-new mirror completed: a scaffold landing inside a tracked tree no longer nests a .git (the gitlink/submodule hazard that bit the fieldtest corpus); outside a work tree the best-effort init is unchanged. Oracle: git rev-parse --is-inside-work-tree in the target dir; any failure reads as not-in-a-work-tree so the init stays best-effort. RED-first (tdd-author handoff): the inside-a-work-tree pin observed failing on the nested .git; the outside guard pinned against over-removal. Gates: workspace 1003/0, clippy -D warnings clean. closes #204
This commit is contained in:
@@ -239,6 +239,12 @@ pub fn scaffold(spec: &ScaffoldSpec) -> Result<(), String> {
|
||||
write("blueprints/signal.json", render(SIGNAL_JSON, spec))?;
|
||||
write("CLAUDE.md", render(CLAUDE_MD, spec))?;
|
||||
// Best-effort git init: a warning, never an error (cargo-new mirror).
|
||||
// Also the cargo-new mirror: inside an existing work tree the init is
|
||||
// SKIPPED silently — a nested .git is a gitlink/submodule hazard when the
|
||||
// scaffold lands in a tracked tree (#204).
|
||||
if inside_git_work_tree(&spec.target_dir) {
|
||||
return Ok(());
|
||||
}
|
||||
match std::process::Command::new("git")
|
||||
.arg("init")
|
||||
.current_dir(&spec.target_dir)
|
||||
@@ -250,6 +256,18 @@ pub fn scaffold(spec: &ScaffoldSpec) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Whether `dir` already sits inside a git work tree (`git rev-parse`, the
|
||||
/// same oracle cargo-new consults). A missing git binary or any failure reads
|
||||
/// as "not in a work tree" — the init stays best-effort either way.
|
||||
fn inside_git_work_tree(dir: &std::path::Path) -> bool {
|
||||
std::process::Command::new("git")
|
||||
.args(["rev-parse", "--is-inside-work-tree"])
|
||||
.current_dir(dir)
|
||||
.output()
|
||||
.map(|o| o.status.success() && String::from_utf8_lossy(&o.stdout).trim() == "true")
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user