@@ -532,9 +532,13 @@ Repository.prototype.createCommitOnHead = function(
532532 . then ( function ( ) {
533533 return index . addByPath ( filePath ) ;
534534 } ) ;
535- } , Promise . resolve ( ) ) ;
536- index . write ( ) ;
537- return index . writeTree ( ) ;
535+ } , Promise . resolve ( ) )
536+ . then ( function ( ) {
537+ return index . write ( ) ;
538+ } )
539+ . then ( function ( ) {
540+ return index . writeTree ( ) ;
541+ } ) ;
538542 } )
539543 . then ( function ( treeOid ) {
540544 return repo . getHeadCommit ( )
@@ -837,7 +841,6 @@ Repository.prototype.mergeBranches =
837841 }
838842
839843 // No conflicts so just go ahead with the merge
840- index . write ( ) ;
841844 return index . writeTreeTo ( repo ) ;
842845 } )
843846 . then ( function ( oid ) {
@@ -1249,7 +1252,6 @@ Repository.prototype.stageFilemode = function(filePath, stageNew) {
12491252 } )
12501253 . then ( function ( indexResult ) {
12511254 index = indexResult ;
1252- return index . read ( 1 ) ;
12531255 } )
12541256 . then ( function ( ) {
12551257 return diffPromise ;
@@ -1276,15 +1278,20 @@ Repository.prototype.stageFilemode = function(filePath, stageNew) {
12761278 return Promise . reject ( "No differences found for this file." ) ;
12771279 }
12781280
1279- pathPatches . forEach ( function ( pathPatch ) {
1280- var entry = index . getByPath ( pathPatch . newFile ( ) . path ( ) , 0 ) ;
1281-
1282- entry . mode = stageNew ?
1283- pathPatch . newFile ( ) . mode ( ) : pathPatch . oldFile ( ) . mode ( ) ;
1281+ return pathPatches
1282+ . reduce ( function ( lastIndexAddPromise , pathPatch ) {
1283+ var entry = index . getByPath ( pathPatch . newFile ( ) . path ( ) , 0 ) ;
12841284
1285- index . add ( entry ) ;
1286- } ) ;
1285+ entry . mode = stageNew ?
1286+ pathPatch . newFile ( ) . mode ( ) : pathPatch . oldFile ( ) . mode ( ) ;
12871287
1288+ return lastIndexAddPromise
1289+ . then ( function ( ) {
1290+ return index . add ( entry ) ;
1291+ } ) ;
1292+ } , Promise . resolve ( ) ) ;
1293+ } )
1294+ . then ( function ( ) {
12881295 return index . write ( ) ;
12891296 } ) ;
12901297} ;
@@ -1445,8 +1452,10 @@ Repository.prototype.stageLines =
14451452 ! pathPatch [ 0 ] . isTypeChange ( ) ;
14461453 }
14471454 if ( emptyPatch ) {
1448- index . addByPath ( filePath ) ;
1449- return index . write ( ) ;
1455+ return index . addByPath ( filePath )
1456+ . then ( function ( ) {
1457+ return index . write ( ) ;
1458+ } ) ;
14501459 } else {
14511460 return result ;
14521461 }
@@ -1456,7 +1465,6 @@ Repository.prototype.stageLines =
14561465 return repo . openIndex ( )
14571466 . then ( function ( indexResult ) {
14581467 index = indexResult ;
1459- return index . read ( 1 ) ;
14601468 } )
14611469 . then ( function ( ) {
14621470 return diffPromise ( ) ;
@@ -1499,7 +1507,9 @@ Repository.prototype.stageLines =
14991507 entry . path = filePath ;
15001508 entry . fileSize = newBlob . content ( ) . length ;
15011509
1502- index . add ( entry ) ;
1510+ return index . add ( entry ) ;
1511+ } )
1512+ . then ( function ( ) {
15031513 return index . write ( ) ;
15041514 } )
15051515 . then ( function ( result ) {
0 commit comments