Skip to content

Commit

Permalink
Merge pull request #1509 from tniessen/fix-commit-parent-no-repo-prop
Browse files Browse the repository at this point in the history
Fix behavior of Commit#parent
  • Loading branch information
implausible committed Jan 21, 2020
2 parents 06489c7 + e3bb744 commit cf10bce
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/commit.js
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
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

0 comments on commit cf10bce

Please sign in to comment.