{"record":{"id":"687e9ae8f20faf76","repo":"affaan-m/ECC","slug":"branch-name-is-not-a-valid-git-ref","errorCode":null,"errorMessage":"branch name is not a valid git ref","messagePattern":"branch name is not a valid git ref","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":1491,"sourceCode":"    }\n\n    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())\n}\n\nfn validate_branch_name(repo_root: &Path, branch: &str) -> Result<()> {\n    let output = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(repo_root)\n        .args([\"check-ref-format\", \"--branch\", branch])\n        .output()\n        .context(\"Failed to validate worktree branch name\")?;\n\n    if output.status.success() {\n        Ok(())\n    } else {\n        let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();\n        if stderr.is_empty() {\n            anyhow::bail!(\"branch name is not a valid git ref\");\n        } else {\n            anyhow::bail!(\"{stderr}\");\n        }\n    }\n}\n\nfn parse_git_status_entry(line: &str) -> Option<GitStatusEntry> {\n    if line.len() < 4 {\n        return None;\n    }\n    let bytes = line.as_bytes();\n    let index_status = bytes[0] as char;\n    let worktree_status = bytes[1] as char;\n    let raw_path = line.get(3..)?.trim();\n    if raw_path.is_empty() {\n        return None;\n    }\n    let display_path = raw_path.to_string();","sourceCodeStart":1473,"sourceCodeEnd":1509,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L1473-L1509","documentation":"`validate_branch_name` runs git's own ref-name check and bails with this generic message when the check fails and git printed no stderr. It means the supplied branch name violates git ref naming rules (e.g. contains spaces, '..', starts with '-', ends with '.lock', or includes control characters).","triggerScenarios":"Creating or renaming a branch with a name git rejects but whose rejection message is empty — commonly names with forbidden sequences like 'a..b', 'a b', '@{', or empty/whitespace names.","commonSituations":"Branch name derived from a free-text prompt, ticket title, or AI-generated label that contains spaces or invalid characters; trailing slashes; names ending in '.lock' or '.\".',","solutions":["Sanitize the name: replace spaces and invalid characters with '-', strip leading '-' and trailing '.lock'/'.'","Validate before calling using 'git check-ref-format --branch <name>' and surface its stderr","Keep names to [A-Za-z0-9._/-] without '..' or '@{' sequences","If the name comes from user input, apply a slugify/kebab-case step at the boundary"],"exampleFix":"// before: raw user input\nlet branch = user_input.trim();\nvalidate_branch_name(&root, branch)?;\n// after: normalize to a safe ref name\nlet branch: String = user_input\n    .trim()\n    .to_lowercase()\n    .chars()\n    .map(|c| if c.is_ascii_alphanumeric() || matches!(c, '/' | '-' | '_' | '.') { c } else { '-' })\n    .collect();\nlet branch = branch.trim_matches(|c| c == '-' || c == '.').to_string();\nvalidate_branch_name(&root, &branch)?;","handlingStrategy":"validation","validationCode":"let valid = Command::new(\"git\")\n    .args([\"check-ref-format\", \"--branch\", name])\n    .output()\n    .map(|o| o.status.success())\n    .unwrap_or(false);","typeGuard":"fn is_safe_branch_name(name: &str) -> bool {\n    !name.is_empty()\n        && name.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '/' | '-' | '_' | '.'))\n        && !name.contains(\"..\")\n        && !name.contains(\"@{\")\n        && !name.starts_with('-')\n        && !name.ends_with(\".lock\")\n}","tryCatchPattern":"match create_branch(&root, name) {\n    Ok(b) => b,\n    Err(e) if e.to_string().contains(\"not a valid git ref\") => {\n        eprintln!(\"sanitize name '{name}' (spaces/.. /.lock are forbidden)\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Slugify user- or AI-supplied names before creating branches","Ban spaces, '..', '@{', leading '-', and '.lock' suffixes at input boundaries","Validate with 'git check-ref-format --branch' before the create call","Prefer kebab-case naming conventions for generated branch names"],"tags":["git","branch-name","validation"],"backgroundTag":"invalid-identifier-format","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}