Skip to content

Commit 026d844

Browse files
noahrcbcoe
authored andcommitted
feat: add a --no-verify option to prevent git hooks from being verified (#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
1 parent 178e001 commit 026d844

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ As long as your git commit messages are conventional and accurate, you no longer
9494

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

97+
### Prevent Git Hooks
98+
99+
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:
100+
101+
```sh
102+
# npm run script
103+
npm run release -- --no-verify
104+
# or global bin
105+
standard-version --no-verify
106+
```
107+
97108
### CLI Help
98109

99110
```sh

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ var argv = require('yargs')
3131
default: false,
3232
global: true
3333
})
34+
.option('no-verify', {
35+
alias: 'n',
36+
describe: 'Bypass pre-commit or commit-msg git hooks during the commit phase',
37+
type: 'boolean',
38+
default: false,
39+
global: true
40+
})
3441
.help()
3542
.alias('help', 'h')
3643
.example('$0', 'Update changelog and tag release')
@@ -108,12 +115,13 @@ function outputChangelog (argv, cb) {
108115
function commit (argv, newVersion, cb) {
109116
var msg = 'committing %s'
110117
var args = [argv.infile]
118+
var verify = argv.verify === false || argv.n ? '--no-verify ' : ''
111119
if (!argv.firstRelease) {
112120
msg += ' and %s'
113121
args.unshift('package.json')
114122
}
115123
checkpoint(msg, args)
116-
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) {
124+
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) {
117125
var errMessage = null
118126
if (err) errMessage = err.message
119127
if (stderr) errMessage = stderr

test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ function writePackageJson (version) {
2020
}), 'utf-8')
2121
}
2222

23+
function writeGitPreCommitHook () {
24+
fs.writeFileSync('.git/hooks/pre-commit', '#!/bin/sh\necho "precommit ran"\nexit 1', 'utf-8')
25+
fs.chmodSync('.git/hooks/pre-commit', '755')
26+
}
27+
2328
describe('cli', function () {
2429
beforeEach(function () {
2530
shell.rm('-rf', 'tmp')
@@ -164,4 +169,14 @@ describe('cli', function () {
164169
var pkgJson = fs.readFileSync('package.json', 'utf-8')
165170
pkgJson.should.equal(['{', ' "version": "1.0.1"', '}', ''].join('\n'))
166171
})
172+
173+
it('does not run git hooks if the --no-verify flag is passed', function () {
174+
writePackageJson('1.0.0')
175+
writeGitPreCommitHook()
176+
177+
commit('feat: first commit')
178+
shell.exec(cliPath + ' --no-verify').code.should.equal(0)
179+
commit('feat: second commit')
180+
shell.exec(cliPath + ' -n').code.should.equal(0)
181+
})
167182
})

0 commit comments

Comments
 (0)