Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ var _parent = Commit.prototype.parent;
*/
Commit.lookup = LookupWrapper(Commit);

/**
* @async
* @param {Number} n
* @return {Commit}
*/
Commit.prototype.parent = function(n, callback) {
var repo = this.repo;
return _parent.call(this, n).then(p => {
p.repo = repo;

if (typeof callback === "function") {
callback(null, p);
}

return p;
}, callback);
};

/**
* Amend a commit
* @async
Expand Down
10 changes: 10 additions & 0 deletions test/tests/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,16 @@ describe("Commit", function() {
assert.equal(1, this.commit.parentcount());
});

it("can fetch a single parent", function() {
return this.commit.parent(0).then(function(parent) {
assert.strictEqual(parent.sha(),
"ecfd36c80a3e9081f200dfda2391acadb56dac27");
// This used to crash due to a missing .repo property on the retrieved
// parent.
return parent.getTree().then(tree => assert(tree));
});
});

it("can retrieve and walk a commit tree", function() {
var commitTreeEntryCount = 0;
var expectedCommitTreeEntryCount = 198;
Expand Down