Skip to content

Instantly share code, notes, and snippets.

@aaronpowell
Created November 13, 2013 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aaronpowell/7442765 to your computer and use it in GitHub Desktop.
Save aaronpowell/7442765 to your computer and use it in GitHub Desktop.
Single-level tree walker for js-git
//assumes that the hash you want and the repo are obtainable via closure scope
function findPrevious(commit, previousCommit) {
repo.load(commit.parents[0], function (err, obj) {
if (obj.type !== 'commit') {
console.error(obj);
throw 'Unexpected type returned';
}
repo.load(obj.body.tree, function (err, tree) {
if (tree.type !== 'tree') {
console.error(tree);
throw 'Object is not a tree';
}
var match = tree.body.filter(function (obj) { return obj.hash == hash; });
if (match.length) {
console.dir(match);
findPrevious(obj.body, commit);
} else {
console.log('we have a winner!');
console.dir(obj);
}
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment