Skip to content

Commit

Permalink
add commit hash check
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Rodriguez committed Sep 13, 2012
1 parent 20ebab6 commit e099b45
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
18 changes: 13 additions & 5 deletions index.js
Expand Up @@ -2,6 +2,7 @@ var npm = require('npm')
, sha1 = require('./lib/sha1')
, readJson = require('read-package-json')
, path = require('path')
, commithash = require('./lib/commit-hash')

function list (str) {
return str.split(/ *, */).map(function (val) {
Expand Down Expand Up @@ -52,14 +53,21 @@ program
var name = data.name
, version = data.version

npm.load(function (err) {
commithash(program.root, function (err, commit) {
ifErr(err);
npm.commands.cache(['add', program.root], function (err) {
npm.load(function (err) {
ifErr(err);
var file = path.join(npm.cache, name, version, 'package.tgz');
sha1.get(file, function (err, sha1sum) {
npm.commands.cache(['add', program.root], function (err) {
ifErr(err);
console.log('cached project with sha1 sum: ' + sha1sum);
var file = path.join(npm.cache, name, version, 'package.tgz');
sha1.get(file, function (err, sha1sum) {
ifErr(err);
console.log('deployed project at ' + program.root);
console.log('sha1 sum: ' + sha1sum);
if (commit) {
console.log('git hash: ' + commit);
}
});
});
});
});
Expand Down
13 changes: 13 additions & 0 deletions lib/commit-hash.js
@@ -0,0 +1,13 @@
var fs = require('fs')
, path = require('path')
, exec = require('child_process').exec

module.exports = function (dir, cb) {
fs.exists(path.join(dir, '.git'), function (exists) {
if (!exists) return cb();
exec('git log -n1 --pretty=oneline', {cwd: dir}, function (err, stdout, stderr) {
if (err) return cb(err);
cb(null, stdout.split(/\s+/)[0]);
});
});
};

0 comments on commit e099b45

Please sign in to comment.