Skip to content

blew up parser to handle special characters in the subject #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
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, { cwd: __dirname, maxBuffer: 1024 * 1024 }, function (err, stdout, stderr) {
if (err !== null) {
console.log('[NODE-GIT-REV] exec error: ' + err);
cb(null);
}
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, 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);
});
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "git-rev",
"version" : "0.2.1",
"version" : "0.2.3",
"description" : "get the current git commit hash, tag or branch in node",
"main" : "index.js",
"bin" : {},
Expand Down