@@ -34,40 +34,6 @@ class RepositoryPick implements QuickPickItem {
34
34
constructor ( public readonly repository : Repository , public readonly index : number ) { }
35
35
}
36
36
37
- abstract class RepositoryMap < T = void > extends Map < string , T > {
38
- constructor ( ) {
39
- super ( ) ;
40
- this . updateContextKey ( ) ;
41
- }
42
-
43
- override set ( key : string , value : T ) : this {
44
- const result = super . set ( key , value ) ;
45
- this . updateContextKey ( ) ;
46
-
47
- return result ;
48
- }
49
-
50
- override delete ( key : string ) : boolean {
51
- const result = super . delete ( key ) ;
52
- this . updateContextKey ( ) ;
53
-
54
- return result ;
55
- }
56
-
57
- abstract updateContextKey ( ) : void ;
58
- }
59
-
60
- /**
61
- * Key - normalized path used in user interface
62
- * Value - path extracted from the output of the `git status` command
63
- * used when calling `git config --global --add safe.directory`
64
- */
65
- class UnsafeRepositoryMap extends RepositoryMap < string > {
66
- updateContextKey ( ) : void {
67
- commands . executeCommand ( 'setContext' , 'git.unsafeRepositoryCount' , this . size ) ;
68
- }
69
- }
70
-
71
37
export interface ModelChangeEvent {
72
38
repository : Repository ;
73
39
uri : Uri ;
@@ -159,6 +125,45 @@ class ParentRepositoriesManager {
159
125
}
160
126
}
161
127
128
+ class UnsafeRepositoriesManager {
129
+
130
+ /**
131
+ * Key - normalized path used in user interface
132
+ * Value - path extracted from the output of the `git status` command
133
+ * used when calling `git config --global --add safe.directory`
134
+ */
135
+ private _repositories = new Map < string , string > ( ) ;
136
+ get repositories ( ) : string [ ] {
137
+ return [ ...this . _repositories . keys ( ) ] ;
138
+ }
139
+
140
+ addRepository ( repository : string , path : string ) : void {
141
+ this . _repositories . set ( repository , path ) ;
142
+ this . onDidChangeRepositories ( ) ;
143
+ }
144
+
145
+ deleteRepository ( repository : string ) : boolean {
146
+ const result = this . _repositories . delete ( repository ) ;
147
+ if ( result ) {
148
+ this . onDidChangeRepositories ( ) ;
149
+ }
150
+
151
+ return result ;
152
+ }
153
+
154
+ getRepositoryPath ( repository : string ) : string | undefined {
155
+ return this . _repositories . get ( repository ) ;
156
+ }
157
+
158
+ hasRepository ( repository : string ) : boolean {
159
+ return this . _repositories . has ( repository ) ;
160
+ }
161
+
162
+ private onDidChangeRepositories ( ) : void {
163
+ commands . executeCommand ( 'setContext' , 'git.unsafeRepositoryCount' , this . _repositories . size ) ;
164
+ }
165
+ }
166
+
162
167
export class Model implements IBranchProtectionProviderRegistry , IRemoteSourcePublisherRegistry , IPostCommitCommandsProviderRegistry , IPushErrorHandlerRegistry {
163
168
164
169
private _onDidOpenRepository = new EventEmitter < Repository > ( ) ;
@@ -226,9 +231,9 @@ export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePu
226
231
227
232
private pushErrorHandlers = new Set < PushErrorHandler > ( ) ;
228
233
229
- private _unsafeRepositories = new UnsafeRepositoryMap ( ) ;
230
- get unsafeRepositories ( ) : UnsafeRepositoryMap {
231
- return this . _unsafeRepositories ;
234
+ private _unsafeRepositoriesManager : UnsafeRepositoriesManager ;
235
+ get unsafeRepositories ( ) : string [ ] {
236
+ return this . _unsafeRepositoriesManager . repositories ;
232
237
}
233
238
234
239
private _parentRepositoriesManager : ParentRepositoriesManager ;
@@ -257,6 +262,7 @@ export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePu
257
262
// Repositories managers
258
263
this . _closedRepositoriesManager = new ClosedRepositoriesManager ( workspaceState ) ;
259
264
this . _parentRepositoriesManager = new ParentRepositoriesManager ( globalState ) ;
265
+ this . _unsafeRepositoriesManager = new UnsafeRepositoriesManager ( ) ;
260
266
261
267
workspace . onDidChangeWorkspaceFolders ( this . onDidChangeWorkspaceFolders , this , this . disposables ) ;
262
268
window . onDidChangeVisibleTextEditors ( this . onDidChangeVisibleTextEditors , this , this . disposables ) ;
@@ -296,7 +302,7 @@ export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePu
296
302
parentRepositoryConfig === 'prompt' ) {
297
303
// Parent repositories notification
298
304
this . showParentRepositoryNotification ( ) ;
299
- } else if ( this . _unsafeRepositories . size !== 0 ) {
305
+ } else if ( this . unsafeRepositories . length !== 0 ) {
300
306
// Unsafe repositories notification
301
307
this . showUnsafeRepositoryNotification ( ) ;
302
308
}
@@ -547,11 +553,11 @@ export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePu
547
553
this . logger . trace ( `Unsafe repository: ${ repositoryRoot } ` ) ;
548
554
549
555
// Show a notification if the unsafe repository is opened after the initial scan
550
- if ( this . _state === 'initialized' && ! this . _unsafeRepositories . has ( repositoryRoot ) ) {
556
+ if ( this . _state === 'initialized' && ! this . _unsafeRepositoriesManager . hasRepository ( repositoryRoot ) ) {
551
557
this . showUnsafeRepositoryNotification ( ) ;
552
558
}
553
559
554
- this . _unsafeRepositories . set ( repositoryRoot , unsafeRepositoryMatch [ 2 ] ) ;
560
+ this . _unsafeRepositoriesManager . addRepository ( repositoryRoot , unsafeRepositoryMatch [ 2 ] ) ;
555
561
556
562
return ;
557
563
}
@@ -903,6 +909,14 @@ export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePu
903
909
return [ ...this . pushErrorHandlers ] ;
904
910
}
905
911
912
+ getUnsafeRepositoryPath ( repository : string ) : string | undefined {
913
+ return this . _unsafeRepositoriesManager . getRepositoryPath ( repository ) ;
914
+ }
915
+
916
+ deleteUnsafeRepository ( repository : string ) : boolean {
917
+ return this . _unsafeRepositoriesManager . deleteRepository ( repository ) ;
918
+ }
919
+
906
920
private async isRepositoryOutsideWorkspace ( repositoryPath : string ) : Promise < boolean > {
907
921
const workspaceFolders = ( workspace . workspaceFolders || [ ] )
908
922
. filter ( folder => folder . uri . scheme === 'file' ) ;
@@ -969,7 +983,7 @@ export class Model implements IBranchProtectionProviderRegistry, IRemoteSourcePu
969
983
return ;
970
984
}
971
985
972
- const message = this . _unsafeRepositories . size === 1 ?
986
+ const message = this . unsafeRepositories . length === 1 ?
973
987
l10n . t ( 'The git repository in the current folder is potentially unsafe as the folder is owned by someone other than the current user.' ) :
974
988
l10n . t ( 'The git repositories in the current folder are potentially unsafe as the folders are owned by someone other than the current user.' ) ;
975
989
0 commit comments