{"record":{"id":"5bc7cf9f156d2c98","repo":"linera-io/linera-protocol","slug":"failed-to-get-current-branch-name","errorCode":null,"errorMessage":"Failed to get current branch name","messagePattern":"Failed to get current branch name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"linera-summary/src/github.rs","lineNumber":94,"sourceCode":"    /// Returns the commit hash at the PR's head.\n    pub fn pr_commit_hash(&self) -> &str {\n        &self.pr_commit_hash\n    }\n\n    /// Returns the repository the PR belongs to.\n    pub fn repository(&self) -> &GithubRepository {\n        &self.repository\n    }\n\n    fn get_local_git_info() -> Result<(String, String, String)> {\n        let repo = git2::Repository::open_from_env().context(\"Failed to open git repository\")?;\n\n        let head = repo.head()?;\n        let commit_hash = head.peel_to_commit()?.id().to_string();\n\n        let branch_name = if head.is_branch() {\n            head.shorthand()\n                .ok_or_else(|| anyhow!(\"Failed to get current branch name\"))?\n                .to_string()\n        } else {\n            anyhow::bail!(\"HEAD is not on a branch - it may be detached\");\n        };\n\n        // This local mode is only used for testing, so we're just hardcoding `main` as the base branch for now.\n        Ok((commit_hash, branch_name, \"main\".to_string()))\n    }\n\n    fn from_env(is_local: bool, pr_number: Option<u64>) -> Result<Self> {\n        let env_pr_commit_hash = env::var(\"GITHUB_PR_COMMIT_HASH\");\n        let env_pr_branch = env::var(\"GITHUB_PR_BRANCH\");\n        let env_base_branch = env::var(\"GITHUB_BASE_BRANCH\");\n        let env_pr_number = env::var(\"GITHUB_PR_NUMBER\");\n\n        let (pr_commit_hash, pr_branch, base_branch, pr_number) = if is_local {\n            let (commit_hash, branch_name, base) = Self::get_local_git_info()?;\n            (","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-summary/src/github.rs#L76-L112","documentation":"In local mode, GithubContext::get_local_git_info opens the repo with git2, resolves HEAD, and reads the branch shorthand. This error means HEAD is a branch but git2 could not produce a valid shorthand for its name — in practice a non-UTF-8 or otherwise malformed reference name. (A detached HEAD takes the other branch and fails with a different message.)","triggerScenarios":"Running linera-summary in local mode from a working copy whose current branch ref name is not representable as a shorthand string. Normal UTF-8 branch names never hit this.","commonSituations":"Branch names with exotic or non-UTF-8 bytes created by scripting or on other filesystems; corrupted refs under .git/refs or packed-refs. Rare in everyday use.","solutions":["Check out a branch with a plain UTF-8 name: git checkout -b summary-run && rerun","Inspect the ref: git symbolic-ref HEAD and the file under .git/refs/ or packed-refs for encoding damage","If you did not intend local mode, run in CI mode instead where the branch comes from GITHUB_PR_BRANCH"],"exampleFix":"# before\n(non-UTF-8 branch checked out)\n# after\ngit checkout -b summary-run && linera-summary --local ...","handlingStrategy":"validation","validationCode":"// Rust: pre-check that HEAD resolves to a named UTF-8 branch\nfn head_branch_name(repo: &git2::Repository) -> Option<String> {\n    let head = repo.head().ok()?;\n    if !head.is_branch() { return None; }\n    head.shorthand().map(|s| s.to_string())\n}","typeGuard":"fn has_readable_branch(repo: &git2::Repository) -> bool {\n    head_branch_name(repo).is_some()\n}","tryCatchPattern":"match GithubContext::get_local_git_info() {\n    Ok(info) => info,\n    Err(e) => {\n        eprintln!(\"local git context unavailable ({e:#}); checkout a UTF-8-named branch or use CI mode\");\n        return Err(e);\n    }\n}","preventionTips":["Before local runs, verify `git branch --show-current` prints a normal name","Avoid non-UTF-8 bytes in branch names anywhere in automation","Run summary tooling from a plain feature branch rather than exotic refs"],"tags":["linera","git","ci","local-mode"],"backgroundTag":"git-branch-resolution-failed","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}