UNPKG

validate-branch

Version:

A CLI tool to validate Git branch names using Conventional Branch guidelines.

8 lines (7 loc) 651 B
#!/usr/bin/env node "use strict";var o=require("child_process");function a(r){return/^(main|master|develop|(?:feature|bugfix|hotfix|chore)\/[a-z0-9\-]+|release\/[a-z0-9\-]+(?:\.[a-z0-9\-]+)*)$/.test(r)}var e;try{e=(0,o.execSync)("git rev-parse --abbrev-ref HEAD",{encoding:"utf8"}).trim()}catch{console.error("Error: Not a Git repository or Git is not installed."),process.exit(1)}a(e)?(console.log(`\u2705 Branch "${e}" is valid!`),process.exit(0)):(console.error(`\u274C Branch "${e}" is invalid. Please use: - main, master, develop - feature/branch-name - bugfix/branch-name - hotfix/branch-name - release/branch-name`),process.exit(1));