diff --git a/README.md b/README.md index 03f24c9..23ebb93 100755 --- a/README.md +++ b/README.md @@ -27,6 +27,11 @@ git.tag(function (str) { // => 0.1.0 }) +git.message(function (str) { + console.log('message', str) + // => initial commit +}) + ``` # Methods @@ -68,6 +73,9 @@ return the current tag ## .branch(function (branch) { ... }) return the current branch +## .message(function (message) { ... }) +return the current commit message + # Install `npm install git-rev` diff --git a/example/simple.js b/example/simple.js index 2a69875..b9c98ac 100755 --- a/example/simple.js +++ b/example/simple.js @@ -35,3 +35,11 @@ git.log(function (array) { // '2 days ago', // 'Thomas Blobaum' ] ] }) + +git.message(function (str) { + console.log('message', str) + // => Merge pull request #6 from shtylman/patch-1 + // + // fix for launching outside of project dir + // +}) diff --git a/index.js b/index.js index fc3d578..cd5bb84 100755 --- a/index.js +++ b/index.js @@ -1,8 +1,9 @@ var exec = require('child_process').exec -function _command (cmd, cb) { +function _command (cmd, cb, cnl) { + cnl = cnl === undefined ? true : cnl; exec(cmd, { cwd: __dirname }, function (err, stdout, stderr) { - cb(stdout.split('\n').join('')) + cb(cnl ? stdout.split('\n').join('') : stdout) }) } @@ -25,4 +26,7 @@ module.exports = { cb(JSON.parse('[' + str + ']')) }) } + , message : function (cb) { + _command('git log -1 --pretty=%B', cb, false) + } }