@@ -35,12 +35,14 @@ public interface IRepositoryManager : IDisposable
3535 ITask UnlockFile ( string file , bool force ) ;
3636 void UpdateGitLog ( ) ;
3737 void UpdateGitStatus ( ) ;
38+ void UpdateGitAheadBehindStatus ( ) ;
3839 void UpdateLocks ( ) ;
3940 int WaitForEvents ( ) ;
4041
4142 IGitConfig Config { get ; }
4243 IGitClient GitClient { get ; }
4344 bool IsBusy { get ; }
45+ event Action < GitAheadBehindStatus > GitAheadBehindStatusUpdated ;
4446 }
4547
4648 interface IRepositoryPathConfiguration
@@ -101,6 +103,7 @@ class RepositoryManager : IRepositoryManager
101103 public event Action < ConfigBranch ? , ConfigRemote ? > CurrentBranchUpdated ;
102104 public event Action < bool > IsBusyChanged ;
103105 public event Action < GitStatus > GitStatusUpdated ;
106+ public event Action < GitAheadBehindStatus > GitAheadBehindStatusUpdated ;
104107 public event Action < List < GitLock > > GitLocksUpdated ;
105108 public event Action < List < GitLogEntry > > GitLogUpdated ;
106109 public event Action < Dictionary < string , ConfigBranch > > LocalBranchesUpdated ;
@@ -281,6 +284,33 @@ public void UpdateGitStatus()
281284 } ) . Start ( ) ;
282285 }
283286
287+ public void UpdateGitAheadBehindStatus ( )
288+ {
289+ ConfigBranch ? configBranch ;
290+ ConfigRemote ? configRemote ;
291+ GetCurrentBranchAndRemote ( out configBranch , out configRemote ) ;
292+
293+ if ( configBranch . HasValue && configBranch . Value . Remote . HasValue )
294+ {
295+ var name = configBranch . Value . Name ;
296+ var trackingName = configBranch . Value . IsTracking ? configBranch . Value . Remote . Value . Name + "/" + name : "[None]" ;
297+
298+ var task = GitClient . AheadBehindStatus ( name , trackingName ) ;
299+ task = HookupHandlers ( task , true , false ) ;
300+ task . Then ( ( success , status ) =>
301+ {
302+ if ( success )
303+ {
304+ GitAheadBehindStatusUpdated ? . Invoke ( status ) ;
305+ }
306+ } ) . Start ( ) ;
307+ }
308+ else
309+ {
310+ GitAheadBehindStatusUpdated ? . Invoke ( GitAheadBehindStatus . Default ) ;
311+ }
312+ }
313+
284314 public void UpdateLocks ( )
285315 {
286316 var task = GitClient . ListLocks ( false ) ;
@@ -345,16 +375,33 @@ private void SetupWatcher()
345375
346376 private void UpdateHead ( )
347377 {
348- var head = repositoryPaths . DotGitHead . ReadAllLines ( ) . FirstOrDefault ( ) ;
349- Logger . Trace ( "UpdateHead: {0}" , head ?? "[NULL]" ) ;
350- UpdateCurrentBranchAndRemote ( head ) ;
378+ Logger . Trace ( "UpdateHead" ) ;
379+ UpdateCurrentBranchAndRemote ( ) ;
351380 UpdateGitLog ( ) ;
352381 }
353382
354- private void UpdateCurrentBranchAndRemote ( string head )
383+ private string GetCurrentHead ( )
384+ {
385+ return repositoryPaths . DotGitHead . ReadAllLines ( ) . FirstOrDefault ( ) ;
386+ }
387+
388+ private void UpdateCurrentBranchAndRemote ( )
389+ {
390+ ConfigBranch ? branch ;
391+ ConfigRemote ? remote ;
392+ GetCurrentBranchAndRemote ( out branch , out remote ) ;
393+
394+ Logger . Trace ( "CurrentBranch: {0}" , branch . HasValue ? branch . Value . ToString ( ) : "[NULL]" ) ;
395+ Logger . Trace ( "CurrentRemote: {0}" , remote . HasValue ? remote . Value . ToString ( ) : "[NULL]" ) ;
396+ CurrentBranchUpdated ? . Invoke ( branch , remote ) ;
397+ }
398+
399+ private void GetCurrentBranchAndRemote ( out ConfigBranch ? branch , out ConfigRemote ? remote )
355400 {
356- ConfigBranch ? branch = null ;
401+ branch = null ;
402+ remote = null ;
357403
404+ var head = GetCurrentHead ( ) ;
358405 if ( head . StartsWith ( "ref:" ) )
359406 {
360407 var branchName = head . Substring ( head . IndexOf ( "refs/heads/" ) + "refs/heads/" . Length ) ;
@@ -367,7 +414,6 @@ private void UpdateCurrentBranchAndRemote(string head)
367414 }
368415
369416 var defaultRemote = "origin" ;
370- ConfigRemote ? remote = null ;
371417
372418 if ( branch . HasValue && branch . Value . IsTracking )
373419 {
@@ -387,10 +433,6 @@ private void UpdateCurrentBranchAndRemote(string head)
387433 remote = configRemotes . FirstOrDefault ( ) ;
388434 }
389435 }
390-
391- Logger . Trace ( "CurrentBranch: {0}" , branch . HasValue ? branch . Value . ToString ( ) : "[NULL]" ) ;
392- Logger . Trace ( "CurrentRemote: {0}" , remote . HasValue ? remote . Value . ToString ( ) : "[NULL]" ) ;
393- CurrentBranchUpdated ? . Invoke ( branch , remote ) ;
394436 }
395437
396438 private void WatcherOnRemoteBranchesChanged ( )
@@ -409,6 +451,7 @@ private void WatcherOnRepositoryCommitted()
409451 {
410452 Logger . Trace ( "WatcherOnRepositoryCommitted" ) ;
411453 UpdateGitLog ( ) ;
454+ UpdateGitAheadBehindStatus ( ) ;
412455 }
413456
414457 private void WatcherOnRepositoryChanged ( )
@@ -507,6 +550,8 @@ private void UpdateRemoteBranches()
507550
508551 Logger . Trace ( "OnRemoteBranchListUpdated {0} remotes" , remotes . Count ) ;
509552 RemoteBranchesUpdated ? . Invoke ( remotes , remoteBranches ) ;
553+
554+ UpdateGitAheadBehindStatus ( ) ;
510555 }
511556
512557 private bool disposed ;
0 commit comments