diff --git a/index.js b/index.js index 3cc9fca94..8ab7c5a34 100755 --- a/index.js +++ b/index.js @@ -24,9 +24,9 @@ var argv = require('yargs') default: false, global: true }) - .option('sign-tag', { + .option('sign', { alias: 's', - describe: 'Should the git tag be signed?', + describe: 'Should the git commit and tag be signed?', type: 'boolean', default: false, global: true @@ -113,7 +113,7 @@ function commit (argv, newVersion, cb) { args.unshift('package.json') } checkpoint(msg, args) - exec('git add package.json ' + argv.infile + ';git commit package.json ' + argv.infile + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) { + 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) { var errMessage = null if (err) errMessage = err.message if (stderr) errMessage = stderr @@ -131,7 +131,7 @@ function formatCommitMessage (msg, newVersion) { function tag (newVersion, argv) { var tagOption - if (argv.signTag) { + if (argv.sign) { tagOption = '-s ' } else { tagOption = '-a ' diff --git a/test.js b/test.js index 672c197aa..a801441de 100644 --- a/test.js +++ b/test.js @@ -79,6 +79,20 @@ describe('cli', function () { }) }) + it('respects the --sign option', function () { + fs.writeFileSync('package.json', JSON.stringify({ + version: '1.0.0' + }), 'utf-8') + + commit('feat: first commit') + + // this should fail without a GPG key + var result = shell.exec(cliPath + ' --sign') + result.code.should.equal(1) + result.stdout.should.match(/gpg\: signing failed\: secret key not available/) + result.stdout.should.match(/error\: gpg failed to sign the data/) + }) + it('handles commit messages longer than 80 characters', function () { fs.writeFileSync('package.json', JSON.stringify({ version: '1.0.0'