{"record":{"id":"f914338c929507e0","repo":"abhigyanpatwari/GitNexus","slug":"refusing-to-update-safetarget-local-changes-de","errorCode":null,"errorMessage":"Refusing to update ${safeTarget}: local changes detected. Set overwrite_local_changes: true to overwrite them.","messagePattern":"Refusing to update (.+?): local changes detected\\. Set overwrite_local_changes: true to overwrite them\\.","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/server/git-clone.ts","lineNumber":607,"sourceCode":"    // \"Already there\" is a named-branch match OR a detached HEAD whose SHA\n    // equals `branch` / `origin/<branch>` (tag / SHA pin). A missing ref\n    // falls through to the switch path, which still refuses a dirty tree.\n    //\n    // Same-named-branch update uses the heads/ → remotes/ fetch refspec plus\n    // `checkout -B <branch> origin/<branch>`, never `pull origin <user-string>`\n    // (a leading `+` would otherwise be a force-fetch). Only\n    // `remote.origin.url` is verified above; `branch.<name>.remote` /\n    // `.merge` are not, so an implicit-upstream pull can update a different\n    // ref while the job still carries this branch (#3199 review).\n    const requestedRefMatch = options?.branch\n      ? await matchRequestedRef(runGitImpl, safeTarget, options.branch, gitOpts)\n      : undefined;\n\n    if (options?.branch && !requestedRefMatch) {\n      if (!options.overwriteLocalChanges) {\n        const status = await runGitImpl(['status', '--porcelain'], safeTarget, gitOpts);\n        if (status.trim()) {\n          throw new Error(\n            `Refusing to update ${safeTarget}: local changes detected. Set overwrite_local_changes: true to overwrite them.`,\n          );\n        }\n      }\n      await runGitImpl(\n        ['fetch', '--depth', '1', 'origin', branchFetchRefspec(options.branch)],\n        safeTarget,\n        gitOpts,\n      );\n      await runGitImpl(\n        [\n          'checkout',\n          ...(options.overwriteLocalChanges ? ['--force'] : []),\n          '-B',\n          options.branch,\n          `origin/${options.branch}`,\n        ],\n        safeTarget,","sourceCodeStart":589,"sourceCodeEnd":625,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/ac9a4e9abd8fd3058c070b72c23402a4f887929a/gitnexus/src/server/git-clone.ts#L589-L625","documentation":"During a pull/update, cloneOrPull runs 'git status --porcelain' in the existing target; if the output is non-empty the working tree has local modifications, and the update is refused rather than silently clobbered. The error tells you to opt in explicitly with overwrite_local_changes: true. It protects uncommitted user work in the clone.","triggerScenarios":"Calling cloneOrPull for a repo whose targetDir already exists as a git repo with uncommitted modifications or untracked files, without overwrite_local_changes: true.","commonSituations":"A developer edited files inside the auto-synced clone; build artifacts or generated files left untracked in the target; a crashed previous run left partial edits; hotfixes applied directly in the synced checkout.","solutions":["Commit or discard the local changes in the target repo, then retry the sync.","Pass overwrite_local_changes: true in the cloneOrPull options if the changes are disposable.","Move/stash the changes (git stash) or copy them aside before re-running the sync.","Clean untracked files (git clean -fd) if they are the trigger and are not needed."],"exampleFix":"// before\nawait cloneOrPull({ url, targetDir });\n// after (changes are intentionally disposable)\nawait cloneOrPull({ url, targetDir, overwrite_local_changes: true });","handlingStrategy":"try-catch","validationCode":"const { stdout } = await exec('git status --porcelain', { cwd: targetDir });\nif (stdout.trim()) {\n  console.warn('target has local changes; commit, stash, or set overwrite_local_changes: true');\n}\nawait cloneOrPull({ url, targetDir, overwrite_local_changes: stdout.trim() ? true : false });","typeGuard":null,"tryCatchPattern":"try {\n  await cloneOrPull(opts);\n} catch (err) {\n  if ((err as Error).message.includes('local changes detected')) {\n    // surface to operator instead of silently overwriting\n    throw new Error(`Sync blocked: ${opts.targetDir} has uncommitted work. Resolve or set overwrite_local_changes.`, { cause: err });\n  }\n  throw err;\n}","preventionTips":["Never edit auto-synced clones directly; work in separate worktrees.","Add the clone dir to .gitignore hygiene so generated files do not accumulate as untracked changes.","Run git status before scheduled syncs and alert instead of force-overwriting.","Only set overwrite_local_changes: true after confirming the changes are disposable."],"tags":["git","sync","conflict"],"backgroundTag":"git-command-failed","analyzedSha":"ac9a4e9abd8fd3058c070b72c23402a4f887929a","analyzedAt":"2026-09-15T23:29:44.066Z","contentChangedAt":"2026-09-15T23:29:44.066Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}