INNER CODE UNIT · TypeScript
assertValidBranchName
EndBug/add-and-commit · src/util.ts:183
export function assertValidBranchName(name: string): void {
if (!name || !name.trim()) {
throw new Error('The new_branch value is empty.');
}
if (name.startsWith('-')) {
throw new Error(
`The new_branch value '${neutralizeLogString(name)}' cannot start with '-' (it would be interpreted as a git option).`,
);
}
for (const char of name) {
const code = char.codePointAt(0)!;
if (
code <= 0x1f || // C0 controls
code === 0x7f || // DEL
(code >= 0x80 && code <= 0x9f) || // C1 controls
/\s/u.test(char) // Unicode whitespace (e.g. NBSP)
) {
throw new Error(