@@ -49,8 +49,8 @@ public void Initialize(IRepositoryManager repositoryManager)
49
49
50
50
this . repositoryManager = repositoryManager ;
51
51
52
- repositoryManager . OnCurrentBranchUpdated += branch => CurrentBranch = branch ;
53
- repositoryManager . OnCurrentRemoteUpdated += remote => CurrentRemote = remote ;
52
+ repositoryManager . OnCurrentBranchUpdated += OnRepositoryManager_OnCurrentBranchUpdated ;
53
+ repositoryManager . OnCurrentRemoteUpdated += OnRepositoryManager_OnCurrentRemoteUpdated ;
54
54
repositoryManager . OnStatusUpdated += status => CurrentStatus = status ;
55
55
repositoryManager . OnLocksUpdated += locks => CurrentLocks = locks ;
56
56
repositoryManager . OnLocalBranchListUpdated += OnRepositoryManager_OnLocalBranchListUpdated ;
@@ -168,6 +168,27 @@ public bool Equals(IRepository other)
168
168
object . Equals ( LocalPath , other . LocalPath ) ;
169
169
}
170
170
171
+ private void OnRepositoryManager_OnCurrentRemoteUpdated ( ConfigRemote ? remote )
172
+ {
173
+ if ( ! Nullable . Equals ( currentRemote , remote ) )
174
+ {
175
+ currentRemote = remote ;
176
+ Logger . Trace ( "OnCurrentRemoteChanged: {0}" , currentRemote . HasValue ? currentRemote . Value . ToString ( ) : "[NULL]" ) ;
177
+ OnCurrentRemoteChanged ? . Invoke ( currentRemote . HasValue ? currentRemote . Value . Name : null ) ;
178
+ UpdateRepositoryInfo ( ) ;
179
+ }
180
+ }
181
+
182
+ private void OnRepositoryManager_OnCurrentBranchUpdated ( ConfigBranch ? branch )
183
+ {
184
+ if ( ! Nullable . Equals ( currentBranch , branch ) )
185
+ {
186
+ currentBranch = branch ;
187
+ Logger . Trace ( "OnCurrentBranchChanged: {0}" , currentBranch . HasValue ? currentBranch . ToString ( ) : "[NULL]" ) ;
188
+ OnCurrentBranchChanged ? . Invoke ( currentBranch . HasValue ? currentBranch . Value . Name : null ) ;
189
+ }
190
+ }
191
+
171
192
private void OnRepositoryManager_OnLocalBranchUpdated ( string name )
172
193
{
173
194
if ( name == currentBranch ? . Name )
@@ -181,10 +202,7 @@ private void OnRepositoryManager_OnRemoteBranchListUpdated(Dictionary<string, Co
181
202
{
182
203
remotes = updatedRemotes ;
183
204
184
- Remotes = remotes . Select ( pair => new GitRemote {
185
- Name = pair . Value . Name ,
186
- Url = pair . Value . Url
187
- } ) . ToArray ( ) ;
205
+ Remotes = remotes . Select ( pair => GetGitRemote ( pair . Value ) ) . ToArray ( ) ;
188
206
189
207
remoteBranches = branches ;
190
208
@@ -291,58 +309,59 @@ private void RepositoryManager_OnRemoteBranchRemoved(string remote, string name)
291
309
}
292
310
}
293
311
294
- public IList < GitRemote > Remotes { get ; private set ; }
295
-
296
- public IEnumerable < GitBranch > LocalBranches => localBranches . Values . Select ( x => {
312
+ private GitBranch GetLocalGitBranch ( ConfigBranch x )
313
+ {
297
314
var name = x . Name ;
298
315
var trackingName = x . IsTracking ? x . Remote . Value . Name + "/" + name : "[None]" ;
299
316
var isActive = name == CurrentBranch ? . Name ;
300
317
301
318
return new GitBranch ( name , trackingName , isActive ) ;
302
- } ) ;
319
+ }
303
320
304
- public IEnumerable < GitBranch > RemoteBranches => remoteBranches . Values . SelectMany ( x => x . Values ) . Select ( x => {
321
+ private GitBranch GetRemoteGitBranch ( ConfigBranch x )
322
+ {
305
323
var name = x . Remote . Value . Name + "/" + x . Name ;
306
324
var trackingName = "[None]" ;
307
325
308
326
return new GitBranch ( name , trackingName , false ) ;
309
- } ) ;
327
+ }
310
328
311
- public ConfigBranch ? CurrentBranch
329
+ private GitRemote GetGitRemote ( ConfigRemote configRemote )
312
330
{
313
- get { return currentBranch ; }
314
- set
331
+ return new GitRemote { Name = configRemote . Name , Url = configRemote . Url } ;
332
+ }
333
+
334
+ public IList < GitRemote > Remotes { get ; private set ; }
335
+
336
+ public IEnumerable < GitBranch > LocalBranches => localBranches . Values . Select ( GetLocalGitBranch ) ;
337
+
338
+ public IEnumerable < GitBranch > RemoteBranches => remoteBranches . Values . SelectMany ( x => x . Values ) . Select ( GetRemoteGitBranch ) ;
339
+
340
+ public GitBranch ? CurrentBranch
341
+ {
342
+ get
315
343
{
316
- if ( ! Nullable . Equals ( currentBranch , value ) )
344
+ if ( currentBranch != null )
317
345
{
318
- currentBranch = value ;
319
- Logger . Trace ( "OnCurrentBranchChanged: {0}" , currentBranch . HasValue ? currentBranch . ToString ( ) : "[NULL]" ) ;
320
- OnCurrentBranchChanged ? . Invoke ( currentBranch . HasValue ? currentBranch . Value . Name : null ) ;
346
+ return GetLocalGitBranch ( currentBranch . Value ) ;
321
347
}
348
+
349
+ return null ;
322
350
}
323
351
}
324
352
325
- /// <summary>
326
- /// Gets the current branch of the repository.
327
- /// </summary>
328
-
329
353
public string CurrentBranchName => currentBranch ? . Name ;
330
354
331
- /// <summary>
332
- /// Gets the current remote of the repository.
333
- /// </summary>
334
- public ConfigRemote ? CurrentRemote
355
+ public GitRemote ? CurrentRemote
335
356
{
336
- get { return currentRemote ; }
337
- set
357
+ get
338
358
{
339
- if ( ! Nullable . Equals ( currentRemote , value ) )
359
+ if ( currentRemote != null )
340
360
{
341
- currentRemote = value ;
342
- Logger . Trace ( "OnCurrentRemoteChanged: {0}" , currentRemote . HasValue ? currentRemote . Value . ToString ( ) : "[NULL]" ) ;
343
- OnCurrentRemoteChanged ? . Invoke ( currentRemote . HasValue ? currentRemote . Value . Name : null ) ;
344
- UpdateRepositoryInfo ( ) ;
361
+ return GetGitRemote ( currentRemote . Value ) ;
345
362
}
363
+
364
+ return null ;
346
365
}
347
366
}
348
367
@@ -370,7 +389,7 @@ public ConfigRemote? CurrentRemote
370
389
public GitStatus CurrentStatus
371
390
{
372
391
get { return currentStatus ; }
373
- set
392
+ private set
374
393
{
375
394
currentStatus = value ;
376
395
Logger . Trace ( "OnStatusChanged: {0}" , value . ToString ( ) ) ;
0 commit comments