@@ -131,6 +131,26 @@ export class GitFileSystemProvider implements FileSystemProvider {
131131 this . cache = cache ;
132132 }
133133
134+ private async getOrOpenRepository ( uri : string | Uri ) : Promise < Repository | undefined > {
135+ let repository = this . model . getRepository ( uri ) ;
136+ if ( repository ) {
137+ return repository ;
138+ }
139+
140+ // In case of the empty window, or the agent sessions window, no repositories are open
141+ // so we need to explicitly open a repository before we can serve git content for the
142+ // given git resource.
143+ if ( workspace . workspaceFolders === undefined || workspace . isAgentSessionsWorkspace ) {
144+ const fsPath = typeof uri === 'string' ? uri : fromGitUri ( uri ) . path ;
145+ this . logger . info ( `[GitFileSystemProvider][getOrOpenRepository] Opening repository for ${ fsPath } ` ) ;
146+
147+ await this . model . openRepository ( fsPath , true , true ) ;
148+ repository = this . model . getRepository ( uri ) ;
149+ }
150+
151+ return repository ;
152+ }
153+
134154 watch ( ) : Disposable {
135155 return EmptyDisposable ;
136156 }
@@ -139,7 +159,11 @@ export class GitFileSystemProvider implements FileSystemProvider {
139159 await this . model . isInitialized ;
140160
141161 const { submoduleOf, path, ref } = fromGitUri ( uri ) ;
142- const repository = submoduleOf ? this . model . getRepository ( submoduleOf ) : this . model . getRepository ( uri ) ;
162+
163+ const repository = submoduleOf
164+ ? await this . getOrOpenRepository ( submoduleOf )
165+ : await this . getOrOpenRepository ( uri ) ;
166+
143167 if ( ! repository ) {
144168 this . logger . warn ( `[GitFileSystemProvider][stat] Repository not found - ${ uri . toString ( ) } ` ) ;
145169 throw FileSystemError . FileNotFound ( ) ;
@@ -175,7 +199,7 @@ export class GitFileSystemProvider implements FileSystemProvider {
175199 const { path, ref, submoduleOf } = fromGitUri ( uri ) ;
176200
177201 if ( submoduleOf ) {
178- const repository = this . model . getRepository ( submoduleOf ) ;
202+ const repository = await this . getOrOpenRepository ( submoduleOf ) ;
179203
180204 if ( ! repository ) {
181205 throw FileSystemError . FileNotFound ( ) ;
@@ -190,7 +214,7 @@ export class GitFileSystemProvider implements FileSystemProvider {
190214 }
191215 }
192216
193- const repository = this . model . getRepository ( uri ) ;
217+ const repository = await this . getOrOpenRepository ( uri ) ;
194218
195219 if ( ! repository ) {
196220 this . logger . warn ( `[GitFileSystemProvider][readFile] Repository not found - ${ uri . toString ( ) } ` ) ;
0 commit comments