@@ -4,9 +4,14 @@ import type { Container } from '../../container';
4
4
import { RemoteResourceType } from '../../git/models/remoteResource' ;
5
5
import type { Repository } from '../../git/models/repository' ;
6
6
import { parseGitRemoteUrl } from '../../git/parsers/remoteParser' ;
7
- import type { GkProviderId , RepositoryIdentityDescriptor } from '../../gk/models/repositoryIdentities' ;
7
+ import type {
8
+ GkProviderId ,
9
+ RepositoryIdentityDescriptor ,
10
+ RepositoryIdentityProviderDescriptor ,
11
+ } from '../../gk/models/repositoryIdentities' ;
8
12
import { missingRepositoryId } from '../../gk/models/repositoryIdentities' ;
9
13
import { log } from '../../system/decorators/log' ;
14
+ import { getSettledValue } from '../../system/promise' ;
10
15
import type { ServerConnection } from '../gk/serverConnection' ;
11
16
12
17
export class RepositoryIdentityService implements Disposable {
@@ -25,6 +30,23 @@ export class RepositoryIdentityService implements Disposable {
25
30
return this . locateRepository ( identity , options ) ;
26
31
}
27
32
33
+ async getRepositoryIdentity < T extends string | GkProviderId > (
34
+ repository : Repository ,
35
+ ) : Promise < RepositoryIdentityDescriptor < T > > {
36
+ const [ bestRemotePromise , initialCommitShaPromise ] = await Promise . allSettled ( [
37
+ this . container . git . getBestRemoteWithProvider ( repository . uri ) ,
38
+ this . container . git . getFirstCommitSha ( repository . uri ) ,
39
+ ] ) ;
40
+ const bestRemote = getSettledValue ( bestRemotePromise ) ;
41
+
42
+ return {
43
+ name : repository . name ,
44
+ initialCommitSha : getSettledValue ( initialCommitShaPromise ) ,
45
+ remote : bestRemote ,
46
+ provider : bestRemote ?. provider ?. providerDesc as RepositoryIdentityProviderDescriptor < T > ,
47
+ } ;
48
+ }
49
+
28
50
@log ( )
29
51
private async locateRepository < T extends string | GkProviderId > (
30
52
identity : RepositoryIdentityDescriptor < T > ,
@@ -132,20 +154,29 @@ export class RepositoryIdentityService implements Disposable {
132
154
( await this . container . git . validateReference ( locatedRepo . uri , identity . initialCommitSha ) )
133
155
) {
134
156
foundRepo = locatedRepo ;
135
- await this . addFoundRepositoryToMap ( foundRepo , identity ) ;
157
+ await this . addRepositoryToPathMap ( foundRepo , identity ) ;
136
158
}
137
159
}
138
160
139
161
return foundRepo ;
140
162
}
141
163
142
- private async addFoundRepositoryToMap < T extends string | GkProviderId > (
164
+ async addRepositoryToPathMap < T extends string | GkProviderId > (
143
165
repo : Repository ,
144
166
identity ?: RepositoryIdentityDescriptor < T > ,
145
167
) {
168
+ if ( repo . virtual ) return ;
169
+
170
+ const [ identityResult , remotesResult ] = await Promise . allSettled ( [
171
+ identity == null ? this . getRepositoryIdentity < T > ( repo ) : undefined ,
172
+ repo . git . getRemotes ( ) ,
173
+ ] ) ;
174
+
175
+ identity ??= getSettledValue ( identityResult ) ;
176
+ const remotes = getSettledValue ( remotesResult ) ?? [ ] ;
177
+
146
178
const repoPath = repo . uri . fsPath ;
147
179
148
- const remotes = await repo . git . getRemotes ( ) ;
149
180
for ( const remote of remotes ) {
150
181
const remoteUrl = remote . provider ?. url ( { type : RemoteResourceType . Repo } ) ;
151
182
if ( remoteUrl != null ) {
0 commit comments