Skip to content

Commit

Permalink
feat: add --sign flag to sign git commit and tag
Browse files Browse the repository at this point in the history
  • Loading branch information
nexdrew committed May 1, 2016
1 parent 253eeca commit de84720
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 '
Expand Down
14 changes: 14 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit de84720

Please sign in to comment.