check-commit.cjs 453 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
const fs = require('fs')
const {
  execSync
} = require('child_process')

const message = fs.readFileSync(process.argv[2]).toString('utf8').toLowerCase()
const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim()

if (
  (branch === 'master' || branch === 'alpha') &&
  !message.startsWith('merge') &&
  !message.startsWith('*')
) {
  console.log('You are not allowed to commit directly to master or alpha branch')
  process.exit(1)
}