Skip to content

Commit 0b7d8ab

Browse files
committed
feat: Add pre-push hook to restrict branch naming
1 parent 7502c5f commit 0b7d8ab

File tree

4 files changed

+998
-1365
lines changed

4 files changed

+998
-1365
lines changed

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarn lint-staged

.husky/pre-push

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
branch=$(git rev-parse --abbrev-ref HEAD)
4+
pattern='^[a-z][a-z0-9\/\-]{1,29}$'
5+
6+
if [[ ! "$branch" =~ $pattern ]]; then
7+
echo """
8+
❌ Invalid branch name: '$branch'
9+
➡️ Branch names must match regex: $pattern
10+
- Start with a lowercase letter
11+
- Can contain lowercase letters, numbers, and hyphens
12+
- Length between 2 and 30 characters
13+
- Slashes '/' are allowed for hierarchical branch names
14+
Example: ocrvs-12345, feature-login, fix-bug123, refactor-api
15+
"""
16+
exit 1
17+
fi
18+
19+
exit 0

package.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,8 @@
1010
"node": "22.x.x"
1111
},
1212
"license": "MPL-2.0",
13-
"husky": {
14-
"hooks": {
15-
"pre-commit": "yarn precommit"
16-
}
17-
},
1813
"scripts": {
1914
"dev": "yarn start",
20-
"precommit": "lint-staged",
2115
"test": "vitest",
2216
"test:compilation": "tsc --noEmit",
2317
"lint": "eslint -c .eslintrc.js",
@@ -50,7 +44,7 @@
5044
"eslint": "^8.43.0",
5145
"eslint-config-prettier": "^9.1.0",
5246
"eslint-plugin-prettier": "^5.2.1",
53-
"husky": "1.0.0-rc.13",
47+
"husky": "^9.1.7",
5448
"inquirer": "^9.2.12",
5549
"js-yaml": "^4.1.0",
5650
"kleur": "^4.1.5",
@@ -129,5 +123,8 @@
129123
},
130124
"resolutions": {
131125
"acorn": "^6.4.1"
126+
},
127+
"husky": {
128+
"hooks": {}
132129
}
133130
}

0 commit comments

Comments
 (0)