{"record":{"id":"934c0eb4b67474e2","repo":"xai-org/grok-build","slug":"git-shown-failed-in","errorCode":null,"errorMessage":"git {shown} failed in {}: {}","messagePattern":"git (.+?) failed in (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-fast-worktree/src/git/checkout.rs","lineNumber":212,"sourceCode":"    // Same reason the probes do it: the snapshot runs unattended, and the\n    // hooks are the worktree's own.\n    cmd.current_dir(worktree_path)\n        .args([\"-c\", &format!(\"core.hooksPath={NO_HOOKS}\")])\n        .args(args);\n    // Before the caller's own, which is what carries the scratch index: the\n    // snapshot has to read the configuration the gate's probes read, or the\n    // two halves judge different repositories.\n    super::probe::forget_inherited_git_environment(&mut cmd);\n    for &(key, val) in envs {\n        cmd.env(key, val);\n    }\n\n    let shown = display_args(args);\n    let output = super::probe::run_with_timeout(cmd, Vec::new(), SNAPSHOT_TIMEOUT)\n        .with_context(|| format!(\"failed to run git {shown} in {}\", worktree_path.display()))?;\n\n    if !output.status.success() {\n        anyhow::bail!(\n            \"git {shown} failed in {}: {}\",\n            worktree_path.display(),\n            String::from_utf8_lossy(&output.stderr)\n        );\n    }\n\n    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())\n}\n\n/// Render git args for an error/context message (paths shown lossily).\nfn display_args<S: AsRef<OsStr>>(args: &[S]) -> String {\n    args.iter()\n        .map(|arg| arg.as_ref().to_string_lossy().into_owned())\n        .collect::<Vec<String>>()\n        .join(\" \")\n}\n\n/// Git config overrides (`-c key=val`, applied before the subcommand) used on","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-fast-worktree/src/git/checkout.rs#L194-L230","documentation":"git_capture_in runs a git command (with a snapshot timeout) inside a worktree and fails if git exits non-zero. The message embeds the displayed command, the worktree path, and git's stderr, so it wraps any git failure during snapshot/checkout operations such as `git status`, `git add`, or `git write-tree`. It signals that the repository state or invocation was rejected by git itself, not by this library.","triggerScenarios":"Calling snapshot_git, test_worktree_at_ref, or rehydrate/snapshot helpers when the underlying git command exits non-zero: e.g. corrupted index/lock files, invalid ref passed to test_worktree_at_ref, .git directory missing or unreadable, or git hooks/config causing failure. Callers include snapshot_git, test_worktree_at_ref, and the worktree snapshot tests.","commonSituations":"A leftover .git/index.lock blocking git status; a caller passing a nonexistent or pruned ref (e.g. after force-push or GC); running as a different user so git's safe.directory check rejects the repo; truncated or corrupt .git dir on NFS worktrees; PATH lacking a working git binary or git failing due to SIGPIPE on huge trees.","solutions":["Read the stderr portion of the message first — it contains git's own diagnosis (e.g. 'index.lock exists', 'bad object <ref>') and fix that specific cause.","If it's an index.lock error, remove the stale lock file: git rm-free fix is `rm <worktree>/.git/index.lock` (verify no git process is running).","If the ref is invalid, verify it exists with `git rev-parse <ref>` in the worktree before calling snapshot/test_worktree_at_ref.","Check ownership/permissions: run `git config --global --add safe.directory <path>` or fix ownership (`chown -R`) if 'dubious ownership' appears in stderr.","Verify the worktree's .git linkage is intact (`cat .git` points to the repo's .git/worktrees/<name>) or recreate the worktree."],"exampleFix":"// before: passing a ref that may not exist\nlet out = test_worktree_at_ref(worktree_path, \"origin/feature-branch\")?;\n// after: resolve and validate the ref first\nlet out = git_capture_in(worktree_path, &[\"rev-parse\", \"--verify\", \"origin/feature-branch\"])\n    .ok()\n    .and_then(|_| test_worktree_at_ref(worktree_path, \"origin/feature-branch\"))?;","handlingStrategy":"try-catch","validationCode":"// before calling snapshot/test_worktree_at_ref, verify repo health\nlet probe = std::process::Command::new(\"git\")\n    .args([\"rev-parse\", \"--verify\", ref_name])\n    .current_dir(worktree_path)\n    .output()?;\nif !probe.status.success() {\n    anyhow::bail!(\"ref {} unavailable in {}: {}\", ref_name, worktree_path.display(),\n        String::from_utf8_lossy(&probe.stderr));\n}","typeGuard":null,"tryCatchPattern":"match snapshot_git(path) {\n    Err(e) if e.to_string().contains(\"index.lock\") => {\n        std::fs::remove_file(path.join(\".git/index.lock\")).ok();\n        retry_with_backoff(|| snapshot_git(path))\n    }\n    Err(e) if e.to_string().contains(\"bad object\") => bail!(\"ref pruned; re-resolve before snapshotting\"),\n    Err(e) => return Err(e),\n}","preventionTips":["Read the stderr embedded in the message — it names the exact git failure.","Remove stale .git/index.lock files after crashed git processes.","Resolve and rev-parse refs before passing them to snapshot/test helpers.","Add safe.directory config when running across user boundaries."],"tags":["git","process","subprocess-failed","rust"],"backgroundTag":"git-command-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}