{"record":{"id":"e2b07b652df7be37","repo":"gitbutlerapp/gitbutler","slug":"defaulttargetnotfound","errorCode":"DefaultTargetNotFound","errorMessage":"there is no default target","messagePattern":"there is no default target","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-core/src/ref_metadata.rs","lineNumber":300,"sourceCode":"    match repo.find_reference(target_ref) {\n        Ok(mut target_ref) => {\n            if project_meta.target_commit_id.is_none()\n                && let Ok(commit) = target_ref.peel_to_commit()\n            {\n                project_meta.target_commit_id = Some(commit.id);\n            }\n        }\n        Err(_) => project_meta.target_ref = None,\n    }\n    project_meta\n}\n\nimpl ProjectMeta {\n    /// Return [`Self::target_ref`], or a [`DefaultTargetNotFound`](but_error::Code::DefaultTargetNotFound)\n    /// error if no target is configured.\n    pub fn target_ref_or_err(&self) -> Result<&gix::refs::FullName> {\n        self.target_ref.as_ref().ok_or_else(|| {\n            anyhow::anyhow!(\"there is no default target\")\n                .context(but_error::Code::DefaultTargetNotFound)\n        })\n    }\n\n    /// Return [`Self::target_commit_id`], or a [`DefaultTargetNotFound`](but_error::Code::DefaultTargetNotFound)\n    /// error if no target commit is known.\n    pub fn target_commit_id_or_err(&self) -> Result<gix::ObjectId> {\n        self.target_commit_id.ok_or_else(|| {\n            anyhow::anyhow!(\"there is no default target commit\")\n                .context(but_error::Code::DefaultTargetNotFound)\n        })\n    }\n\n    /// The name of the remote to push to: [`Self::push_remote`], falling back to the\n    /// remote behind [`Self::target_ref`].\n    ///\n    /// If no configured remote matches the target ref, fall back to the first path component\n    /// after `refs/remotes/`, the textual remote name that legacy metadata stored verbatim.","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-core/src/ref_metadata.rs#L282-L318","documentation":"ProjectMeta::target_ref_or_err returns this DefaultTargetNotFound error when the project metadata has no target_ref configured. The target ref (the remote branch a local branch is based on, e.g. refs/remotes/origin/main) is required for operations that need to compare against the default branch. Callers like target_short_name and push_remote_name depend on it, so any operation that resolves branch metadata before a target was established hits this.","triggerScenarios":"Calling target_ref_or_err (directly or via target_short_name/push_remote_name) on a ProjectMeta built before the target was recorded — e.g. in a repo with no remote tracking configuration or before first assignment of a default target.","commonSituations":"Freshly cloned-but-not-configured repos; repositories without any remote; running but commands before the first target/assignment was written; deleted remote-tracking branch leaving target_ref unset.","solutions":["Configure the default target (assign the base branch) via the but UI/CLI (`but branch`/assignment flow or set target metadata)","Add a remote and a remote-tracking ref (`git remote add origin ...; git fetch`) then retry","Avoid calling *_or_err variants on projects known to lack a target; use the Option-returning target_ref() instead"],"exampleFix":"// before\nlet short = meta.target_short_name()?; // panics if no target\n// after\nif let Some(tref) = meta.target_ref() {\n    let short = meta.target_short_name()?;\n} else {\n    assign_default_target(&mut meta)?;\n}","handlingStrategy":"validation","validationCode":"if meta.target_ref().is_none() {\n    assign_default_target(&mut meta)?; // or bail early\n}","typeGuard":"fn has_target(meta: &ProjectMeta) -> bool { meta.target_ref().is_some() }","tryCatchPattern":"match meta.target_ref_or_err() {\n    Ok(tref) => use(tref),\n    Err(e) if e.root_cause().to_string().contains(\"no default target\") => configure_target()?,\n    Err(e) => return Err(e),\n}","preventionTips":["Always configure the default target before operations that compare against it","Ensure the repo has a remote and fetched remote-tracking refs","Prefer Option-returning accessors (target_ref) when a missing target is acceptable"],"tags":["git","configuration","target-branch"],"backgroundTag":"missing-config-value","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"}