Permalink
Browse files

Allow getCommit to be called without a revision.

In this case, it returns the most recent commit for any branch.
  • Loading branch information...
mbostock committed Feb 21, 2014
1 parent 00f2c84 commit 9e837a8e911aaf3dd7090f04a32a91ee164deaa6
Showing with 4 additions and 3 deletions.
  1. +3 −2 index.js
  2. +1 −1 package.json
View
@@ -42,12 +42,13 @@ exports.getSha = function(repository, revision, callback) {
};
exports.getCommit = function(repository, revision, callback) {
- child.exec("git log -1 --format=\"format:%H%n%ad\" '" + revision.replace(/'/g, "'\''") + "'", {cwd: repository}, function(error, stdout) {
+ if (arguments.length < 3) callback = revision, revision = null;
+ child.exec("git for-each-ref --count 1 --sort=-committerdate 'refs/heads/" + (revision ? revision.replace(/'/g, "'\''") : "") + "' --format='%(objectname)\n%(authordate:iso8601)'", {cwd: repository}, function(error, stdout) {
if (error) return callback(error);
var lines = stdout.split("\n");
callback(null, {
sha: lines[0],
- date: new Date(Date.parse(lines[1]))
+ date: new Date(lines[1])
});
});
};
View
@@ -1,6 +1,6 @@
{
"name": "git-static",
- "version": "0.0.11",
+ "version": "0.0.12",
"author": {
"name": "Mike Bostock",
"url": "http://bost.ocks.org/mike"

0 comments on commit 9e837a8

Please sign in to comment.