Для проверки текущей ветки Git на соответствие условиям выполнения команд, используется в npm скриптах hook, чтобы предотвратить выполнение неправильной команды в неправильной ветке.
npm install git-branch-check -D
yarn add git-branch-check -D
// package.json
{
"name": "xxx",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "node ./build.js",
"prebuild": "npx git-branch-check include master",
"staging": "node ./staging.js",
"prestaging": "npx git-branch-check exclude master"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"colors": "^1.4.0",
"commander": "^6.0.0",
"execa": "^4.0.3"
}
}
Как показано выше, npm run build
может выполняться только в ветке master
, а во всех других ветках будет выдана ошибка. В то же время, npm run staging
можно выполнять только за пределами ветки master
, а в самой ветке master
будет выдана ошибка.
Использование: git-branch-check [опции] [команда]
Опции:
-V, --version выводит номер версии
-h, --help отображает помощь для команды
Команды:
include <ветки> позволяет выполнять в ограниченных ветках, несколько веток разделены запятой
exclude <ветки> позволяет выполнять в исключаемых ветках, несколько веток разделены запятой
help [команда] отображает помощь для команды
You can comment after Login
Inappropriate content may be displayed here and will not be shown on the page. You can check and modify it through the relevant editing function
If you confirm that the content does not involve inappropriate language/advertisement redirection/violence/vulgar pornography/infringement/piracy/false/insignificant or illegal content related to national laws and regulations, you can click submit to make an appeal, and we will handle it as soon as possible.
Comments ( 0 )