File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ var Commit = NodeGit.Commit;
55var LookupWrapper = NodeGit . Utils . lookupWrapper ;
66
77var _amend = Commit . prototype . amend ;
8+ var _parent = Commit . prototype . parent ;
89
910/**
1011 * Retrieves the commit pointed to by the oid
@@ -394,6 +395,21 @@ Commit.prototype.history = function() {
394395 return event ;
395396} ;
396397
398+ /**
399+ * Get the specified parent of the commit.
400+ *
401+ * @param {number } the position of the parent, starting from 0
402+ * @async
403+ * @return {Commit } the parent commit at the specified position
404+ */
405+ Commit . prototype . parent = function ( id ) {
406+ var repository = this . repo ;
407+ return _parent . call ( this , id ) . then ( function ( parent ) {
408+ parent . repo = repository ;
409+ return parent ;
410+ } ) ;
411+ } ;
412+
397413/**
398414 * Retrieve the commit's parent shas.
399415 *
Original file line number Diff line number Diff line change @@ -128,6 +128,18 @@ describe("Commit", function() {
128128 assert . equal ( this . commit . timeOffset ( ) , 780 ) ;
129129 } ) ;
130130
131+ it ( "can call getTree on a parent commit" , function ( ) {
132+ return this . commit . parent ( 0 )
133+ . then ( function ( parent ) {
134+ return parent . getTree ( ) ;
135+ } )
136+ . then ( function ( tree ) {
137+ assert . equal (
138+ tree . id ( ) . toString ( ) , "327ff68e59f94f0c25d2c62fb0938efa01e8a107"
139+ ) ;
140+ } ) ;
141+ } ) ;
142+
131143 it ( "can create a commit" , function ( ) {
132144 var test = this ;
133145 var expectedCommitId = "315e77328ef596f3bc065d8ac6dd2c72c09de8a5" ;
You can’t perform that action at this time.
0 commit comments