Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a --no-verify option to prevent git hooks from being verified #44

Merged
merged 4 commits into from
Jun 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, nice work!


```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)
})
})