simple-git
Advanced tools
Comparing version 0.0.2 to 0.1.0
{ | ||
"name": "simple-git", | ||
"description": "Simple GIT interface for node.js", | ||
"version": "0.0.2", | ||
"author": "Steve King <steve@mydev.co>", | ||
"contributors": [ | ||
{ | ||
"name": "Steve King", | ||
"email": "steve@mydev.co" | ||
} | ||
], | ||
"dependencies": { | ||
}, | ||
"devDependencies": { | ||
"grunt-release-steps": "~0.3.7", | ||
"grunt": "~0.4.1" | ||
}, | ||
"keywords": [ | ||
"git", | ||
"source control", | ||
"vcs" | ||
], | ||
"repository": "git://github.com/steveukx/git-js.git", | ||
"main": "src/git.js", | ||
"bin": {}, | ||
"scripts": {}, | ||
"config": {}, | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
} | ||
"name": "simple-git", | ||
"description": "Simple GIT interface for node.js", | ||
"version": "0.1.0", | ||
"author": "Steve King <steve@mydev.co>", | ||
"contributors": [ | ||
{ | ||
"name": "Steve King", | ||
"email": "steve@mydev.co" | ||
} | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"grunt-release-steps": "~0.3.7", | ||
"grunt": "~0.4.1" | ||
}, | ||
"keywords": [ | ||
"git", | ||
"source control", | ||
"vcs" | ||
], | ||
"repository": "git://github.com/steveukx/git-js.git", | ||
"main": "src/git.js", | ||
"bin": {}, | ||
"scripts": {}, | ||
"config": {}, | ||
"engines": { | ||
"node": ">= 0.10.0" | ||
} | ||
} |
@@ -24,3 +24,3 @@ # Simple Git | ||
be called when that step has been completed. When it is called it has two arguments - firstly an error object (or null | ||
when no error ocurred) and secondly the data generated by that call. | ||
when no error occurred) and secondly the data generated by that call. | ||
@@ -35,3 +35,8 @@ `.pull(handlerFn)` pull all updates from the repo | ||
`.add([fileA, ...], handlerFn)` adds one or more files to be under source control | ||
`.commit(message, handlerFn)` commits changes in the current working directory with the supplied message | ||
`.commit(message, [fileA, ...], handlerFn)` commits changes on the named files with the supplied message | ||
# Examples | ||
@@ -38,0 +43,0 @@ |
@@ -28,2 +28,36 @@ (function() { | ||
/** | ||
* Adds one or more files to source control | ||
* | ||
* @param {String|String[]} files | ||
* @param {Function} [then] | ||
*/ | ||
Git.prototype.add = function(files, then) { | ||
return this._run('git add "' + [].concat(files).join('" "') + '"', function(err, data) { | ||
then && then(err); | ||
}); | ||
}; | ||
/** | ||
* Commits changes in the current working directory - when specific file paths are supplied, only changes on those | ||
* files will be committed. | ||
* | ||
* @param {String} message | ||
* @param {String|String[]} files | ||
* @param {Function} [then] | ||
*/ | ||
Git.prototype.commit = function(message, files, then) { | ||
var git = this; | ||
if(!then && typeof files === "function") { | ||
then = files; | ||
files = []; | ||
} | ||
files = files ? ' "' + [].concat(files).join('" "') + '"' : ''; | ||
return this._run('git commit -m "' + message.replace(/"/g, '\\"') + '"' + files, function(err, data) { | ||
then && then(err, git._parseCommit(data)); | ||
}); | ||
}; | ||
/** | ||
* Pull the updated contents of the current repo | ||
@@ -120,2 +154,19 @@ * @param {Function} [then] | ||
Git.prototype._parseCommit = function(commit) { | ||
var lines = commit.trim().split('\n'); | ||
var branch = /\[([^\s]+) ([^\]]+)/.exec(lines.shift()); | ||
var summary = /(\d+)[^\d]+(\d+)[^\d]+(\d+)/.exec(lines.pop()); | ||
return { | ||
branch: branch[1], | ||
commit: branch[2], | ||
summary: { | ||
changes: summary[1], | ||
insertions: summary[2], | ||
deletions: summary[3] | ||
} | ||
}; | ||
}; | ||
Git.prototype._parseCheckout = function(checkout) { | ||
@@ -122,0 +173,0 @@ // TODO |
9306
5
201
57