{"record":{"id":"e494790f9c068288","repo":"gitbutlerapp/gitbutler","slug":"commit-is-not-in-the-applied-workspace","errorCode":null,"errorMessage":"Commit {} is not in the applied workspace","messagePattern":"Commit (.+?) is not in the applied workspace","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-comments/src/lib.rs","lineNumber":131,"sourceCode":"\n/// Create a new comment anchored to a line in a diff.\n///\n/// The anchor must point at a line that exists in the current diff — the uncommitted worktree\n/// diff of `path`, or the first-parent diff of the workspace commit with `commit_change_id` —\n/// otherwise an error is returned. The anchored line's content (and its neighbours) is\n/// snapshotted so the comment can be re-located when the diff drifts.\npub fn create_comment(\n    repo: &gix::Repository,\n    workspace: &but_graph::Workspace,\n    store: &CommentStore,\n    comment: NewComment,\n    context_lines: u32,\n    now_ms: i64,\n) -> anyhow::Result<DiffComment> {\n    let scope = anchor_scope_display(&comment.commit_change_id, &comment.path);\n    let mut diffs = ScopeDiffs::new(repo, workspace, context_lines);\n    let Some(anchor) = diffs.file(comment.commit_change_id.as_deref(), &comment.path)? else {\n        bail!(\n            \"Commit {} is not in the applied workspace\",\n            comment.commit_change_id.as_deref().unwrap_or_default()\n        );\n    };\n    let file = match anchor {\n        FileAnchor::Lines(lines) => lines,\n        FileAnchor::Gone => bail!(\"Nothing to anchor a comment to in {scope}\"),\n        FileAnchor::Unanchorable => {\n            bail!(\"Cannot comment on {scope}: the diff is binary or too large\")\n        }\n    };\n    let line = file\n        .line_at(comment.side, comment.line_number)\n        .with_context(|| {\n            format!(\n                \"No line {} on the {} side in {scope}\",\n                comment.line_number,\n                comment.side.as_str(),","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-comments/src/lib.rs#L113-L149","documentation":"create_comment anchors a diff comment to a file within the applied workspace. It builds ScopeDiffs for the workspace and looks up a file anchor by commit-change-id and path; if no anchor is found, the target commit/file is not part of the currently applied workspace and the function bails with this message.","triggerScenarios":"Calling create_comment with a comment whose commit_change_id (or its path) does not resolve to a file in the applied workspace — e.g. the commit was unapplied, the workspace changed, or the id/path is wrong.","commonSituations":"Commenting on a commit that was later unapplied or squashed; stale commit-change-id captured before a workspace rebase; referencing a file path that no longer exists in the commit; passing the wrong workspace.","solutions":["Verify the commit is currently applied in the workspace (list workspace commits before commenting)","Re-resolve the commit_change_id against the current workspace state instead of using a cached value","Confirm the file path exists in that commit's changes","Refresh the workspace/reload state and retry if the workspace changed concurrently"],"exampleFix":"// before\ncreate_comment(repo, workspace, comment, context_lines, now_ms).await?;\n// after\nanyhow::ensure!(\n    workspace.applied().iter().any(|c| c.id == comment.commit_change_id),\n    \"commit {} not applied; refresh workspace first\",\n    comment.commit_change_id\n);\ncreate_comment(repo, workspace, comment, context_lines, now_ms).await?;","handlingStrategy":"validation","validationCode":"let applied: Vec<_> = workspace.applied().iter().map(|c| c.id.clone()).collect();\nanyhow::ensure!(applied.contains(&comment.commit_change_id), \"commit {} not applied\", comment.commit_change_id);","typeGuard":"fn is_applied(workspace: &Workspace, commit_change_id: &Option<String>) -> bool {\n    commit_change_id.as_deref()\n        .map(|id| workspace.applied().iter().any(|c| c.id == id))\n        .unwrap_or(false)\n}","tryCatchPattern":"match create_comment(repo, workspace, comment, ctx, now).await {\n    Err(e) if e.to_string().contains(\"not in the applied workspace\") => refresh_workspace_and_retry()?,\n    other => other?,\n}","preventionTips":["Re-resolve commit_change_id against current workspace state before commenting","Re-check that the commit is applied after any workspace rebase/apply","Validate the file path exists in the commit's changes","Never cache commit-change-ids across workspace mutations"],"tags":["rust","workspace","comment","anchor","state"],"backgroundTag":"entity-not-found","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"}