{"record":{"id":"f7876003851e0c8e","repo":"gitbutlerapp/gitbutler","slug":"failed-to-cut-remote-name-longest-remote-off-of-shorthand","errorCode":null,"errorMessage":"Failed to cut remote name {longest_remote} off of shorthand name {shorthand_name}","messagePattern":"Failed to cut remote name (.+?) off of shorthand name (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-branch/src/reference_ext.rs","lineNumber":39,"sourceCode":"    fn identity(&self, remotes: &gix::remote::Names) -> Result<BranchIdentity> {\n        let (category, shorthand_name) = self\n            .category_and_short_name()\n            .context(\"Branch could not be categorized\")?;\n        if !matches!(category, Category::RemoteBranch) {\n            return Ok(shorthand_name.try_into()?);\n        }\n\n        let longest_remote = remotes\n            .iter()\n            .rfind(|reference_name| shorthand_name.starts_with(reference_name))\n            .ok_or(anyhow::anyhow!(\n                \"Failed to find remote branch's corresponding remote\"\n            ))?;\n\n        let shorthand_name: &BStr = shorthand_name\n            .strip_prefix(longest_remote.as_bytes())\n            .and_then(|str| str.strip_prefix(b\"/\"))\n            .ok_or(anyhow::anyhow!(\n                \"Failed to cut remote name {longest_remote} off of shorthand name {shorthand_name}\"\n            ))?\n            .into();\n\n        Ok(shorthand_name.try_into()?)\n    }\n}\n","sourceCodeStart":21,"sourceCodeEnd":47,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-branch/src/reference_ext.rs#L21-L47","documentation":"Thrown when parsing a remote-tracking ref name: after identifying the longest registered remote name, the code tries to strip `<remote>/` from the shorthand ref name. If the shorthand does not start with that remote name followed by `/`, no valid remote/branch split exists and this error is raised. It signals a ref name that claims a remote-tracking form but does not match any known remote prefix.","triggerScenarios":"Calling target_identity_from_ref_name with a ref whose name does not begin with one of the repo's registered remote names plus `/` (e.g. a ref under an unregistered remote, or a malformed ref like `refs/remotes/originbranch` with no slash).","commonSituations":"Repos where `.git/config` remote entries were removed or renamed while remote-tracking refs remain; refs created by tools using non-standard naming; a remote name with unusual characters causing the longest-match to mismatch.","solutions":["Check the ref name actually matches `refs/remotes/<remote>/<branch>` for a remote listed in `git remote -v`.","Re-add or fix the missing remote in `.git/config` so the prefix matches.","Delete stale refs (`git branch -r -d` or `git update-ref -d`) that no longer correspond to a configured remote.","Ensure the ref name contains a `/` after the remote name."],"exampleFix":"// before: ref = refs/remotes/oldremote/feature, remote 'oldremote' removed from config\n// after: git remote add oldremote <url> (or delete the stale ref)\ngit update-ref -d refs/remotes/oldremote/feature","handlingStrategy":"validation","validationCode":"fn is_remote_tracking(name: &str, remotes: &[String]) -> bool {\n    remotes.iter().any(|r| name.strip_prefix(\"refs/remotes/\").and_then(|s| s.strip_prefix(r)).map_or(false, |s| s.starts_with('/')))\n}","typeGuard":"fn split_remote_tracking<'a>(name: &'a str, remotes: &[String]) -> Option<(&'a str, &'a str)> {\n    let short = name.strip_prefix(\"refs/remotes/\")?;\n    remotes.iter().filter_map(|r| short.strip_prefix(r)?.strip_prefix('/').map(|b| (r.as_str(), b))).next()\n}","tryCatchPattern":null,"preventionTips":["Keep .git/config remotes in sync with existing refs; run git fetch --prune regularly.","Validate ref names against git remote before passing to reference parsing.","Avoid manually crafting refs/remotes/... names."],"tags":["git","ref-parsing","remote"],"backgroundTag":"resource-not-found","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"}