@@ -55,12 +55,14 @@ function(name, commit, force, signature, logMessage) {
5555/**
5656 * Look up a branch
5757 *
58- * @param {String } name Branch name, e.g. "master"
58+ * @param {String|Ref } name Branch name, e.g. "master" or Branch Ref
5959 * @param {Function } callback
6060 * @return {Ref }
6161 */
6262Repository . prototype . getBranch = function ( name , callback ) {
63- name = ~ name . indexOf ( "refs/heads/" ) ? name : "refs/heads/" + name ;
63+ name = name instanceof Reference || ~ name . indexOf ( "refs/heads/" )
64+ ? name
65+ : "refs/heads/" + name ;
6466
6567 return this . getReference ( name ) . then ( function ( reference ) {
6668 if ( typeof callback === "function" ) {
@@ -74,7 +76,7 @@ Repository.prototype.getBranch = function(name, callback) {
7476/**
7577 * Look up a branch's most recent commit.
7678 *
77- * @param {String } name Branch name, e.g. "master"
79+ * @param {String|Ref } name Branch name, e.g. "master" or Branch Ref
7880 * @param {Function } callback
7981 * @return {Commit }
8082 */
@@ -331,40 +333,40 @@ Repository.prototype.getHeadCommit = function(callback) {
331333Repository . prototype . createCommit = function (
332334 updateRef , author , committer , message , tree , parents , callback ) {
333335
334- var createCommit = null ;
335336 var repo = this ;
337+ var promises = [ ] ;
336338
337- if ( tree instanceof Tree ) {
338- createCommit = Promise . all ( [
339- Commit . create (
340- repo ,
341- updateRef ,
342- author ,
343- committer ,
344- null /* use default message encoding */ ,
345- message ,
346- tree ,
347- parents . length ,
348- parents
349- )
350- ] ) ;
351- } else {
352- createCommit = this . getTree ( tree ) . then ( function ( tree ) {
353- return Commit . create (
354- repo ,
355- updateRef ,
356- author ,
357- committer ,
358- null /* use default message encoding */ ,
359- message ,
360- tree ,
361- parents . length ,
362- parents
363- ) ;
364- } ) ;
365- }
339+ parents = parents || [ ] ;
340+
341+ promises . push ( repo . getTree ( tree ) ) ;
342+
343+ parents . forEach ( function ( parent ) {
344+ promises . push ( repo . getCommit ( parent ) ) ;
345+ } ) ;
366346
367- return createCommit . then ( function ( commit ) {
347+ return Promise . all ( promises ) . then ( function ( results ) {
348+ tree = results [ 0 ] ;
349+
350+ // Get the normalized values for our input into the function
351+ var parentsLength = parents . length ;
352+ parents = [ ] ;
353+
354+ for ( var i = 0 ; i < parentsLength ; i ++ ) {
355+ parents . push ( results [ i + 1 ] ) ;
356+ }
357+
358+ return Commit . create (
359+ repo ,
360+ updateRef ,
361+ author ,
362+ committer ,
363+ null /* use default message encoding */ ,
364+ message ,
365+ tree ,
366+ parents . length ,
367+ parents
368+ ) ;
369+ } ) . then ( function ( commit ) {
368370 if ( typeof callback === "function" ) {
369371 callback ( null , commit ) ;
370372 }
0 commit comments