@@ -14,8 +14,9 @@ import { Resource } from "./resource";
14
14
import { throttle , debounce } from "./decorators" ;
15
15
import { Repository as BaseRepository } from "./svnRepository" ;
16
16
import { SvnStatusBar } from "./statusBar" ;
17
- import { dispose , anyEvent , filterEvent } from "./util" ;
17
+ import { dispose , anyEvent , filterEvent , toDisposable } from "./util" ;
18
18
import * as path from "path" ;
19
+ import { setInterval , clearInterval } from "timers" ;
19
20
20
21
export class Repository {
21
22
public watcher : FileSystemWatcher ;
@@ -26,6 +27,7 @@ export class Repository {
26
27
public currentBranch = "" ;
27
28
public isSwitchingBranch : boolean = false ;
28
29
public branches : any [ ] = [ ] ;
30
+ public branchesTimer : NodeJS . Timer ;
29
31
30
32
private _onDidChangeRepository = new EventEmitter < Uri > ( ) ;
31
33
readonly onDidChangeRepository : Event < Uri > = this . _onDidChangeRepository
@@ -94,6 +96,11 @@ export class Repository {
94
96
null ,
95
97
this . disposables
96
98
) ;
99
+ this . onDidChangeRepository (
100
+ ( ) => ( this . sourceControl . statusBarCommands = statusBar . commands ) ,
101
+ null ,
102
+ this . disposables
103
+ ) ;
97
104
this . sourceControl . statusBarCommands = statusBar . commands ;
98
105
99
106
this . changes = this . sourceControl . createResourceGroup ( "changes" , "Changes" ) ;
@@ -105,9 +112,22 @@ export class Repository {
105
112
this . changes . hideWhenEmpty = true ;
106
113
this . notTracked . hideWhenEmpty = true ;
107
114
115
+ this . disposables . push ( toDisposable ( ( ) => clearInterval ( this . branchesTimer ) ) ) ;
116
+ setInterval ( ( ) => { this . updateBranches ( ) } , 1000 * 60 * 5 ) ; // 5 minutes
117
+
118
+ this . updateBranches ( ) ;
108
119
this . update ( ) ;
109
120
}
110
121
122
+ @debounce ( 1000 )
123
+ async updateBranches ( ) {
124
+ try {
125
+ this . branches = await this . repository . getBranches ( ) ;
126
+ } catch ( error ) {
127
+ console . error ( error ) ;
128
+ }
129
+ }
130
+
111
131
@debounce ( 1000 )
112
132
async update ( ) {
113
133
let changes : any [ ] = [ ] ;
@@ -147,12 +167,6 @@ export class Repository {
147
167
148
168
this . currentBranch = await this . getCurrentBranch ( ) ;
149
169
150
- try {
151
- this . branches = await this . repository . getBranches ( ) ;
152
- } catch ( error ) {
153
- console . error ( error ) ;
154
- }
155
-
156
170
this . _onDidChangeStatus . fire ( ) ;
157
171
158
172
return Promise . resolve ( ) ;
@@ -182,16 +196,23 @@ export class Repository {
182
196
return this . repository . getCurrentBranch ( ) ;
183
197
}
184
198
185
- branch ( name : string ) {
186
- return this . repository . branch ( name ) ;
199
+ async branch ( name : string ) {
200
+ this . isSwitchingBranch = true ;
201
+ this . _onDidChangeRepository . fire ( ) ;
202
+ const response = await this . repository . branch ( name ) ;
203
+ this . isSwitchingBranch = false ;
204
+ this . updateBranches ( ) ;
205
+ this . _onDidChangeRepository . fire ( ) ;
206
+ return response ;
187
207
}
188
208
189
209
async switchBranch ( name : string ) {
190
210
this . isSwitchingBranch = true ;
191
- this . _onDidChangeStatus . fire ( ) ;
211
+ this . _onDidChangeRepository . fire ( ) ;
192
212
const response = await this . repository . switchBranch ( name ) ;
193
213
this . isSwitchingBranch = false ;
194
- this . _onDidChangeStatus . fire ( ) ;
214
+ this . updateBranches ( ) ;
215
+ this . _onDidChangeRepository . fire ( ) ;
195
216
return response ;
196
217
}
197
218
}
0 commit comments