{"record":{"id":"0ebb13e4b51f05c8","repo":"nikivdev/code","slug":"git-failed-for-preview-in","errorCode":null,"errorMessage":"git {} failed for preview in {}","messagePattern":"git (.+?) failed for preview in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pr_preview.rs","lineNumber":1571,"sourceCode":"    if let Some(work_tree_root) = work_tree_root {\n        command\n            .arg(\"--git-dir\")\n            .arg(repo_root.join(\".git\"))\n            .arg(\"--work-tree\")\n            .arg(work_tree_root)\n            .current_dir(work_tree_root);\n    } else {\n        command.current_dir(repo_root);\n    }\n    let output = command.args(args).output().with_context(|| {\n        format!(\n            \"failed to run git {} for preview in {}\",\n            args.join(\" \"),\n            work_tree_root.unwrap_or(repo_root).display()\n        )\n    })?;\n    if !output.status.success() {\n        bail!(\n            \"git {} failed for preview in {}\",\n            args.join(\" \"),\n            work_tree_root.unwrap_or(repo_root).display()\n        );\n    }\n    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())\n}\n\nfn first_diff_hunk(\n    repo_root: &Path,\n    work_tree_root: Option<&Path>,\n    merge_base: &str,\n    relative_path: &str,\n) -> Result<Option<String>> {\n    let patch = git_capture_for_preview(\n        repo_root,\n        work_tree_root,\n        &[","sourceCodeStart":1553,"sourceCodeEnd":1589,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/pr_preview.rs#L1553-L1589","documentation":"Same failure mode as the general git helper, but for the preview-specific variant that can operate on an alternate work tree root. When the `git <args>` command run for building the preview exits non-zero, the tool bails with the args and the effective root (work_tree_root if provided, otherwise repo_root).","triggerScenarios":"Preview-time git calls (diff, rev-parse, etc.) failing in the work tree: the work tree path does not exist or is not registered with git (`git worktree` pruned), the repo root fallback is not a repository, or the command's target refs/files are missing.","commonSituations":"A git worktree was removed from disk but not unregistered, the preview is pointed at a bare or invalid root, renamed/deleted branches referenced by the preview, or pathspec errors in the constructed git args.","solutions":["Re-run the printed `git <args>` in the displayed root to see git's underlying error.","If using a work tree, confirm it is valid: `git worktree list` and re-add with `git worktree add` if missing.","Verify repo_root/work_tree_root both exist and contain .git (or are registered worktrees).","Check the refs and paths passed to the preview git command actually exist."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let root = work_tree_root.unwrap_or(repo_root);\nif !root.exists() {\n    return Err(anyhow!(\"preview root {} does not exist\", root.display()));\n}\nif !root.join(\".git\").exists() {\n    return Err(anyhow!(\"preview root {} is not a git work tree\", root.display()));\n}","typeGuard":null,"tryCatchPattern":"match git_capture_for_preview(repo_root, work_tree_root, &args) {\n    Ok(out) => out,\n    Err(e) => { log::error!(\"preview git {:?} failed: {e}\", args); Err(e) }\n}","preventionTips":["Run `git worktree prune`/`git worktree list` when using alternate work trees.","Verify both repo_root and work_tree_root exist before preview.","Keep worktree registrations in sync with the filesystem."],"tags":["git","subprocess","worktree","preview"],"backgroundTag":"subprocess-nonzero-exit","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}