FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix behavior of Commit#parent by tniessen · Pull Request #1509 · nodegit/nodegit · GitHub

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

Filter by extension

Filter by extension .js  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
18 changes: 18 additions & 0 deletions lib/commit.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL