{"record":{"id":"baab61950333e682","repo":"vectordotdev/vector","slug":"wrote-but-git-add-failed-stage-it-manually-before-running","errorCode":null,"errorMessage":"wrote {} but `git add` failed — stage it manually before running `vdev check changelog-fragments`.","messagePattern":"wrote (.+?) but `git add` failed — stage it manually before running `vdev check changelog-fragments`\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"vdev/src/commands/changelog/new.rs","lineNumber":62,"sourceCode":"        let Some(entry) = FRAGMENT_TYPES\n            .iter()\n            .find(|t| t.name == self.fragment_type.as_str())\n        else {\n            bail!(\"unknown fragment type '{}'\", self.fragment_type);\n        };\n        let content = render_template(entry, &author);\n        fs::write(&file, content)?;\n\n        // `git add` the new fragment so the checker (which scans `git diff --diff-filter=A`)\n        // picks it up immediately without a manual staging step. Report the failure if it\n        // happens — the file is on disk, but the checker won't see it until it's staged.\n        let status = Command::new(\"git\")\n            .args([\"add\", \"--\"])\n            .arg(&file)\n            .status()\n            .with_context(|| format!(\"failed to run `git add {}`\", file.display()))?;\n        if !status.success() {\n            bail!(\n                \"wrote {} but `git add` failed — stage it manually before running `vdev check changelog-fragments`.\",\n                file.display()\n            );\n        }\n\n        info!(\"Created {}\", relative(&repo_root, &file).display());\n        info!(\"Edit the file, then run `vdev check changelog-fragments` to validate.\");\n        Ok(())\n    }\n}\n\n/// A slug must be one filename component: ASCII alnum, `_`, or `-` only.\n/// Rejects path separators, `..`, absolute paths, and anything with punctuation.\nfn validate_slug(slug: &str) -> Result<()> {\n    if slug.is_empty() {\n        bail!(\"slug must not be empty\");\n    }\n    if !slug","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/vdev/src/commands/changelog/new.rs#L44-L80","documentation":"After writing the fragment file, `vdev changelog new` runs `git add` on it so the fragments checker (which scans added files) sees it. If `git add` exits non-zero, the command bails with this error telling the developer the file was written but not staged.","triggerScenarios":"`git add -- <file>` returns a non-zero exit status after the fragment file was successfully written — e.g. git refuses due to index lock, .gitignore/.git exclude rules with refuse semantics, hooks, or git binary/environment problems.","commonSituations":"A stale .git/index.lock left by a crashed git process; running the command in a worktree with unusual git config; a pre-commit/applypatch hook failing; repo ownership mismatch ('dubious ownership').","solutions":["Read the stderr printed by the with_context wrapper ('failed to run `git add ...`') and the git error itself, fix that cause (e.g. remove stale .git/index.lock)","Run `git add changelog.d/<your-fragment>.md` manually as the message suggests","Verify `git status` works and you are in the Vector repo root (dubious-ownership: `git config --global --add safe.directory <path>`), then re-run"],"exampleFix":"# before\nrm -f .git/index.lock\ngit add changelog.d/my_fix.md\n# after: re-run\nvdev changelog new bug_fix my_fix","handlingStrategy":"try-catch","validationCode":"const st = spawnSync(\"git\", [\"status\"]); if (st.status !== 0 || /not a git repository|dubious ownership/.test(st.stderr.toString())) fixGitEnv();","typeGuard":null,"tryCatchPattern":"try { vdevChangelogNew(type, slug); } catch (e) { if (/git add/.test(e.message)) { execSync(`git add changelog.d/*.md`); console.warn(\"staged manually\"); } else throw e; }","preventionTips":["Ensure a writable, healthy git index (no .git/index.lock) before running","Run from the repo root with proper git ownership config","Prefer staging fragments manually if hooks interfere"],"tags":["git","cli"],"backgroundTag":"git-command-failed","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}