Skip to content

Commit

Permalink
Added getCommit function that gets the last commit, and added a test …
Browse files Browse the repository at this point in the history
…to see if my version regex works properly
  • Loading branch information
larzconwell committed Jun 27, 2012
1 parent d27cd02 commit 050a427
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions lib/auto_npm.js
Expand Up @@ -6,7 +6,8 @@ var fs = require('fs')
// //
// Vars // Vars
var cd = process.cwd() var cd = process.cwd()
, hookDir = path.join(cd, '.git', 'hooks') , gitDir = path.join(cd, '.git')
, hookDir = path.join(gitDir, 'hooks')
, hookFile = path.join(hookDir, 'post-commit') , hookFile = path.join(hookDir, 'post-commit')
, hookContent; , hookContent;


Expand Down Expand Up @@ -38,14 +39,27 @@ exports.deleteHook = function() {
}); });
}; };


//
// Returns the commit information from the last commit
exports.getCommit = function(callback) {
var exec = require('child_process').exec
, cmd = 'git --git-dir=' + gitDir + ' log -p -1';

exec(cmd, function(err, stdout, stderr) {
if(err) callback && callback(err);

callback && callback(undefined, stdout);
});
};

// //
// Install the hook file // Install the hook file
exports.enable = function(options) { exports.enable = function(options) {
options = options || {}; options = options || {};


// Throw error if no .git directory is present // Throw error if no .git directory is present
var gitDir = path.existsSync(path.join(cd, '.git')); var gitDirExists = path.existsSync(gitDir);
if(!gitDir) throw new Error('The Directory "' + cd + '" is not a git repo.'); if(!gitDirExists) throw new Error('The Directory "' + cd + '" is not a git repo.');


// If hooks directory can't be found, create it // If hooks directory can't be found, create it
if(!path.existsSync(hookDir)) fs.mkdirSync(hookDir); if(!path.existsSync(hookDir)) fs.mkdirSync(hookDir);
Expand Down Expand Up @@ -105,5 +119,9 @@ exports.disable = function(options) {
// //
// Updated NPM packages // Updated NPM packages
exports.update = function() { exports.update = function() {
console.log('Test'); exports.getCommit(function(err, data) {
if(err) throw err;

console.log(!!data.match(/"version*":\s"([0-9].|[0-9])*"/));
});
}; };
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -9,7 +9,7 @@
, "version" , "version"
, "control" , "control"
] ]
, "version": "0.0.1" , "version": "0.0.2"
, "author": "Larz Conwell <larzconwell@gmail.com>" , "author": "Larz Conwell <larzconwell@gmail.com>"
, "bin": { , "bin": {
"auto-npm": "./bin/auto_npm.js" "auto-npm": "./bin/auto_npm.js"
Expand Down

0 comments on commit 050a427

Please sign in to comment.