nikivdev/code · error
{} exists but is not a git repo: {}
Error message
{} exists but is not a git repo: {} What it means
ensure_repo verifies that a destination directory either doesn't exist (and will be cloned) or is a valid git checkout. If dest exists but has no .git directory, the library refuses to proceed — it will not clone into or operate on a non-repo directory, since it can't manage its origin or pull updates.
Source
Thrown at src/home.rs:570
println!(
" not linked: {} (expected -> {})",
dest.display(),
source.display()
);
}
Ok(())
}
fn ensure_repo(
dest: &Path,
repo_url: Option<&str>,
label: &str,
allow_origin_reset: bool,
) -> Result<()> {
if dest.exists() {
if !dest.join(".git").exists() {
bail!("{} exists but is not a git repo: {}", label, dest.display());
}
if let Some(expected) = repo_url {
if allow_origin_reset {
ensure_origin_url(dest, expected)?;
} else if let Ok(actual) = git_capture(dest, &["remote", "get-url", "origin"]) {
if !urls_match(expected, actual.trim()) {
bail!(
"{} origin mismatch: expected {}, got {}",
label,
expected,
actual.trim()
);
}
}
}
update_repo(dest)?;View on GitHub (pinned to a747e741ae)
Solutions
- Delete the existing directory so the tool can clone fresh: rm -rf <dest>
- If the content is wanted, run `git init` + `git remote add origin <url>` + fetch inside it (only if it really is the repo content)
- Move the existing directory aside and re-run
Example fix
// before $ f home sync # ~/.config/kar exists but no .git // after $ mv ~/.config/kar ~/.config/kar.bak $ f home sync # clones repo into ~/.config/kar
Defensive patterns
Strategy: validation
Validate before calling
if dest.exists() && !dest.join(".git").exists() {
eprintln!("{} is not a git repo; remove or move it before syncing", dest.display());
} Type guard
fn is_git_repo(dir: &Path) -> bool {
dir.join(".git").exists()
} Try / catch
match ensure_repo(...) {
Err(e) if e.to_string().contains("exists but is not a git repo") => {
eprintln!("inspect/remove {} and re-run", dest.display());
}
r => r?,
} Prevention
- Don't pre-create the destination directory; let the tool clone it
- After partial deletes, remove leftovers before re-syncing
- Add a pre-sync check that target paths are either absent or valid repos
When it happens
Trigger: ensure_repo (called by run or ensure_kar_repo) finds dest.exists() == true while dest.join(".git") is missing.
Common situations: A stale or partially-deleted clone left an empty/plain directory at the target path; the user created the directory manually beforehand; a previous non-git tool wrote files to that location; .git was deleted during cleanup.
Related errors
- Refusing to commit internal .ai files
- Git operation in progress. Run `f git-repair` first.
- failed to resolve HEAD commit
- jj git export retry loop should always return
- Lin.app is not running
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/44eae3c4d879efef.
Report an issue: GitHub.