{"record":{"id":"2e214e5c37975da2","repo":"gitbutlerapp/gitbutler","slug":"could-not-get-a-tree-of-all-applied-virtual-branch","errorCode":null,"errorMessage":"Could not get a tree of all applied virtual branches merged","messagePattern":"Could not get a tree of all applied virtual branches merged","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-oplog/src/oplog.rs","lineNumber":406,"sourceCode":"    if let Some(details) = details\n        && details.version == Version(3)\n    {\n        let worktree_id = get_v3_workdir_tree(snapshot_commit.tree()?)?.context(format!(\n            \"no entry at 'worktree' on sha {:?}, version: {:?}\",\n            &snapshot_commit.id(),\n            &details.version,\n        ))?;\n        return Ok(worktree_id);\n    }\n    match wd_trees_cache {\n        Some(cache) => {\n            if let Entry::Vacant(entry) = cache.entry(snapshot_commit.id)\n                && let Ok(tree_id) = tree_from_applied_vbranches(repo, snapshot_commit.id)\n            {\n                entry.insert(tree_id);\n            }\n            cache.get(&snapshot_commit.id).copied().ok_or_else(|| {\n                anyhow!(\"Could not get a tree of all applied virtual branches merged\")\n            })\n        }\n        None => tree_from_applied_vbranches(repo, snapshot_commit.id),\n    }\n}\n\nstruct IndexTrees {\n    index: gix::ObjectId,\n    conflicts: Option<gix::ObjectId>,\n}\n\nfn write_index_trees(ctx: &Context) -> Result<IndexTrees> {\n    let repo = ctx.repo.get()?;\n    let index = repo.index_or_empty()?;\n    // The detached editor writes trees without checking that each entry's blob exists\n    // locally, which it may not, e.g. for unfetched files in a partial clone with a\n    // sparse checkout.\n    let mut tree = repo.empty_tree().edit()?.detach();","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-oplog/src/oplog.rs#L388-L424","documentation":"get_workdir_tree reconstructs the working-directory tree by merging all applied virtual branches at a given snapshot commit. When the computed tree cannot be produced (tree_from_applied_vbranches fails) and the cache lookup misses, this error is thrown. It means GitButler could not materialize a coherent merged tree for the snapshot being restored.","triggerScenarios":"Calling restore_snapshot when tree_from_applied_vbranches returns Err for the snapshot commit — e.g. conflicting virtual branches, missing commits underneath the virtual branches, or a corrupted oplog snapshot — so neither the cache population nor the direct call yields a tree.","commonSituations":"Restoring an old undo snapshot whose virtual branches reference commits that were garbage-collected or rebased away; heavily conflicted multi-branch states at snapshot time; interrupted oplog writes.","solutions":["Run `git fsck` and `git gc --prune=now` alternatives carefully: first confirm the underlying commits exist (`git cat-file -t <commit>`); restore missing objects from a remote/backup if pruned.","Try restoring an adjacent (earlier or later) snapshot instead of the failing one.","Use `but` CLI to list snapshots and pick one whose branches are intact.","As a last resort, capture the current branch state manually with git and re-initialize the GitButler workspace."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// ensure snapshot commit still exists before restore\nrepo.find_commit(snapshot_commit_id)\n    .map_err(|_| \"snapshot commit is missing; pick another snapshot\")?;","typeGuard":null,"tryCatchPattern":"match restore_snapshot_result {\n    Err(e) if e.to_string().contains(\"tree of all applied virtual branches merged\") => {\n        // try an adjacent snapshot or fall back to git-level restore\n        restore_adjacent_snapshot()?\n    }\n    other => other,\n}","preventionTips":["Run periodic `git fsck` and avoid aggressive gc settings that prune objects referenced by virtual branches.","Restore snapshots soon after creating them rather than after unrelated rebases.","Keep a backup/push of branches before performing undo/restore operations."],"tags":["git","oplog","tree","virtual-branches"],"backgroundTag":"git-command-failed","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"}