{"record":{"id":"abe5ecc0e1b4ddf0","repo":"gitbutlerapp/gitbutler","slug":"targetref-in-project-meta-toml-is-not-a-remote-tra","errorCode":null,"errorMessage":"targetRef in project_meta.toml is not a remote-tracking branch","messagePattern":"targetRef in project_meta\\.toml is not a remote-tracking branch","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-oplog/src/oplog.rs","lineNumber":97,"sourceCode":"            target_ref: meta.target_ref.as_ref().map(ToString::to_string),\n            target_commit_id: target_commit_id.to_string(),\n            push_remote: meta.push_remote.clone(),\n        })\n    }\n}\n\nimpl TryFrom<SnapshotProjectMeta> for ProjectMeta {\n    type Error = anyhow::Error;\n\n    fn try_from(meta: SnapshotProjectMeta) -> Result<Self> {\n        let target_ref = meta\n            .target_ref\n            .map(|name| {\n                let name: gix::refs::FullName = name\n                    .try_into()\n                    .context(\"invalid targetRef in project_meta.toml\")?;\n                if name.category() != Some(gix::refs::Category::RemoteBranch) {\n                    bail!(\"targetRef in project_meta.toml is not a remote-tracking branch\");\n                }\n                Ok(name)\n            })\n            .transpose()?;\n        let target_commit_id = gix::ObjectId::from_str(&meta.target_commit_id)\n            .context(\"invalid targetCommitId in project_meta.toml\")?;\n        if target_commit_id.is_null() {\n            bail!(\"targetCommitId in project_meta.toml is null\");\n        }\n        Ok(Self {\n            target_ref,\n            target_commit_id: Some(target_commit_id),\n            push_remote: meta.push_remote,\n        })\n    }\n}\n\n/// The Oplog allows for crating snapshots of the current state of the project as well as restoring to a previous snapshot.","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/gitbutler-oplog/src/oplog.rs#L79-L115","documentation":"On snapshot restore, `ProjectMeta` is rebuilt from the stored `project_meta.toml`; a `targetRef` must be a remote-tracking branch (a ref under `refs/remotes/`). A ref name in any other category — local branch, tag, or other — is rejected so a bogus target can never be restored into the project.","triggerScenarios":"Restoring an oplog snapshot whose recorded targetRef is not `refs/remotes/<remote>/<branch>`, e.g. `refs/heads/main` or `refs/tags/v1` stored in the snapshot's metadata tree.","commonSituations":"Hand-edited snapshot trees; snapshots written by an incompatible GitButler version or external tooling; migration artifacts from older formats.","solutions":["Fix the snapshot's targetRef to a valid remote-tracking ref such as `refs/remotes/origin/main` and retry the restore","Restore from an earlier, consistent snapshot entry instead","Recreate the state manually (reselect the target branch, re-apply changes) if the snapshot cannot be repaired"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let name: gix::refs::FullName = stored_target_ref.parse()?;\nif name.category() != Some(gix::refs::Category::RemoteBranch) {\n    return Err(anyhow::anyhow!(\"refusing snapshot with non-remote-tracking targetRef {name}\"));\n}","typeGuard":"fn is_remote_tracking(ref_name: &gix::refs::FullName) -> bool {\n    ref_name.category() == Some(gix::refs::Category::RemoteBranch)\n}","tryCatchPattern":"match oplog.restore(snapshot_id) {\n    Err(err) if err.to_string().contains(\"not a remote-tracking branch\") => { /* pick another snapshot */ }\n    other => other,\n}","preventionTips":["Never hand-edit snapshot metadata","Validate ref category when writing refs into project metadata"],"tags":["rust","gitbutler","oplog","restore","ref-validation"],"backgroundTag":"invalid-reference-format","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}