Browse files

Added getCommit function that gets the last commit, and added a test …

…to see if my version regex works properly
  • Loading branch information...
1 parent d27cd02 commit 050a42714543c59fb4a81a03ff3271d71717b2dd @larzconwell committed Jun 26, 2012
Showing with 23 additions and 5 deletions.
  1. +22 −4 lib/auto_npm.js
  2. +1 −1 package.json
View
26 lib/auto_npm.js
@@ -6,7 +6,8 @@ var fs = require('fs')
//
// Vars
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')
, hookContent;
@@ -39,13 +40,26 @@ 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
exports.enable = function(options) {
options = options || {};
// Throw error if no .git directory is present
- var gitDir = path.existsSync(path.join(cd, '.git'));
- if(!gitDir) throw new Error('The Directory "' + cd + '" is not a git repo.');
+ var gitDirExists = path.existsSync(gitDir);
+ if(!gitDirExists) throw new Error('The Directory "' + cd + '" is not a git repo.');
// If hooks directory can't be found, create it
if(!path.existsSync(hookDir)) fs.mkdirSync(hookDir);
@@ -105,5 +119,9 @@ exports.disable = function(options) {
//
// Updated NPM packages
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])*"/));
+ });
};
View
2 package.json
@@ -9,7 +9,7 @@
, "version"
, "control"
]
- , "version": "0.0.1"
+ , "version": "0.0.2"
, "author": "Larz Conwell <larzconwell@gmail.com>"
, "bin": {
"auto-npm": "./bin/auto_npm.js"

0 comments on commit 050a427

Please sign in to comment.