{"record":{"id":"053d86dd771f2007","repo":"nikivdev/code","slug":"failed-to-stash-local-changes-resolve-the-iss","errorCode":null,"errorMessage":"Failed to stash local changes: {}. Resolve the issue and re-run sync.","messagePattern":"Failed to stash local changes: (.+?)\\. Resolve the issue and re-run sync\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sync.rs","lineNumber":1451,"sourceCode":"        let current = current.trim();\n\n        // Check for uncommitted changes\n        let status = git_capture(&[\"status\", \"--porcelain\"])?;\n        let has_changes = !status.trim().is_empty();\n\n        if has_changes && !cmd.stash {\n            recorder.record(\"stash\", \"skipped (uncommitted changes without --stash)\");\n            bail!(\"Uncommitted changes\");\n        }\n\n        // Stash if needed\n        let mut auto_stash_state = AutoStashState::default();\n        if has_changes && cmd.stash {\n            sync_progressln!(\"Stashing local changes...\");\n            auto_stash_state =\n                auto_stash_repo(repo_root_path, \"f sync auto-stash\").map_err(|err| {\n                    recorder.record(\"stash\", format!(\"stash failed: {}\", err));\n                    anyhow::anyhow!(\n                        \"Failed to stash local changes: {}. Resolve the issue and re-run sync.\",\n                        err\n                    )\n                })?;\n            if !auto_stash_state.intent_to_add_paths.is_empty() {\n                sync_progressln!(\n                    \"Temporarily normalized {} intent-to-add path(s) before stashing.\",\n                    auto_stash_state.intent_to_add_paths.len()\n                );\n                recorder.record(\n                    \"stash\",\n                    format!(\n                        \"temporarily normalized {} intent-to-add path(s)\",\n                        auto_stash_state.intent_to_add_paths.len()\n                    ),\n                );\n            }\n        }","sourceCodeStart":1433,"sourceCodeEnd":1469,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/sync.rs#L1433-L1469","documentation":"During sync, when there are uncommitted local changes and the command has stash enabled, the code calls auto_stash_repo to stash them before proceeding. If the stash operation fails, it records 'stash failed' and throws 'Failed to stash local changes: {err}. Resolve the issue and re-run sync.', aborting the sync so the user can fix the working tree manually.","triggerScenarios":"Running sync with uncommitted changes while cmd.stash is true and auto_stash_repo fails — e.g. git cannot create a stash because of a lock file, conflicting index, untracked/ignored path issues, or intent-to-add entries that confuse `git stash`.","commonSituations":"Stale .git/index.lock from a crashed git process; merge/rebase in progress; corrupt stash ref; files with conflicting local modifications that stash refuses to handle; restricted permissions on .git.","solutions":["Read the underlying git error in the message and resolve it (e.g. remove a stale .git/index.lock after confirming no git process runs)","Commit or manually stash/discarding changes with `git stash` / `git checkout -- .` before re-running sync","Abort any in-progress merge/rebase (git merge --abort / git rebase --abort), then re-run sync","Check .git permissions and disk space"],"exampleFix":"# before re-running sync\nrm -f .git/index.lock        # only if no git process is running\ngit stash -u                 # stash manually\nf sync                       # then re-run (with or without --stash)","handlingStrategy":"try-catch","validationCode":"let status = std::process::Command::new(\"git\").args([\"status\", \"--porcelain\"]).current_dir(repo_root).output()?;\nlet dirty = !status.stdout.is_empty();\nif dirty {\n    // probe stash capability first\n    let probe = std::process::Command::new(\"git\").args([\"stash\", \"list\"]).current_dir(repo_root).status()?;\n    if !probe.success() { eprintln!(\"git stash is currently broken; resolve before sync\"); }\n}","typeGuard":null,"tryCatchPattern":"match sync(cmd) {\n    Ok(()) => (),\n    Err(e) if e.to_string().contains(\"Failed to stash local changes\") => {\n        eprintln!(\"{}\", e); // includes underlying git error\n        eprintln!(\"hint: check for .git/index.lock, in-progress merge/rebase, then re-run sync\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Commit or stash intentionally before long-running syncs","Remove stale .git/index.lock only when no git process is running","Keep .git writable and watch disk space","Avoid concurrent git operations in the same repo"],"tags":["git","sync","stash","working-tree"],"backgroundTag":"git-stash-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}