{"record":{"id":"ffd895a617275756","repo":"gitbutlerapp/gitbutler","slug":"snapshot-checkout-ref-is-not-a-local-branch","errorCode":null,"errorMessage":"snapshot checkout ref is not a local branch","messagePattern":"snapshot checkout ref is not a local branch","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-oplog/src/oplog.rs","lineNumber":589,"sourceCode":"}\n\nfn snapshot_checkout(\n    snapshot_tree: &gix::Tree<'_>,\n    repo: &gix::Repository,\n) -> Result<Option<SnapshotCheckout>> {\n    let Some(ref_entry) = snapshot_tree.lookup_entry_by_path(\"checkout/ref\")? else {\n        return Ok(None);\n    };\n    let commit_entry = snapshot_tree\n        .lookup_entry_by_path(\"checkout/commit\")?\n        .context(\"snapshot checkout ref has no commit\")?;\n    let ref_blob = repo\n        .find_blob(ref_entry.id())\n        .context(\"failed to read snapshot checkout ref\")?;\n    let ref_name = gix::refs::FullName::try_from(ref_blob.data.as_bstr())\n        .context(\"snapshot checkout ref is invalid\")?;\n    if ref_name.category() != Some(gix::refs::Category::LocalBranch) {\n        bail!(\"snapshot checkout ref is not a local branch\");\n    }\n    let commit_blob = repo\n        .find_blob(commit_entry.id())\n        .context(\"failed to read snapshot checkout commit\")?;\n    let commit_id = gix::ObjectId::from_hex(&commit_blob.data)\n        .context(\"snapshot checkout commit is invalid\")?;\n    if commit_id.is_null() {\n        bail!(\"snapshot checkout commit is null\");\n    }\n    Ok(Some(SnapshotCheckout {\n        ref_name,\n        commit_id,\n    }))\n}\n\nfn snapshot_metadata(\n    snapshot_tree: &gix::Tree<'_>,\n    repo: &gix::Repository,","sourceCodeStart":571,"sourceCodeEnd":607,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-oplog/src/oplog.rs#L571-L607","documentation":"Thrown by `snapshot_checkout` during snapshot restore when the blob storing the checkout ref name parses as a valid `gix::refs::FullName` but its category is not a local branch (e.g. it is a tag, remote branch, or another kind of ref). GitButler only supports restoring snapshots onto local branches, so any other ref category is rejected.","triggerScenarios":"`restore_snapshot` -> `snapshot_checkout` encounters a snapshot whose checkout-ref blob contains e.g. `refs/remotes/origin/main`, `refs/tags/v1`, or a non-branch ref instead of `refs/heads/<branch>`.","commonSituations":"Snapshots taken while the workspace pointed at a remote-tracking ref; manual manipulation of the oplog tree; restoring a snapshot across repos where ref layouts differ; snapshots created by older versions with different ref naming.","solutions":["Ensure the branch you want to restore onto exists as a local branch (`git branch <name> <commit>`) before restoring","Check the snapshot's checkout-ref blob (`git ls-tree` on the snapshot tree) and confirm it stores `refs/heads/...`","Restore an earlier snapshot entry whose checkout ref is a local branch","If migrating between repos, create the local branch in the target repo to match the snapshot's ref name"],"exampleFix":"// snapshot stores a non-branch ref\n// before: refs/remotes/origin/main\n// after (create local branch first, then snapshot references it):\n//   git branch main origin/main  ->  refs/heads/main","handlingStrategy":"validation","validationCode":"fn checkout_ref_is_local_branch(snapshot: &SnapshotMetadata) -> bool {\n    snapshot.checkout_ref()\n        .map(|r| r.as_bstr().starts_with(b\"refs/heads/\".as_bstr()))\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only take snapshots while local branches are checked out","Ensure target branches exist locally before restoring snapshots migrated across repos","Avoid storing remote-tracking or tag refs as snapshot checkout targets","Inspect the snapshot ref blob (`git ls-tree`) before scripted restores"],"tags":["git","snapshot","ref-category","branch"],"backgroundTag":"unsupported-operation","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"}