From 3072804a006d310e7aae104e08a8135c49afd6f6 Mon Sep 17 00:00:00 2001 From: isaacs Date: Thu, 12 Jul 2012 08:27:08 -0700 Subject: [PATCH] Add sign-git-tag config for 'npm version' command --- doc/cli/config.md | 11 +++++++++++ lib/utils/config-defs.js | 2 ++ lib/version.js | 8 ++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/doc/cli/config.md b/doc/cli/config.md index 537af5ca0ea..7bd46cd43a7 100644 --- a/doc/cli/config.md +++ b/doc/cli/config.md @@ -694,6 +694,17 @@ character to indicate reverse sort. The shell to run for the `npm explore` command. +### sign-git-tag + +* Default: false +* Type: Boolean + +If set to true, then the `npm version` command will tag the version +using `-s` to add a signature. + +Note that git requires you to have set up GPG keys in your git configs +for this to work properly. + ### strict-ssl * Default: true diff --git a/lib/utils/config-defs.js b/lib/utils/config-defs.js index ee2c22f101f..4237ae6bafe 100644 --- a/lib/utils/config-defs.js +++ b/lib/utils/config-defs.js @@ -189,6 +189,7 @@ Object.defineProperty(exports, "defaults", {get: function () { , searchexclude: null , searchsort: "name" , shell : osenv.shell() + , "sign-git-tag": false , "strict-ssl": true , tag : "latest" , tmp : temp @@ -280,6 +281,7 @@ exports.types = , "date", "-date" , "keywords", "-keywords" ] , shell : String + , "sign-git-tag": Boolean , "strict-ssl": Boolean , tag : String , tmp : path diff --git a/lib/version.js b/lib/version.js index d1a6b563ede..67a4b4ce9a7 100644 --- a/lib/version.js +++ b/lib/version.js @@ -10,7 +10,7 @@ var exec = require("./utils/exec.js") , log = require("npmlog") , npm = require("./npm.js") -version.usage = "npm version [--message commit-message]" +version.usage = "npm version [ | major | minor | patch | build]\n" + "\n(run in package dir)\n" + "'npm -v' or 'npm --version' to print npm version " + "("+npm.version+")\n" @@ -52,19 +52,23 @@ function checkGit (data, cb) { , function (er, code, stdout, stderr) { var lines = stdout.trim().split("\n").filter(function (line) { return line.trim() && !line.match(/^\?\? /) + }).map(function (line) { + return line.trim() }) if (lines.length) return cb(new Error( "Git working directory not clean.\n"+lines.join("\n"))) write(data, function (er) { if (er) return cb(er) var message = npm.config.get("message").replace(/%s/g, data.version) + , sign = npm.config.get("sign-git-tag") + , flag = sign ? "-sm" : "-am" chain ( [ [ exec, npm.config.get("git") , ["add","package.json"], process.env, false ] , [ exec, npm.config.get("git") , ["commit", "-m", message ], process.env, false ] , [ exec, npm.config.get("git") - , ["tag", "v"+data.version], process.env, false ] ] + , ["tag", "v"+data.version, flag, message], process.env, false ] ] , cb ) }) })