@@ -9,7 +9,7 @@ import * as fs from "fs";
9
9
import * as path from "path" ;
10
10
import { Repository } from "./repository" ;
11
11
import { Svn } from "./svn" ;
12
- import { dispose } from "./util" ;
12
+ import { dispose , anyEvent , filterEvent } from "./util" ;
13
13
14
14
interface OpenRepository {
15
15
repository : Repository ;
@@ -19,6 +19,7 @@ export class Model {
19
19
public openRepositories : OpenRepository [ ] = [ ] ;
20
20
private disposables : Disposable [ ] = [ ] ;
21
21
private enabled = false ;
22
+ private possibleSvnRepositoryPaths = new Set < string > ( ) ;
22
23
23
24
get repositories ( ) : Repository [ ] {
24
25
return this . openRepositories . map ( r => r . repository ) ;
@@ -46,9 +47,41 @@ export class Model {
46
47
removed : [ ]
47
48
} ) ;
48
49
50
+ const fsWatcher = workspace . createFileSystemWatcher ( "**" ) ;
51
+ this . disposables . push ( fsWatcher ) ;
52
+
53
+ const onWorkspaceChange = anyEvent (
54
+ fsWatcher . onDidChange ,
55
+ fsWatcher . onDidCreate ,
56
+ fsWatcher . onDidDelete
57
+ ) ;
58
+ const onPossibleSvnRepositoryChange = filterEvent (
59
+ onWorkspaceChange ,
60
+ uri => ! this . getRepository ( uri )
61
+ ) ;
62
+ onPossibleSvnRepositoryChange (
63
+ this . onPossibleSvnRepositoryChange ,
64
+ this ,
65
+ this . disposables
66
+ ) ;
67
+
49
68
this . scanWorkspaceFolders ( ) ;
50
69
}
51
70
71
+ private onPossibleSvnRepositoryChange ( uri : Uri ) : void {
72
+ const possibleSvnRepositoryPath = uri . fsPath . replace ( / \. s v n .* $ / , "" ) ;
73
+ this . possibleSvnRepositoryPaths . add ( possibleSvnRepositoryPath ) ;
74
+ this . eventuallyScanPossibleSvnRepositories ( ) ;
75
+ }
76
+
77
+ private eventuallyScanPossibleSvnRepositories ( ) : void {
78
+ for ( const path of this . possibleSvnRepositoryPaths ) {
79
+ this . tryOpenRepository ( path ) ;
80
+ }
81
+
82
+ this . possibleSvnRepositoryPaths . clear ( ) ;
83
+ }
84
+
52
85
private disable ( ) : void {
53
86
this . repositories . forEach ( repository => repository . dispose ( ) ) ;
54
87
this . openRepositories = [ ] ;
@@ -112,7 +145,7 @@ export class Model {
112
145
return liveRepository && liveRepository . repository ;
113
146
}
114
147
115
- getOpenRepository ( hint : any ) {
148
+ getOpenRepository ( hint : any ) : OpenRepository | undefined {
116
149
if ( ! hint ) {
117
150
return undefined ;
118
151
}
@@ -121,20 +154,38 @@ export class Model {
121
154
return this . openRepositories . filter ( r => r . repository === hint ) [ 0 ] ;
122
155
}
123
156
124
- hint = Uri . file ( hint ) ;
157
+ if ( typeof hint === "string" ) {
158
+ hint = Uri . file ( hint ) ;
159
+ }
160
+
161
+ if ( hint instanceof Uri ) {
162
+ for ( const liveRepository of this . openRepositories ) {
163
+ const relativePath = path . relative (
164
+ liveRepository . repository . root ,
165
+ hint . fsPath
166
+ ) ;
167
+
168
+ if ( ! / ^ \. \. / . test ( relativePath ) ) {
169
+ return liveRepository ;
170
+ }
171
+ }
172
+
173
+ return undefined ;
174
+ }
125
175
126
176
for ( const liveRepository of this . openRepositories ) {
127
- const relativePath = path . relative (
128
- liveRepository . repository . root ,
129
- hint . fsPath
130
- ) ;
177
+ const repository = liveRepository . repository ;
131
178
132
- if ( ! / ^ \. \. / . test ( relativePath ) ) {
179
+ if ( hint === repository . sourceControl ) {
133
180
return liveRepository ;
134
181
}
135
182
136
- return undefined ;
183
+ if ( hint === repository . changes || hint === repository . notTracked ) {
184
+ return liveRepository ;
185
+ }
137
186
}
187
+
188
+ return undefined ;
138
189
}
139
190
140
191
private open ( repository : Repository ) : void {
0 commit comments