{"record":{"id":"df365ae09e8ffc03","repo":"nikivdev/code","slug":"unmerged-files-detected-resolve-them-before-synci","errorCode":null,"errorMessage":"Unmerged files detected. Resolve them before syncing.","messagePattern":"Unmerged files detected\\. Resolve them before syncing\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sync.rs","lineNumber":3249,"sourceCode":"                }\n            }\n        }\n    }\n}\n\nfn run_jj_sync(\n    repo_root: &Path,\n    cmd: &SyncRunOptions,\n    auto_fix: bool,\n    recorder: &mut SyncRecorder,\n) -> Result<()> {\n    // Avoid git operations in progress.\n    if is_rebase_in_progress() || is_merge_in_progress() {\n        bail!(\"Git operation in progress. Run `f git-repair` first.\");\n    }\n    let unmerged = git_capture(&[\"diff\", \"--name-only\", \"--diff-filter=U\"]).unwrap_or_default();\n    if !unmerged.trim().is_empty() {\n        bail!(\"Unmerged files detected. Resolve them before syncing.\");\n    }\n\n    let head_ref = git_capture_in(repo_root, &[\"rev-parse\", \"--abbrev-ref\", \"HEAD\"])\n        .unwrap_or_else(|_| \"HEAD\".to_string());\n    let head_ref = head_ref.trim();\n    let default_branch = jj_default_branch(repo_root);\n    let current_bookmarks = jj_local_bookmarks_at_rev(repo_root, \"@\");\n    let current_branch = select_jj_sync_branch(head_ref, &current_bookmarks, &default_branch);\n    if head_ref == \"HEAD\" || head_ref.is_empty() {\n        recorder.record(\n            \"jj\",\n            format!(\"detached head (using jj branch {})\", current_branch),\n        );\n    } else if current_branch != head_ref {\n        recorder.record(\n            \"jj\",\n            format!(\n                \"using current jj bookmark {} instead of git HEAD {}\",","sourceCodeStart":3231,"sourceCodeEnd":3267,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/sync.rs#L3231-L3267","documentation":"This error is thrown at the start of the sync flow in src/sync.rs when the repository contains unmerged files (git conflict entries in the index). Before syncing, the tool runs `git diff --name-only --diff-filter=U` and bails if any paths are unresolved, because a sync/fetch-merge cannot proceed with a dirty, conflicted index. It guards against corrupting the working state mid-conflict.","triggerScenarios":"Running `f sync` (the sync command) while the index holds unmerged (conflicted) entries — i.e., after `git diff --name-only --diff-filter=U` returns non-empty output. Note: an in-progress rebase/merge is caught earlier by a separate check ('Git operation in progress'), so this fires for lingering conflicted index entries.","commonSituations":"A previous pull/merge left conflicts the user resolved in the working tree but never `git add`-ed; the user aborted a merge uncleanly; a teammate-sync tool conflicted and the user retried sync instead of finishing the resolution.","solutions":["Resolve the conflicts: run `git diff --name-only --diff-filter=U` to list files, edit each to remove conflict markers.","Stage resolved files with `git add <file>` (or `git add .`) and commit the merge.","Run `f git-repair` as suggested by related sync errors if the repo state seems inconsistent.","If you truly want to abandon the conflicted state, `git merge --abort` (or `git rebase --abort`) then re-run sync."],"exampleFix":"// before (sync fails)\nf sync\n// error: Unmerged files detected. Resolve them before syncing.\n\n// after\ngit diff --name-only --diff-filter=U   # list conflicted files\ngit add src/main.rs                   # resolve + stage\ngit commit                            # finish merge\nf sync                                 # now succeeds","handlingStrategy":"validation","validationCode":"let unmerged = git_capture(&[\"diff\", \"name-only\", \"--diff-filter=U\"]).unwrap_or_default();\nif !unmerged.trim().is_empty() {\n    eprintln!(\"Resolve conflicts first: {}\", unmerged);\n    std::process::exit(1);\n}","typeGuard":"fn has_unmerged_files(unmerged_output: &str) -> bool {\n    !unmerged_output.trim().is_empty()\n}","tryCatchPattern":"match sync::run(&repo_root, &cmd) {\n    Err(e) if e.to_string().contains(\"Unmerged files detected\") => {\n        eprintln!(\"Conflicts pending. Run: git diff --name-only --diff-filter=U\");\n    }\n    Err(e) => return Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Always resolve and `git add` conflicts immediately after a conflicted merge; don't leave the repo half-resolved.","Check `git status` for 'Unmerged paths' before running sync.","Use `git merge --abort` when you don't intend to complete a conflicted merge.","Add a pre-sync script that fails fast on unmerged entries."],"tags":["git","merge-conflict","unmerged-files","sync"],"backgroundTag":"unmerged-files-conflict","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}