-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathprecommit.js
More file actions
43 lines (35 loc) · 952 Bytes
/
precommit.js
File metadata and controls
43 lines (35 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env node
const exec = require('child_process').exec
function currentBranch() {
return new Promise((resolve, reject) => {
exec('git branch --no-color', (err, out) => {
if (err) return reject(err)
const branches = out.split('\n')
let branch = branches.find(branch => {
return /^\*/.test(branch)
})
branch = branch.replace('*', '')
branch = branch.trim()
return resolve(branch)
})
})
}
currentBranch().then(branch => {
console.log('Checking branch name...')
if (
branch !== 'master' &&
branch !== 'develop' &&
!/^feature\//.test(branch) &&
!/^patch\//.test(branch) &&
!/^release-/.test(branch)
) {
console.log()
console.log('Branch name invalid.')
console.log('Please use topic branches named "feature/...", or "patch/..."')
console.log()
process.exit(1)
} else {
console.log('Branch name OK.')
process.exit(0)
}
})