Skip to content

Commit 2860393

Browse files
committed
1 parent 2ef64ee commit 2860393

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

extensions/git/src/git.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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> {

extensions/git/src/repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ export class Repository implements Disposable {
798798
});
799799
}
800800

801-
lstree(ref: string, filePath: string): Promise<{ mode: number, object: string, size: number }> {
801+
lstree(ref: string, filePath: string): Promise<{ mode: string, object: string, size: number }> {
802802
return this.run(Operation.LSTree, () => this.repository.lstree(ref, filePath));
803803
}
804804

0 commit comments

Comments
 (0)