← 全部工具

git-branch-is

热度 65 更新于 开发与构建

Assert that the name of the current branch of a git repository has a particular value.

npmauto-collected

安装

npm
npm install -g git-branch-is

通过 npm 安装。

git-branch-is ===============

Assert that the name of the current branch of a git repository has a particular value.

Introductory Example

To check that the current branch is named release and print an error if not, run the following command:

$ git-branch-is release
Error: Current branch is "main", not "release".
$ echo $?
1

This can be useful as part of a preversion script in package.json:

{
  "name": "super-cool-package",
  "version": "1.2.3",
  "scripts": {
    "preversion": "git-branch-is release && echo Preversion checks passed."
  }
}

Installation

This package can be installed using npm, either globally or locally, by running:

npm install git-branch-is

Command Usage

The command options are intended to be similar to git and are documented in the --help output:

Usage: git-branch-is [options] <branch name>

Options:
  -C <path>           run as if started in <path>
  --git-arg <arg>     additional argument to git (can be repeated) (default: [])
  --git-dir <dir>     set the path to the repository
  --git-path <path>   set the path to the git binary
  -i, --ignore-case   compare/match branch name case-insensitively
  -I, --invert-match  inverts/negates comparison
  --not               inverts/negates comparison (same as --invert-match)
  -q, --quiet         suppress warning message if branch differs
  -r, --regex         match <branch name> as a regular expression

-V, --version output the version number -h, --help output usage information


## Additional Command Examples

### Regular Expression Matching

To check that the current branch starts with `release/` using a regular
expression:

$ git-branch-is -r "^release/" Error: Current branch "main" does not match "^release/". $ echo $? 1


Note:  Be careful to quote patterns to avoid shell expansion or special
handling (e.g. POSIX shells expand `*` and `cmd.exe` treats `^` specially).

### Case-Insensitive Matching

To check that the current branch starts with `release/` case-insensitively
using a regular expression:

$ git-branch-is -i -r "^release/" Error: Current branch "main" does not match "^release/". $ echo $? 1