{"record":{"id":"8b634d687408d920","repo":"gitbutlerapp/gitbutler","slug":"failed-to-determine-target-commit-for-hunk-absorpt","errorCode":null,"errorMessage":"Failed to determine target commit for hunk absorption due to ambiguous dependencies in path: {}","messagePattern":"Failed to determine target commit for hunk absorption due to ambiguous dependencies in path: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/legacy/absorb.rs","lineNumber":424,"sourceCode":"fn ensure_target_commit(\n    ctx: &mut Context,\n    candidate: &AbsorbCandidate,\n    locks: Option<&[HunkLock]>,\n    workspace: &mut RefInfo,\n    perm: &mut RepoExclusive,\n) -> anyhow::Result<(\n    but_core::ref_metadata::StackId,\n    gix::ObjectId,\n    AbsorptionReason,\n)> {\n    // Priority 1: Check if there's a dependency lock for this hunk\n    if let Some(locks) = locks {\n        if let Some(lock) = find_top_most_lock(locks, workspace) {\n            if let HunkLockTarget::Stack(stack_id) = lock.target {\n                return Ok((stack_id, lock.commit_id, AbsorptionReason::HunkDependency));\n            }\n        } else {\n            anyhow::bail!(\n                \"Failed to determine target commit for hunk absorption due to ambiguous dependencies in path: {}\",\n                candidate.hunk.path\n            );\n        }\n    }\n\n    // Priority 2: Use the candidate's stack ID if available\n    if let Some(stack_id) = candidate.stack_id {\n        let branch_ref = candidate.branch_ref.as_ref();\n\n        let (reference, commit_id) = target_segment(workspace, stack_id, branch_ref)?;\n        if let Some(commit_id) = commit_id {\n            return Ok((stack_id, commit_id, AbsorptionReason::StackAssignment));\n        }\n\n        // If there are no commits in the target branch, create a blank commit first\n        commit_insert_blank_only_impl(\n            ctx,","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/legacy/absorb.rs#L406-L442","documentation":"`ensure_target_commit` (part of hunk absorption via `group_changes_by_target_commit`) throws this when a hunk has hunk-level dependencies (locks) but no top-most lock can be determined in the workspace, so the commit that should receive the hunk is ambiguous. Absorption requires an unambiguous dependency path to decide which stack commit the hunk belongs to.","triggerScenarios":"Calling hunk absorption where `locks` is `Some` for the candidate hunk, `find_top_most_lock(locks, workspace)` returns `None` (the locked commits/branches are not present in the current workspace projection) and no stack assignment can be derived from the lock target.","commonSituations":"Hunk dependencies recorded against commits or branches that were since rebased away, squashed, or deleted; stale dependency metadata from an older workspace state; absorbing hunks whose reference commits no longer exist after a `but pull`.","solutions":["Refresh the workspace (`but pull` / re-open the project) so dependency locks are reconciled with current commits, then retry.","Absorb the hunk into a specific commit explicitly (pick a target commit) instead of relying on automatic dependency resolution.","Clear stale hunk dependencies for the file (re-assign the hunk) if the referenced commits are gone for good."],"exampleFix":"// before\nabsorb_hunks(hunk)  // Err: ambiguous dependencies in path: src/lib.rs\n// after\nlet target = pick_commit_explicitly(hunk.path);  // or refresh workspace first\nabsorb_hunks(hunk.into_target(target))","handlingStrategy":"fallback","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  await api.absorbHunks(hunks);\n} catch (e) {\n  if (String(e).includes('ambiguous dependencies in path')) {\n    await api.refreshWorkspace();          // reconcile stale locks with current commits\n    await api.absorbHunks(hunks, { explicitTarget: pickCommit(hunks) }); // or pick target manually\n  } else throw e;\n}","preventionTips":["Refresh the workspace after rebases, squashes, or pulls that could invalidate hunk dependencies.","Prefer explicit target commits for absorption when dependency metadata may be stale.","Avoid deleting or rewriting commits that hunks in the worktree depend on."],"tags":["git","hunk-dependencies","absorb","ambiguous-state"],"backgroundTag":"internal-invariant-violation","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}