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

Ensures that commits from parent(*) has a repository by rcjsuen · Pull Request #1658 · 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
16 changes: 16 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 @@ -5,6 +5,7 @@ var Commit = NodeGit.Commit;
var LookupWrapper = NodeGit.Utils.lookupWrapper;

var _amend = Commit.prototype.amend;
var _parent = Commit.prototype.parent;

/**
* Retrieves the commit pointed to by the oid
Expand Down Expand Up @@ -394,6 +395,21 @@ Commit.prototype.history = function() {
return event;
};

/**
* Get the specified parent of the commit.
*
* @param {number} the position of the parent, starting from 0
* @async
* @return {Commit} the parent commit at the specified position
*/
Commit.prototype.parent = function (id) {
var repository = this.repo;
return _parent.call(this, id).then(function(parent) {
parent.repo = repository;
return parent;
});
};

/**
* Retrieve the commit's parent shas.
*
Expand Down
12 changes: 12 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 @@ -128,6 +128,18 @@ describe("Commit", function() {
assert.equal(this.commit.timeOffset(), 780);
});

it("can call getTree on a parent commit", function() {
return this.commit.parent(0)
.then(function(parent) {
return parent.getTree();
})
.then(function(tree) {
assert.equal(
tree.id().toString(), "327ff68e59f94f0c25d2c62fb0938efa01e8a107"
);
});
});

it("can create a commit", function() {
var test = this;
var expectedCommitId = "315e77328ef596f3bc065d8ac6dd2c72c09de8a5";
Expand Down

Back | FazBrowse Home | New Git URL