Commit c738610d authored by shangbj's avatar shangbj

update

parent 5b194d0c
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const logSymbols = require('log-symbols');
console.log(logSymbols.success, chalk.red('Hello world!'));
// process.exit(1)
// const execSync = require('child_process').execSync
// // git 对所有冲突的地方都会生成下面这种格式的信息,所以写个检测冲突文件的正则
// const isConflictRegular = "^<<<<<<<\\s|^=======$|^>>>>>>>\\s"
// let results
// try {
// // git grep 命令会执行 perl 的正则匹配所有满足冲突条件的文件
// results = execSync(`git grep -n -P "${isConflictRegular}"`, {encoding: 'utf-8'})
// } catch (e) {
// console.log('没有发现冲突,等待 commit')
// process.exit(0)
// }
// if(results) {
// console.error('发现冲突,请解决后再提交,冲突文件:')
// console.error(results.trim())
// process.exit(1)
// }
const logSymbols = require('log-symbols')
const gitPath = path.join(process.cwd(), process.env.HUSKY_GIT_PARAMS);
const mergeMsgPath = path.join(gitPath,'../','MERGE_MSG')
function mergeCheck(){
const mergeMsg = fs.readFileSync(mergeMsgPath, 'utf-8');
console.log(mergeMsg)
}
function commitMsgCheck(){
const commitMsg = fs.readFileSync(gitPath, 'utf-8');
if(!commitMsg) {
console.log(logSymbols.error, chalk.red('no message'))
process.exit(1)
}
}
function conflictCheck() {
console.log(logSymbols.info, chalk.blue('开始冲突检测...'))
const execSync = require('child_process').execSync
// git 对所有冲突的地方都会生成下面这种格式的信息,所以写个检测冲突文件的正则
const isConflictRegular = "^<<<<<<<\\s|^=======$|^>>>>>>>\\s"
let results
try {
// git grep 命令会执行 perl 的正则匹配所有满足冲突条件的文件
results = execSync(`git grep -n -P "${isConflictRegular}"`, {encoding: 'utf-8'})
} catch (e) {
process.exit(0)
}
if(results) {
console.log(logSymbols.error, chalk.red('发现冲突,请解决后再提交,冲突文件:'))
console.log(results.trim())
process.exit(1)
}
}
if(fs.existsSync(mergeMsgPath)){
mergeCheck()
} else {
commitMsgCheck()
}
conflictCheck()
process.exit(0)
\ No newline at end of file
......@@ -12,7 +12,7 @@
},
"husky": {
"hooks": {
"commit-msg": "node ./build/commit-hook.js"
"commit-msg": "node ./build/commit-hook.js $HUSKY_GIT_PARAMS"
}
},
"keywords": [],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment