@@ -679,7 +679,7 @@ export class Repository {
679679 return stdout ;
680680 }
681681
682- async lstree ( treeish : string , path : string ) : Promise < { mode : number , object : string , size : number } > {
682+ async lstree ( treeish : string , path : string ) : Promise < { mode : string , object : string , size : number } > {
683683 if ( ! treeish ) { // index
684684 const { stdout } = await this . run ( [ 'ls-files' , '--stage' , '--' , path ] ) ;
685685
@@ -693,7 +693,7 @@ export class Repository {
693693 const catFile = await this . run ( [ 'cat-file' , '-s' , object ] ) ;
694694 const size = parseInt ( catFile . stdout ) ;
695695
696- return { mode : parseInt ( mode ) , object, size } ;
696+ return { mode, object, size } ;
697697 }
698698
699699 const { stdout } = await this . run ( [ 'ls-tree' , '-l' , treeish , '--' , path ] ) ;
@@ -705,7 +705,7 @@ export class Repository {
705705 }
706706
707707 const [ , mode , , object , size ] = match ;
708- return { mode : parseInt ( mode ) , object, size : parseInt ( size ) } ;
708+ return { mode, object, size : parseInt ( size ) } ;
709709 }
710710
711711 async detectObjectType ( object : string ) : Promise < { mimetype : string , encoding ?: string } > {
@@ -787,7 +787,16 @@ export class Repository {
787787 } ) ;
788788 }
789789
790- await this . run ( [ 'update-index' , '--cacheinfo' , '100644' , hash , path ] ) ;
790+ let mode : string ;
791+
792+ try {
793+ const details = await this . lstree ( 'HEAD' , path ) ;
794+ mode = details . mode ;
795+ } catch ( err ) {
796+ mode = '100644' ;
797+ }
798+
799+ await this . run ( [ 'update-index' , '--cacheinfo' , mode , hash , path ] ) ;
791800 }
792801
793802 async checkout ( treeish : string , paths : string [ ] ) : Promise < void > {
0 commit comments