Skip to content

Commit

Permalink
feat: add a --no-verify option to prevent git hooks from being verifi…
Browse files Browse the repository at this point in the history
…ed (#44)

* feature(commit): Add --no-verify option to prevent githooks from being verified during commit

* docs: add explanation of --no-verify to readme

* docs: add explanation of --no-verify to readme

* fix(commit): Handle -n alias for --no-verify appropriately
  • Loading branch information
noahrc authored and bcoe committed Jun 2, 2016
1 parent 178e001 commit 026d844
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ As long as your git commit messages are conventional and accurate, you no longer

After you cut a release, you can push the new git tag and `npm publish` (or `npm publish --tag next`) when you're ready.

### Prevent Git Hooks

If you use git hooks, like pre-commit, to test your code before committing, you can prevent hooks from being verified during the commit step by passing the `--no-verify` option:

```sh
# npm run script
npm run release -- --no-verify
# or global bin
standard-version --no-verify
```

### CLI Help

```sh
Expand Down
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ var argv = require('yargs')
default: false,
global: true
})
.option('no-verify', {
alias: 'n',
describe: 'Bypass pre-commit or commit-msg git hooks during the commit phase',
type: 'boolean',
default: false,
global: true
})
.help()
.alias('help', 'h')
.example('$0', 'Update changelog and tag release')
Expand Down Expand Up @@ -108,12 +115,13 @@ function outputChangelog (argv, cb) {
function commit (argv, newVersion, cb) {
var msg = 'committing %s'
var args = [argv.infile]
var verify = argv.verify === false || argv.n ? '--no-verify ' : ''
if (!argv.firstRelease) {
msg += ' and %s'
args.unshift('package.json')
}
checkpoint(msg, args)
exec('git add package.json ' + argv.infile + ';git commit ' + (argv.sign ? '-S ' : '') + 'package.json ' + argv.infile + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) {
exec('git add package.json ' + argv.infile + ';git commit ' + verify + (argv.sign ? '-S ' : '') + 'package.json ' + argv.infile + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) {
var errMessage = null
if (err) errMessage = err.message
if (stderr) errMessage = stderr
Expand Down
15 changes: 15 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ function writePackageJson (version) {
}), 'utf-8')
}

function writeGitPreCommitHook () {
fs.writeFileSync('.git/hooks/pre-commit', '#!/bin/sh\necho "precommit ran"\nexit 1', 'utf-8')
fs.chmodSync('.git/hooks/pre-commit', '755')
}

describe('cli', function () {
beforeEach(function () {
shell.rm('-rf', 'tmp')
Expand Down Expand Up @@ -164,4 +169,14 @@ describe('cli', function () {
var pkgJson = fs.readFileSync('package.json', 'utf-8')
pkgJson.should.equal(['{', ' "version": "1.0.1"', '}', ''].join('\n'))
})

it('does not run git hooks if the --no-verify flag is passed', function () {
writePackageJson('1.0.0')
writeGitPreCommitHook()

commit('feat: first commit')
shell.exec(cliPath + ' --no-verify').code.should.equal(0)
commit('feat: second commit')
shell.exec(cliPath + ' -n').code.should.equal(0)
})
})

0 comments on commit 026d844

Please sign in to comment.