From 85c3ff5aab4e4d64b850339377f718e98df26e93 Mon Sep 17 00:00:00 2001 From: Roman Jurkov Date: Fri, 10 Jul 2015 14:07:40 -0400 Subject: [PATCH 1/7] moved subject line to the end, added separators between fields, preserved previous order after formatter was changed --- index.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index fc3d578..5ba139d 100755 --- a/index.js +++ b/index.js @@ -1,28 +1,37 @@ var exec = require('child_process').exec function _command (cmd, cb) { - exec(cmd, { cwd: __dirname }, function (err, stdout, stderr) { - cb(stdout.split('\n').join('')) + exec(cmd, function (err, stdout, stderr) { + cb(stdout.slice(0, -1)); }) } -module.exports = { - short : function (cb) { +module.exports = { + short : function (cb) { _command('git rev-parse --short HEAD', cb) } - , long : function (cb) { + , long : function (cb) { _command('git rev-parse HEAD', cb) } - , branch : function (cb) { + , branch : function (cb) { _command('git rev-parse --abbrev-ref HEAD', cb) } - , tag : function (cb) { + , tag : function (cb) { _command('git describe --always --tag --abbrev=0', cb) } - , log : function (cb) { - _command('git log --no-color --pretty=format:\'[ "%H", "%s", "%cr", "%an" ],\' --abbrev-commit', function (str) { - str = str.substr(0, str.length-1) - cb(JSON.parse('[' + str + ']')) + , log : function (cb) { + _command('git log --no-color --pretty=format:\'%H | %cr | %an | %s\' --abbrev-commit', function (str) { + var logs = []; + (str.split('\n')).forEach(function(line, line_idx) { + var parsed_line = line.split(' | '); + logs.push([ + parsed_line[0], + parsed_line[3], + parsed_line[1], + parsed_line[2] + ]); + }); + cb(logs) }) } } From 06c2d55aabeb4ffa8b9abd4c3440a8ca2bfa00ab Mon Sep 17 00:00:00 2001 From: Roman Jurkov Date: Fri, 10 Jul 2015 14:11:54 -0400 Subject: [PATCH 2/7] bumped package.json version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 386cba6..5199d04 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "git-rev", - "version" : "0.2.1", + "version" : "0.2.2", "description" : "get the current git commit hash, tag or branch in node", "main" : "index.js", "bin" : {}, From 05d51d0dc9d83bf6d3138a5081d8fc669d15f593 Mon Sep 17 00:00:00 2001 From: Roman Jurkov Date: Fri, 10 Jul 2015 14:15:03 -0400 Subject: [PATCH 3/7] added back stumped change --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 5ba139d..cad95ef 100755 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ var exec = require('child_process').exec function _command (cmd, cb) { - exec(cmd, function (err, stdout, stderr) { + exec(cmd, { cwd: __dirname }, function (err, stdout, stderr) { cb(stdout.slice(0, -1)); }) } From 8e0ce0e8515131ad6fbf477e9b3b8751d2943052 Mon Sep 17 00:00:00 2001 From: Roman Jurkov Date: Fri, 10 Jul 2015 14:28:36 -0400 Subject: [PATCH 4/7] added error check in exec --- index.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index cad95ef..2db004b 100755 --- a/index.js +++ b/index.js @@ -2,6 +2,10 @@ var exec = require('child_process').exec function _command (cmd, cb) { exec(cmd, { cwd: __dirname }, function (err, stdout, stderr) { + if (err !== null) { + console.log('[NODE-GIT-REV] exec error: ' + err); + cb(null); + } cb(stdout.slice(0, -1)); }) } @@ -21,17 +25,19 @@ module.exports = { } , log : function (cb) { _command('git log --no-color --pretty=format:\'%H | %cr | %an | %s\' --abbrev-commit', function (str) { - var logs = []; - (str.split('\n')).forEach(function(line, line_idx) { - var parsed_line = line.split(' | '); - logs.push([ - parsed_line[0], - parsed_line[3], - parsed_line[1], - parsed_line[2] - ]); - }); - cb(logs) - }) - } + var logs = []; + if ( str !== null ) { + (str.split('\n')).forEach(function(line, line_idx) { + var parsed_line = line.split(' | '); + logs.push([ + parsed_line[0], + parsed_line[3], + parsed_line[1], + parsed_line[2] + ]); + }); + }; + cb(logs); + }); + } } From 0ce58a4479330cd246aebe7bbd277c920018224c Mon Sep 17 00:00:00 2001 From: Roman Jurkov Date: Fri, 10 Jul 2015 14:47:07 -0400 Subject: [PATCH 5/7] added max buffer option --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 2db004b..d7d9899 100755 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ var exec = require('child_process').exec function _command (cmd, cb) { - exec(cmd, { cwd: __dirname }, function (err, stdout, stderr) { + exec(cmd, { cwd: __dirname, maxBuffer: 1024 * 1024 }, function (err, stdout, stderr) { if (err !== null) { console.log('[NODE-GIT-REV] exec error: ' + err); cb(null); From dc8a3bf2e7408f2b109680affdce2687154e3af5 Mon Sep 17 00:00:00 2001 From: Roman Jurkov Date: Fri, 10 Jul 2015 14:47:49 -0400 Subject: [PATCH 6/7] bumped version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5199d04..ef3a07e 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "git-rev", - "version" : "0.2.2", + "version" : "0.2.3", "description" : "get the current git commit hash, tag or branch in node", "main" : "index.js", "bin" : {}, From 7f0439b4f66c0cf2fd899ece0a036e63211c811f Mon Sep 17 00:00:00 2001 From: Roman Jurkov Date: Sat, 5 Dec 2015 08:56:16 -0500 Subject: [PATCH 7/7] incorporated changes by @xoorath --- index.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index d7d9899..f3d9090 100755 --- a/index.js +++ b/index.js @@ -23,21 +23,25 @@ module.exports = { , tag : function (cb) { _command('git describe --always --tag --abbrev=0', cb) } - , log : function (cb) { - _command('git log --no-color --pretty=format:\'%H | %cr | %an | %s\' --abbrev-commit', function (str) { - var logs = []; - if ( str !== null ) { - (str.split('\n')).forEach(function(line, line_idx) { - var parsed_line = line.split(' | '); - logs.push([ - parsed_line[0], - parsed_line[3], - parsed_line[1], - parsed_line[2] - ]); - }); - }; - cb(logs); + , log : function (cb, limit) { + var cmd_string = 'git log --no-color --pretty=format:\"%H | %cr | %an | %s\" --abbrev-commit'; + if(limit != null && !isNaN(limit)) { + cmd_string += ' -'+limit; + } + _command(cmd_string, function (str) { + var logs = []; + if ( str !== null ) { + (str.split('\n')).forEach(function(line, line_idx) { + var parsed_line = line.split(' | '); + logs.push([ + parsed_line[0], + parsed_line[3], + parsed_line[1], + parsed_line[2] + ]); + }); + }; + cb(logs); }); } }