Skip to content

Commit e3bb744

Browse files
committed
Fix behavior of Commit#parent
Commit#parent did not assign the repo property so subsequent calls which relied on this property (such as Commit#getTree) failed. This change works around this problem by imitating what LookupWrapper does for Commit.lookup, that is, it wraps the actual call in a new function and manually assigns the repo property.
1 parent 8ad3e37 commit e3bb744

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/commit.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ var _parent = Commit.prototype.parent;
1616
*/
1717
Commit.lookup = LookupWrapper(Commit);
1818

19+
/**
20+
* @async
21+
* @param {Number} n
22+
* @return {Commit}
23+
*/
24+
Commit.prototype.parent = function(n, callback) {
25+
var repo = this.repo;
26+
return _parent.call(this, n).then(p => {
27+
p.repo = repo;
28+
29+
if (typeof callback === "function") {
30+
callback(null, p);
31+
}
32+
33+
return p;
34+
}, callback);
35+
};
36+
1937
/**
2038
* Amend a commit
2139
* @async

test/tests/commit.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,16 @@ describe("Commit", function() {
774774
assert.equal(1, this.commit.parentcount());
775775
});
776776

777+
it("can fetch a single parent", function() {
778+
return this.commit.parent(0).then(function(parent) {
779+
assert.strictEqual(parent.sha(),
780+
"ecfd36c80a3e9081f200dfda2391acadb56dac27");
781+
// This used to crash due to a missing .repo property on the retrieved
782+
// parent.
783+
return parent.getTree().then(tree => assert(tree));
784+
});
785+
});
786+
777787
it("can retrieve and walk a commit tree", function() {
778788
var commitTreeEntryCount = 0;
779789
var expectedCommitTreeEntryCount = 198;

0 commit comments

Comments
 (0)