1 | #!/usr/bin/env node
|
2 |
|
3 | const exec = require('child_process').exec
|
4 |
|
5 | function currentBranch () {
|
6 | return new Promise((resolve, reject) => {
|
7 | exec('git branch --no-color', (err, out) => {
|
8 | if (err) return reject(err)
|
9 |
|
10 | let branches = out.split('\n')
|
11 | let branch = branches.find(branch => {
|
12 | return /^\*/.test(branch)
|
13 | })
|
14 |
|
15 | branch = branch.replace('*', '')
|
16 | branch = branch.trim()
|
17 |
|
18 | return resolve(branch)
|
19 | })
|
20 | })
|
21 | }
|
22 |
|
23 | currentBranch().then(branch => {
|
24 | console.log('Checking branch name...')
|
25 |
|
26 | if (branch !== 'master' &&
|
27 | branch !== 'develop' &&
|
28 | !/^feature\//.test(branch) &&
|
29 | !/^patch\//.test(branch) &&
|
30 | !/^release-/.test(branch)
|
31 | ) {
|
32 | console.log()
|
33 | console.log('Branch name invalid.')
|
34 | console.log('Please use topic branches named "feature/...", or "patch/..."')
|
35 | console.log()
|
36 |
|
37 | process.exit(1)
|
38 | } else {
|
39 | console.log('Branch name OK.')
|
40 | process.exit(0)
|
41 | }
|
42 | })
|