@@ -549,9 +549,13 @@ Repository.prototype.createCommitOnHead = function(
549549 . then ( function ( ) {
550550 return index . addByPath ( filePath ) ;
551551 } ) ;
552- } , Promise . resolve ( ) ) ;
553- index . write ( ) ;
554- return index . writeTree ( ) ;
552+ } , Promise . resolve ( ) )
553+ . then ( function ( ) {
554+ return index . write ( ) ;
555+ } )
556+ . then ( function ( ) {
557+ return index . writeTree ( ) ;
558+ } ) ;
555559 } )
556560 . then ( function ( treeOid ) {
557561 return repo . getHeadCommit ( )
@@ -854,7 +858,6 @@ Repository.prototype.mergeBranches =
854858 }
855859
856860 // No conflicts so just go ahead with the merge
857- index . write ( ) ;
858861 return index . writeTreeTo ( repo ) ;
859862 } )
860863 . then ( function ( oid ) {
@@ -1292,15 +1295,20 @@ Repository.prototype.stageFilemode = function(filePath, stageNew) {
12921295 return Promise . reject ( "No differences found for this file." ) ;
12931296 }
12941297
1295- pathPatches . forEach ( function ( pathPatch ) {
1296- var entry = index . getByPath ( pathPatch . newFile ( ) . path ( ) , 0 ) ;
1297-
1298- entry . mode = stageNew ?
1299- pathPatch . newFile ( ) . mode ( ) : pathPatch . oldFile ( ) . mode ( ) ;
1298+ return pathPatches
1299+ . reduce ( function ( lastIndexAddPromise , pathPatch ) {
1300+ var entry = index . getByPath ( pathPatch . newFile ( ) . path ( ) , 0 ) ;
13001301
1301- index . add ( entry ) ;
1302- } ) ;
1302+ entry . mode = stageNew ?
1303+ pathPatch . newFile ( ) . mode ( ) : pathPatch . oldFile ( ) . mode ( ) ;
13031304
1305+ return lastIndexAddPromise
1306+ . then ( function ( ) {
1307+ return index . add ( entry ) ;
1308+ } ) ;
1309+ } , Promise . resolve ( ) ) ;
1310+ } )
1311+ . then ( function ( ) {
13041312 return index . write ( ) ;
13051313 } ) ;
13061314} ;
@@ -1461,8 +1469,10 @@ Repository.prototype.stageLines =
14611469 ! pathPatch [ 0 ] . isTypeChange ( ) ;
14621470 }
14631471 if ( emptyPatch ) {
1464- index . addByPath ( filePath ) ;
1465- return index . write ( ) ;
1472+ return index . addByPath ( filePath )
1473+ . then ( function ( ) {
1474+ return index . write ( ) ;
1475+ } ) ;
14661476 } else {
14671477 return result ;
14681478 }
@@ -1514,7 +1524,9 @@ Repository.prototype.stageLines =
15141524 entry . path = filePath ;
15151525 entry . fileSize = newBlob . content ( ) . length ;
15161526
1517- index . add ( entry ) ;
1527+ return index . add ( entry ) ;
1528+ } )
1529+ . then ( function ( ) {
15181530 return index . write ( ) ;
15191531 } )
15201532 . then ( function ( result ) {
0 commit comments