{"record":{"id":"bb6b6498068a15a8","repo":"xai-org/grok-build","slug":"failed-to-discover-git-repo-e","errorCode":null,"errorMessage":"failed to discover git repo: {e}","messagePattern":"failed to discover git repo: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-fast-worktree/src/lib.rs","lineNumber":110,"sourceCode":"    _out: &std::path::Path,\n) -> anyhow::Result<SalvageReply> {\n    anyhow::bail!(\"not available in this build\")\n}\npub fn local_clean_artifacts(_dest: &std::path::Path) -> anyhow::Result<CleanArtifactsReply> {\n    anyhow::bail!(\"not available in this build\")\n}\npub use sync::{SourceDirtyState, SyncReport, WorktreeSync, collect_source_dirty_state};\n#[cfg(target_os = \"linux\")]\npub use worktree::execute::cleanup_snapshot_git_state;\npub use worktree::{STRATEGY_GROVE_FUSE, STRATEGY_GROVE_NFS, STRATEGY_NFS, is_grove_strategy};\n/// Count the number of tracked files in a git repository's index.\n///\n/// Reads the index header via `gix`, which contains the entry count — this\n/// is an O(1) read (no directory walk). Useful for deciding whether a repo\n/// is large enough to benefit from worktree pooling.\npub fn count_tracked_files(repo_path: &std::path::Path) -> anyhow::Result<usize> {\n    let repo = gix::discover(repo_path)\n        .map_err(|e| anyhow::anyhow!(\"failed to discover git repo: {e}\"))?;\n    let index = repo\n        .index_or_load_from_head()\n        .map_err(|e| anyhow::anyhow!(\"failed to load git index: {e}\"))?;\n    Ok(index.entries().len())\n}\n","sourceCodeStart":92,"sourceCodeEnd":116,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-fast-worktree/src/lib.rs#L92-L116","documentation":"count_tracked_files discovers the repository with gix before reading the index; if `gix::discover` fails (no repo found at or above repo_path, or the repo metadata is unreadable) it is mapped to this error. It is a public API used to cheaply count index entries.","triggerScenarios":"Calling count_tracked_files with a path that is not inside a git repository, a path that does not exist, or a repository whose `.git` discovery fails due to permissions or corrupt config.","commonSituations":"Typos in the repo path; running outside any checkout; passing a bare repo with an unreadable layout; running before the workspace checkout exists.","solutions":["Verify repo_path exists and is inside a valid git working tree (`git -C <path> rev-parse --show-toplevel`)","Correct the path passed to count_tracked_files","Check filesystem permissions on the path and its `.git` directory","Repair repository corruption (`git status` to diagnose, re-clone if needed)"],"exampleFix":"// before\ncount_tracked_files(Path::new(\"/tmp/not-a-repo\"))?;\n// after\ncount_tracked_files(Path::new(\"/home/me/project\"))?; // dir containing .git","handlingStrategy":"validation","validationCode":"fn inside_git_repo(path: &Path) -> bool {\n    path.join(\".git\").exists()\n        || std::process::Command::new(\"git\")\n            .arg(\"-C\").arg(path).arg(\"rev-parse\").arg(\"--git-dir\")\n            .output().map(|o| o.status.success()).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"let count = count_tracked_files(repo_path)\n    .map_err(|e| e.context(format!(\"cannot count tracked files in {}\", repo_path.display())))?;","preventionTips":["Verify repo_path exists and is inside a checkout before calling","Use the checkout root rather than a subdirectory of unknown provenance","Check permissions on the path and `.git` in containerized environments","Create/clone the repo before any counting logic runs"],"tags":["git","discovery","repository-not-found"],"backgroundTag":"git-repository-not-found","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}