Skip to content

Commit

Permalink
fetch master
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Mar 14, 2018
1 parent 763990e commit 2e461d6
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions cmds/commitlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,39 @@ function exec (command) {
})
}

exec('git rev-parse --abbrev-ref HEAD')
.then((branch) => exec(`git rev-list --left-right --count master...${branch}`))
.then((count) => count.split(/\s+/)[1])
.then((commits) => read({to: 'HEAD', from: `HEAD~${commits}`}))
.then((commits) => Promise.all([commits, load({ extends: ['@commitlint/config-conventional'] })]))
.then(([commits, opts]) => Promise.all(commits.map((commit) => lint(
commit,
opts.rules,
opts.parserPreset ? {parserOpts: opts.parserPreset.parserOpts} : {}
))))
.then(results => results.filter((r) => !r.valid))
.then(invalid => {
if (invalid.length) {
console.log(util.inspect(invalid, false, null))
return 1
} else {
return 0
}
})
.then(process.exit)
function lint () {
return exec('git rev-parse --abbrev-ref HEAD')
.then((branch) => exec(`git rev-list --left-right --count master...${branch}`))
.then((count) => count.split(/\s+/)[1])
.then((commits) => read({to: 'HEAD', from: `HEAD~${commits}`}))
.then((commits) => Promise.all([commits, load({ extends: ['@commitlint/config-conventional'] })]))
.then(([commits, opts]) => Promise.all(commits.map((commit) => lint(
commit,
opts.rules,
opts.parserPreset ? {parserOpts: opts.parserPreset.parserOpts} : {}
))))
.then(results => results.filter((r) => !r.valid))
.then(invalid => {
if (invalid.length) {
console.log(util.inspect(invalid, false, null))
return 1
} else {
return 0
}
})
.then(process.exit)
.catch((error) => {
console.log(error)
process.exit(1)
})
}

exec('git rev-parse --verify master')
.then(lint)
.catch(() => exec('git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*'))
.then(() => exec('git fetch'))
.then(lint)
.catch((error) => {
console.log(error)
process.exit(1)
})

0 comments on commit 2e461d6

Please sign in to comment.