Commit c738610d authored by shangbj's avatar shangbj

update

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