Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

commit-hash

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commit-hash - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

16

cli.js
#!/usr/bin/env node
var commitHash = require('./index.js');
var argv = require('minimist')(process.argv.slice(2)),
commitHash = require('./index.js');
var args = process.argv;
args.shift();
args.shift();
args.forEach(function(arg) {
argv._.forEach(function(arg) {
commitHash(arg, function(err, commitHash) {

@@ -17,4 +13,8 @@ if (err) {

console.log((commitHash|| ' ')+' -> '+arg);
if (argv.verbose) {
console.log((commitHash|| ' ')+' -> '+arg);
} else {
console.log(commitHash);
}
});
});

@@ -30,3 +30,3 @@ var spawn = require('child_process').spawn,

module.exports = function(commitRef, opts, next) {
function getCommitHash(commitRef, opts, next) {

@@ -171,5 +171,65 @@ function findLocalCommitHash(commitRef, next) {

});
};
}
function getCommitInfo(commitRef, opts, next) {
if (isFunction(opts)) {
next = opts;
opts = {};
}
opts = opts || {};
opts.dir = value(opts.dir, null);
opts.bin = value(opts.bin, 'git');
// if a custom directory was provided, chdir to it before starting
if (opts.dir) {
process.chdir(opts.dir);
}
getCommitHash(commitRef, function(err, commitHash) {
if (err) return next(err);
if (!commitHash) {
return next(null, null);
}
async.parallel({
author: function(next) {
var authorInfo = '';
spawn(opts.bin, ['log', '--format=%ad::%an::%ae', '-n', '1', commitHash])
.on('close', function(code) {
var match = /(.+)::(.+)::(.+)/.exec(authorInfo);
next(null, {
date: match[1],
name: match[2],
email: match[3]
});
})
.stdout.on('data', function(data) {
authorInfo = data.toString();
});
},
message: function(next) {
var message = '';
spawn(opts.bin, ['log', '--format=%B', '-n', '1', commitHash])
.on('close', function(code) {
next(null, message);
})
.stdout.on('data', function(data) {
message += data.toString();
});
}
}, function(err, result) {
if (err) return next(err);
result.hash = commitHash;
next(null, result);
})
});
}
module.exports = getCommitHash;
module.exports.commitInfo = getCommitInfo;
module.exports.fetchAll = fetchAll;
{
"name": "commit-hash",
"version": "0.1.2",
"version": "0.1.3",
"description": "Get commit hash from a branch name, tag, or reference",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/dgoguerra/commit-hash#readme",

@@ -55,2 +55,24 @@ var tape = require('tape'),

});
tape('get commit message and author', function(t) {
commitHash.commitInfo('21f6ba4e644e77d6e20eaa5156a928b6d75fdf76', function(err, info) {
t.deepEquals(info, {
hash: '21f6ba4e644e77d6e20eaa5156a928b6d75fdf76',
message: 'initial empty commit\n\n',
author: {
date: 'Wed Jul 13 10:08:56 2016 +0200',
name: 'Diego Guerra',
email: 'dgoguerra.or@gmail.com'
}
});
t.end();
});
});
tape('unknown commit returns null as commit info', function(t) {
commitHash.commitInfo('unknown', function(err, info) {
t.deepEquals(info, null);
t.end();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc