Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

validate-branch-name

JsonMa195.4kMIT1.3.2

Git branch name validator

validate-branch-name, branch-name, branch, hook, git, git hook, git branch name, branch name, pre push, git push

readme

validate-branch-name

GitHub license npm version Build Status codecov PRs Welcome Known Vulnerabilities npm download npm

中文文档

Git branch name validator.

Description

validate-branch-name can be used through command line directly. When using with Husky, you should make sure husky version >= v1.0.0.

Install

# local install
$ npm i validate-branch-name -D

# global install
$ npm i validate-branch-name -g

Usage

Use through command line


npx validate-branch-name

# test target branch name
npx validate-branch-name -t test/branch/name

# define regexp to test branch name
npx validate-branch-name -r regexp -t test/branch/name

# use -h for more usage detail
npx validate-branch-name -h

Use with husky

First way:

Configure hooks and pattern using package.json.

// {app_root}/package.json
{
  "husky": {
    "hooks": {
      "pre-commit": "npx validate-branch-name"
    }
  },
  "validate-branch-name": {
    "pattern": "^(master|main|develop){1}$|^(feature|fix|hotfix|release)\/.+$",
    "errorMsg": "your own error message"
  }
}

Second way:

Define pre-commit file under .husky directory.


#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# validate branch name before commit

npx validate-branch-name 

We have set pattern and errorMsg by default, but you can still defined them as you like.

Default pattern: ^(master|main|develop){1}$|^(feature|fix|hotfix|release)/.+$

Example: feature/test/pattern-test would be passed.

Available patterns:

  • ^(feature|fix|hotfix|release)/.+ - branch has to start with feature/, fix/, release/ or hotfix/

  • (feature|release|hotfix)/(JIRA-\d+) - it should look like feature/JIRA-1234

  • (feature|release|hotfix)/(JIRA-\d+/)?[a-z-]+ - it should look like feature/branch-name or include JIRA's code like feature/JIRA-1234/branch-name

  • custom patterns, visit regex.

You can also use .validate-branch-namerc, .validate-branch-namerc.json, .validate-branch-namerc.yaml, .validate-branch-namerc.yml, .validate-branch-namerc.js, .validate-branch-namerc.cjs, validate-branch-name.config.js or validate-branch-name.config.cjs file to define config.

Questions & Suggestions

Please open an issue here.

License

MIT

changelog

1.3.0 (2022-02-22)

Features

  • add main to detfault config (9d58f00)

1.2.1 (2021-11-30)

Features

  • :bookmark: release v1.2.1 (ee547af)

1.2.0 (2021-11-26)

Features

  • :bookmark: release v1.1.1 (175b7a2)
  • :sparkles: support.cjs config file (d5afb5f)

1.1.1 (2021-11-25)

Bug Fixes

  • :bug: fix useless console log (f23fb87)

Features

  • :bookmark: release v1.1.0 (c8df179)
  • add change log to project (0944421)

1.1.0 (2021-11-25)

Features

  • :memo: socialify project (5f7270d)
  • :sparkles: add command line interface (bafc956)
  • add husky pre-commit example (b1a5a10)
  • add json config example (9207f9c)
  • add logo to project (b7f36db)
  • add logo to readme (4f8da80)
  • add transparent logo (a36da44)

1.0.6 (2020-04-23)

1.0.5 (2020-01-14)

1.0.4 (2019-08-16)

Bug Fixes

Features

  • add bin config to package.json (4e0db74)
  • add node prefix to bin file (abe5c58)
  • add validation method (fd28804)