@@ -9,6 +9,8 @@ public interface IRepositoryManager : IDisposable
9
9
{
10
10
event Action < ConfigBranch ? , ConfigRemote ? > OnCurrentBranchAndRemoteUpdated ;
11
11
event Action < bool > OnIsBusyChanged ;
12
+ event Action < GitStatus > GitStatusUpdated ;
13
+ event Action < List < GitLogEntry > > GitLogUpdated ;
12
14
event Action < Dictionary < string , ConfigBranch > > OnLocalBranchListUpdated ;
13
15
event Action < Dictionary < string , ConfigRemote > , Dictionary < string , Dictionary < string , ConfigBranch > > > OnRemoteBranchListUpdated ;
14
16
@@ -96,6 +98,8 @@ class RepositoryManager : IRepositoryManager
96
98
97
99
public event Action < ConfigBranch ? , ConfigRemote ? > OnCurrentBranchAndRemoteUpdated ;
98
100
public event Action < bool > OnIsBusyChanged ;
101
+ public event Action < GitStatus > GitStatusUpdated ;
102
+ public event Action < List < GitLogEntry > > GitLogUpdated ;
99
103
public event Action < Dictionary < string , ConfigBranch > > OnLocalBranchListUpdated ;
100
104
public event Action < Dictionary < string , ConfigRemote > , Dictionary < string , Dictionary < string , ConfigBranch > > > OnRemoteBranchListUpdated ;
101
105
@@ -283,10 +287,13 @@ public ITask UnlockFile(string file, bool force)
283
287
284
288
private void SetupWatcher ( )
285
289
{
286
- watcher . HeadChanged += Watcher_OnHeadChanged ;
287
- watcher . IndexChanged += Watcher_OnIndexChanged ;
288
- watcher . ConfigChanged += Watcher_OnConfigChanged ;
289
- watcher . RepositoryChanged += Watcher_OnRepositoryChanged ;
290
+ watcher . HeadChanged += WatcherOnHeadChanged ;
291
+ watcher . IndexChanged += WatcherOnIndexChanged ;
292
+ watcher . ConfigChanged += WatcherOnConfigChanged ;
293
+ watcher . RepositoryCommitted += WatcherOnRepositoryCommitted ;
294
+ watcher . RepositoryChanged += WatcherOnRepositoryChanged ;
295
+ watcher . LocalBranchesChanged += WatcherOnLocalBranchesChanged ;
296
+ watcher . RemoteBranchesChanged += WatcherOnRemoteBranchesChanged ;
290
297
}
291
298
292
299
private void UpdateHead ( )
@@ -296,6 +303,48 @@ private void UpdateHead()
296
303
UpdateCurrentBranchAndRemote ( head ) ;
297
304
}
298
305
306
+ private void UpdateCurrentBranchAndRemote ( string head )
307
+ {
308
+ ConfigBranch ? branch = null ;
309
+
310
+ if ( head . StartsWith ( "ref:" ) )
311
+ {
312
+ var branchName = head . Substring ( head . IndexOf ( "refs/heads/" ) + "refs/heads/" . Length ) ;
313
+ branch = config . GetBranch ( branchName ) ;
314
+
315
+ if ( ! branch . HasValue )
316
+ {
317
+ branch = new ConfigBranch { Name = branchName } ;
318
+ }
319
+ }
320
+
321
+ var defaultRemote = "origin" ;
322
+ ConfigRemote ? remote = null ;
323
+
324
+ if ( branch . HasValue && branch . Value . IsTracking )
325
+ {
326
+ remote = branch . Value . Remote ;
327
+ }
328
+
329
+ if ( ! remote . HasValue )
330
+ {
331
+ remote = config . GetRemote ( defaultRemote ) ;
332
+ }
333
+
334
+ if ( ! remote . HasValue )
335
+ {
336
+ var configRemotes = config . GetRemotes ( ) . ToArray ( ) ;
337
+ if ( configRemotes . Any ( ) )
338
+ {
339
+ remote = configRemotes . FirstOrDefault ( ) ;
340
+ }
341
+ }
342
+
343
+ Logger . Trace ( "CurrentBranch: {0}" , branch . HasValue ? branch . Value . ToString ( ) : "[NULL]" ) ;
344
+ Logger . Trace ( "CurrentRemote: {0}" , remote . HasValue ? remote . Value . ToString ( ) : "[NULL]" ) ;
345
+ OnCurrentBranchAndRemoteUpdated ? . Invoke ( branch , remote ) ;
346
+ }
347
+
299
348
private ITask HookupHandlers ( ITask task , bool disableWatcher = false )
300
349
{
301
350
task . OnStart += t => {
@@ -321,67 +370,70 @@ private ITask HookupHandlers(ITask task, bool disableWatcher = false)
321
370
return task ;
322
371
}
323
372
324
- private void Watcher_OnRepositoryChanged ( )
373
+ private void WatcherOnRemoteBranchesChanged ( )
325
374
{
326
- Logger . Trace ( "OnRepositoryChanged" ) ;
375
+ Logger . Trace ( "WatcherOnRemoteBranchesChanged" ) ;
376
+ UpdateRemoteBranches ( ) ;
327
377
}
328
378
329
- private void Watcher_OnConfigChanged ( )
379
+ private void WatcherOnLocalBranchesChanged ( )
330
380
{
381
+ Logger . Trace ( "WatcherOnLocalBranchesChanged" ) ;
382
+ UpdateLocalBranches ( ) ;
383
+ }
384
+
385
+ private void WatcherOnRepositoryCommitted ( )
386
+ {
387
+ Logger . Trace ( "WatcherOnRepositoryCommitted" ) ;
388
+ UpdateLog ( ) ;
389
+ }
390
+
391
+ private void WatcherOnRepositoryChanged ( )
392
+ {
393
+ Logger . Trace ( "WatcherOnRepositoryChanged" ) ;
394
+ UpdateStatus ( ) ;
395
+ }
396
+
397
+ private void WatcherOnConfigChanged ( )
398
+ {
399
+ Logger . Trace ( "WatcherOnConfigChanged" ) ;
331
400
UpdateConfigData ( true ) ;
332
401
}
333
402
334
- private void Watcher_OnHeadChanged ( )
403
+ private void WatcherOnHeadChanged ( )
335
404
{
336
- Logger . Trace ( "Watcher_OnHeadChanged " ) ;
405
+ Logger . Trace ( "WatcherOnHeadChanged " ) ;
337
406
UpdateHead ( ) ;
338
407
}
339
408
340
- private void UpdateCurrentBranchAndRemote ( string head )
409
+ private void WatcherOnIndexChanged ( )
341
410
{
342
- ConfigBranch ? branch = null ;
411
+ Logger . Trace ( "WatcherOnIndexChanged" ) ;
412
+ UpdateStatus ( ) ;
413
+ }
343
414
344
- if ( head . StartsWith ( "ref:" ) )
415
+ private void UpdateLog ( )
416
+ {
417
+ Log ( ) . Then ( ( success , logEntries ) =>
345
418
{
346
- var branchName = head . Substring ( head . IndexOf ( "refs/heads/" ) + "refs/heads/" . Length ) ;
347
- branch = config . GetBranch ( branchName ) ;
348
-
349
- if ( ! branch . HasValue )
419
+ if ( success )
350
420
{
351
- branch = new ConfigBranch { Name = branchName } ;
421
+ GitLogUpdated ? . Invoke ( logEntries ) ;
352
422
}
353
- }
354
-
355
- var defaultRemote = "origin" ;
356
- ConfigRemote ? remote = null ;
357
-
358
- if ( branch . HasValue && branch . Value . IsTracking )
359
- {
360
- remote = branch . Value . Remote ;
361
- }
362
-
363
- if ( ! remote . HasValue )
364
- {
365
- remote = config . GetRemote ( defaultRemote ) ;
366
- }
423
+ } ) . Start ( ) ;
424
+ }
367
425
368
- if ( ! remote . HasValue )
426
+ private void UpdateStatus ( )
427
+ {
428
+ Status ( ) . Then ( ( success , status ) =>
369
429
{
370
- var configRemotes = config . GetRemotes ( ) . ToArray ( ) ;
371
- if ( configRemotes . Any ( ) )
430
+ if ( success )
372
431
{
373
- remote = configRemotes . FirstOrDefault ( ) ;
432
+ GitStatusUpdated ? . Invoke ( status ) ;
374
433
}
375
- }
376
-
377
- Logger . Trace ( "OnCurrentBranchUpdated: {0}" , branch . HasValue ? branch . Value . ToString ( ) : "[NULL]" ) ;
378
- Logger . Trace ( "OnCurrentRemoteUpdated: {0}" , remote . HasValue ? remote . Value . ToString ( ) : "[NULL]" ) ;
379
- OnCurrentBranchAndRemoteUpdated ? . Invoke ( branch , remote ) ;
434
+ } ) . Start ( ) ;
380
435
}
381
436
382
- private void Watcher_OnIndexChanged ( )
383
- { }
384
-
385
437
private void UpdateConfigData ( bool resetConfig = false )
386
438
{
387
439
Logger . Trace ( "UpdateConfigData reset:{0}" , resetConfig ) ;
@@ -391,23 +443,23 @@ private void UpdateConfigData(bool resetConfig = false)
391
443
config . Reset ( ) ;
392
444
}
393
445
394
- LoadBranchesFromConfig ( ) ;
395
- LoadRemotesFromConfig ( ) ;
446
+ UpdateLocalBranches ( ) ;
447
+ UpdateRemoteBranches ( ) ;
396
448
UpdateHead ( ) ;
397
449
}
398
450
399
- private void LoadBranchesFromConfig ( )
451
+ private void UpdateLocalBranches ( )
400
452
{
401
- Logger . Trace ( "LoadBranchesFromConfig " ) ;
453
+ Logger . Trace ( "UpdateLocalBranches " ) ;
402
454
403
455
var branches = new Dictionary < string , ConfigBranch > ( ) ;
404
- LoadBranchesFromConfig ( branches , repositoryPaths . BranchesPath , config . GetBranches ( ) . Where ( x => x . IsTracking ) , "" ) ;
456
+ UpdateLocalBranches ( branches , repositoryPaths . BranchesPath , config . GetBranches ( ) . Where ( x => x . IsTracking ) , "" ) ;
405
457
406
458
Logger . Trace ( "OnLocalBranchListUpdated {0} branches" , branches . Count ) ;
407
459
OnLocalBranchListUpdated ? . Invoke ( branches ) ;
408
460
}
409
461
410
- private void LoadBranchesFromConfig ( Dictionary < string , ConfigBranch > branches , NPath path , IEnumerable < ConfigBranch > configBranches , string prefix )
462
+ private void UpdateLocalBranches ( Dictionary < string , ConfigBranch > branches , NPath path , IEnumerable < ConfigBranch > configBranches , string prefix )
411
463
{
412
464
foreach ( var file in path . Files ( ) )
413
465
{
@@ -423,13 +475,13 @@ private void LoadBranchesFromConfig(Dictionary<string, ConfigBranch> branches, N
423
475
424
476
foreach ( var dir in path . Directories ( ) )
425
477
{
426
- LoadBranchesFromConfig ( branches , dir , configBranches , prefix + dir . FileName + "/" ) ;
478
+ UpdateLocalBranches ( branches , dir , configBranches , prefix + dir . FileName + "/" ) ;
427
479
}
428
480
}
429
481
430
- private void LoadRemotesFromConfig ( )
482
+ private void UpdateRemoteBranches ( )
431
483
{
432
- Logger . Trace ( "LoadRemotesFromConfig " ) ;
484
+ Logger . Trace ( "UpdateRemoteBranches " ) ;
433
485
434
486
var remotes = config . GetRemotes ( ) . ToArray ( ) . ToDictionary ( x => x . Name , x => x ) ;
435
487
var remoteBranches = new Dictionary < string , Dictionary < string , ConfigBranch > > ( ) ;
0 commit comments