abhigyanpatwari/GitNexus · error · Error
must not start with "-"
Error message
must not start with "-"
What it means
A branch name starting with '-' would be interpreted by git command lines as an option flag rather than a ref (argument injection), so validateAutoSyncBranchName rejects it as its own explicit check. The library throws at config parse time via parseAutoSyncConfig, before any git invocation.
Source
Thrown at gitnexus/src/core/auto-sync/config.ts:339
!repoName ||
repoName === '.' ||
repoName === '..' ||
repoName === 'unknown' ||
repoName.startsWith('-') ||
!REMOTE_REPO_NAME_PATTERN.test(repoName)
) {
throw new Error(
'repository name must use only letters, digits, ".", "_", or "-" and must not be "unknown"',
);
}
}
export function validateAutoSyncBranchName(branch: string): void {
if (!branch.trim()) throw new Error('must not be empty');
if (/[\s\0-\x1f\x7f]/.test(branch))
throw new Error('must not contain whitespace or control characters');
if (/[~^:?*[\\]/.test(branch)) throw new Error('contains characters not allowed in a git ref');
if (branch.startsWith('-')) throw new Error('must not start with "-"');
if (branch.startsWith('/')) throw new Error('must not start with "/"');
if (branch.includes('..')) throw new Error('must not contain ".."');
if (branch.includes('`')) throw new Error('must not contain backticks');
if (branch.endsWith('/') || branch.endsWith('.')) throw new Error('must not end with "/" or "."');
if (branch.includes('//')) throw new Error('must not contain consecutive slashes');
if (branch.includes('@{')) throw new Error('must not contain "@{"');
if (
branch
.split('/')
.some(
(component) =>
component.startsWith('.') || component.endsWith('.') || component.endsWith('.lock'),
)
)
throw new Error('must not contain hidden, trailing-dot, or .lock path components');
}
export function parseDurationMs(value: unknown): number {View on GitHub (pinned to 0d1aed942f)
Solutions
- Remove the leading '-' and use the actual branch name (e.g. -main → main).
- Never put git flags in the branches list — flags are not supported there.
- If you intended a dash-separated name, ensure the dash is not first: my-branch is fine, -branch is not.
Example fix
// before branches: - "--all" // after branches: - main
Defensive patterns
Strategy: validation
Validate before calling
function noLeadingDash(b) {
return typeof b === 'string' && !b.startsWith('-');
}
const bad = (cfg.branches ?? []).filter((b) => !noLeadingDash(b));
if (bad.length) throw new Error(`branches must not start with '-': ${JSON.stringify(bad)}`); Try / catch
try {
validateAutoSyncBranchName(branch);
} catch (e) {
if (String(e.message).includes('must not start with "-"')) {
log.error(`'${branch}' looks like a git flag; put the actual branch name in branches[].`);
}
throw e;
} Prevention
- Never place git CLI flags (--force, --all) in the branches list.
- Sanitize any user/script-provided branch value for a leading dash.
- Treat branches[] entries as pure ref names, not command fragments.
When it happens
Trigger: branches: ["--force"], ["-main"], or a config where a flag like '--all' was accidentally placed in the branches list; a generated value that lost its prefix, e.g. an env var '-b main' fragment.
Common situations: Someone tried to pass git flags through the branches list; shell history fragments pasted into config; scripts emitting '- ' list markers into the value itself.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- path must include owner/repo without traversal
- must not be empty
- must not contain whitespace or control characters
- contains characters not allowed in a git ref
- must not start with "/"
AI-assisted analysis of abhigyanpatwari/GitNexus@0d1aed942f (2026-09-08).
Data as JSON: /api/errors/7bb9f0abff1c368a.
Report an issue: GitHub.