sourcecontrol
Version:
A modern TypeScript CLI application for source control
49 lines • 1.67 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.BranchValidator = void 0;
class BranchValidator {
static validateBranchName(name) {
const errors = [];
if (!name || name.length === 0) {
errors.push('Branch name cannot be empty');
}
if (BranchValidator.RESERVED_NAMES.includes(name)) {
errors.push(`Branch name '${name}' is reserved`);
}
if (name.startsWith('.') || name.endsWith('.')) {
errors.push('Branch name cannot start or end with a dot');
}
if (name.endsWith('/')) {
errors.push('Branch name cannot end with a slash');
}
if (BranchValidator.INVALID_CHARS.test(name)) {
errors.push('Branch name contains invalid characters');
}
for (const sequence of BranchValidator.INVALID_SEQUENCES) {
if (name.includes(sequence)) {
errors.push(`Branch name cannot contain '${sequence}'`);
}
}
return {
isValid: errors.length === 0,
errors,
};
}
static validateAndThrow(name) {
const result = this.validateBranchName(name);
if (!result.isValid) {
throw new Error(`Invalid branch name: ${result.errors.join(', ')}`);
}
}
}
exports.BranchValidator = BranchValidator;
BranchValidator.RESERVED_NAMES = [
'HEAD',
'refs',
'refs/heads',
'refs/tags',
'refs/remotes',
];
BranchValidator.INVALID_CHARS = /[\x00-\x1f\x7f ~^:?*\[]/;
BranchValidator.INVALID_SEQUENCES = ['..', '//', '@{', '\\'];
//# sourceMappingURL=branch-validator.js.map
;