{"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":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-oplog/src/oplog.rs","lineNumber":98,"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":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-oplog/src/oplog.rs#L80-L116","documentation":"When loading a snapshot's project metadata back from project_meta.toml, the stored targetRef string is parsed as a gix::refs::FullName and must be a remote-tracking branch (refs/remotes/...). If the ref name is unparseable the context reports 'invalid targetRef'; if it parses but names any other ref category (local branch, tag, etc.) this bail fires, because snapshot restore requires a remote-tracking target.","triggerScenarios":"Restoring an oplog snapshot whose project_meta.toml contains a targetRef pointing at a non-remote-tracking ref, e.g. refs/heads/main instead of refs/remotes/origin/main, or a malformed/garbage ref string.","commonSituations":"Projects whose target was set to a local-only branch when the snapshot was taken; manual edits to project_meta.toml; older/other tooling writing a different ref format; hand-crafted test snapshots.","solutions":["Set the project target to a remote-tracking branch (refs/remotes/<remote>/<branch>) before taking snapshots you may need to restore.","Edit project_meta.toml in the snapshot to correct targetRef to a refs/remotes/... full name.","Push the target branch to a remote and re-point the target, then retake the snapshot.","If the snapshot is unrecoverable, restore workspace state manually rather than via oplog restore."],"exampleFix":"// before (project_meta.toml inside snapshot)\ntargetRef = \"refs/heads/main\"\n// after\ntargetRef = \"refs/remotes/origin/main\"","handlingStrategy":"validation","validationCode":"let name: gix::refs::FullName = target_ref.parse()?;\nassert_eq!(name.category(), Some(gix::refs::Category::RemoteBranch),\n    \"target must be a remote-tracking branch\");","typeGuard":"fn is_remote_tracking_ref(name: &str) -> bool {\n    gix::refs::FullName::try_from(name.to_owned()).ok()\n        .and_then(|n| n.category().map(|c| c == gix::refs::Category::RemoteBranch))\n        .unwrap_or(false)\n}","tryCatchPattern":"match restore_snapshot(&ctx, id) {\n    Err(e) if e.to_string().contains(\"not a remote-tracking branch\") => {\n        // repair metadata or restore manually\n    }\n    other => other?,\n}","preventionTips":["Always set the project target to refs/remotes/<remote>/<branch>, never a local branch","Validate targetRef format when writing project_meta.toml, not only at restore time","Don't hand-edit snapshot metadata; use the target-assignment API"],"tags":["git","oplog","snapshot-restore","ref-format","validation"],"backgroundTag":"invalid-argument-format","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"}