abhigyanpatwari/GitNexus · error · InvalidBranchError
: branch name must not contain consecutive slashes.
Error message
${source}: branch name must not contain consecutive slashes. What it means
validateBranchName rejects names containing '//' (consecutive slashes), matching git's ref-format rules; git itself never creates refs with empty path components. The library throws a descriptive InvalidBranchError early rather than letting the git subprocess fail later with a less clear message.
Solutions
- Collapse consecutive slashes: `name.replace(/\/{2,}/g, "/")` before validating.
- Fix the join logic so empty segments are filtered out (e.g. `[a, b].filter(Boolean).join("/")`).
- Verify the source variable (env var, config key) is actually populated.
Example fix
// before
const branch = `${group}/${sub}/${name}`; // group empty -> "//feature"
validateBranchName(branch);
// after
const branch = [group, sub, name].filter(Boolean).join("/");
validateBranchName(branch); Defensive patterns
Strategy: validation
Validate before calling
function hasDoubleSlash(name) { return typeof name === "string" && name.includes("//"); }
branch = String(branch ?? "").replace(/\/{2,}/g, "/"); Type guard
function isSingleSlashed(v: unknown): v is string {
return typeof v === "string" && !v.includes("//");
} Try / catch
try {
validateBranchName(branch, "http");
} catch (e) {
if (e instanceof InvalidBranchError && e.message.includes("consecutive slashes")) {
return res.status(400).json({ error: "branch names must not contain '//'" });
}
throw e;
} Prevention
- Check that env vars interpolated into branch names are non-empty.
- Normalize URLs/paths before reusing their segments as branch names.
- Use defensive joins ([...parts].filter(Boolean).join('/')).
- Add a unit test for names built from empty segments.
When it happens
Trigger: Calling validateBranchName with 'feature//next' or names built by joining segments where an empty segment occurs, e.g. `${a}/${b}` with empty a or b, or double slashes from copy-pasted URLs/paths.
Common situations: CI environment variables that are empty or unset producing 'origin//branch'; naive path joins; pasting 'refs/heads//name' style strings.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- err.message (InvalidBranchError rethrown as GitNexusRcError…
- : branch name contains characters not allowed in a git ref…
- : branch name is too long (max ).
- : branch name must not be empty.
- : branch name must not be "HEAD".
AI-assisted analysis of abhigyanpatwari/GitNexus@ac9a4e9abd (2026-09-15).
Data as JSON: /api/errors/7e912facf0b5c34d.
Report an issue: GitHub.
Appendix: source
Thrown at gitnexus/src/core/git-ref.ts:103
if (trimmed === 'HEAD') {
throw new InvalidBranchError(`${source}: branch name must not be "HEAD".`);
}
if (trimmed.includes('..')) {
throw new InvalidBranchError(`${source}: branch name must not contain "..".`);
}
// The remaining `git check-ref-format` rules. Without these the validator
// accepted refs git itself refuses (`feature.lock`, `/feature`, `feature/`,
// `feature//next`, `@`, `.hidden`), so the failure surfaced later from the
// git subprocess instead of here. No real branch can violate them — git
// could not have created one — so nothing that works today starts failing.
if (trimmed.endsWith('.lock') || trimmed.split('/').some((part) => part.endsWith('.lock'))) {
throw new InvalidBranchError(`${source}: branch name must not end with ".lock".`);
}
if (trimmed.startsWith('/') || trimmed.endsWith('/')) {
throw new InvalidBranchError(`${source}: branch name must not start or end with "/".`);
}
if (trimmed.includes('//')) {
throw new InvalidBranchError(`${source}: branch name must not contain consecutive slashes.`);
}
if (trimmed === '@') {
throw new InvalidBranchError(`${source}: branch name must not be the single character "@".`);
}
if (trimmed.includes('@{')) {
throw new InvalidBranchError(`${source}: branch name must not contain "@{".`);
}
if (trimmed.endsWith('.') || trimmed.split('/').some((part) => part.startsWith('.'))) {
throw new InvalidBranchError(
`${source}: branch name must not end with "." or have a path component starting with ".".`,
);
}
// Git permits a backtick in a ref, but the branch is embedded inside a
// Markdown inline-code span in the generated AGENTS.md/CLAUDE.md regression
// example, where a backtick would close the span early and let the rest of
// the template render as instruction text. Reject it at this single
// chokepoint so all three tiers (CLI flag, .gitnexusrc, auto-detect via
// sanitizeDetectedBranch) are covered (#1996 tri-review P1).View on GitHub (pinned to ac9a4e9abd)