@@ -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 ;
@@ -209,25 +212,13 @@ public ITask RemoteAdd(string remote, string url)
209212 {
210213 var task = GitClient . RemoteAdd ( remote , url ) ;
211214 task = HookupHandlers ( task , true , false ) ;
212- if ( ! platform . Environment . IsWindows )
213- {
214- task . Then ( _ => {
215- UpdateConfigData ( true ) ;
216- } ) ;
217- }
218215 return task ;
219216 }
220217
221218 public ITask RemoteRemove ( string remote )
222219 {
223220 var task = GitClient . RemoteRemove ( remote ) ;
224221 task = HookupHandlers ( task , true , false ) ;
225- if ( ! platform . Environment . IsWindows )
226- {
227- task . Then ( _ => {
228- UpdateConfigData ( true ) ;
229- } ) ;
230- }
231222 return task ;
232223 }
233224
@@ -258,13 +249,13 @@ public ITask CreateBranch(string branch, string baseBranch)
258249 public ITask LockFile ( string file )
259250 {
260251 var task = GitClient . Lock ( file ) ;
261- return HookupHandlers ( task , true , false ) ;
252+ return HookupHandlers ( task , true , false ) . Then ( UpdateLocks ) ;
262253 }
263254
264255 public ITask UnlockFile ( string file , bool force )
265256 {
266257 var task = GitClient . Unlock ( file , force ) ;
267- return HookupHandlers ( task , true , false ) ;
258+ return HookupHandlers ( task , true , false ) . Then ( UpdateLocks ) ;
268259 }
269260
270261 public void UpdateGitLog ( )
@@ -293,6 +284,33 @@ public void UpdateGitStatus()
293284 } ) . Start ( ) ;
294285 }
295286
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+
296314 public void UpdateLocks ( )
297315 {
298316 var task = GitClient . ListLocks ( false ) ;
@@ -357,15 +375,33 @@ private void SetupWatcher()
357375
358376 private void UpdateHead ( )
359377 {
360- var head = repositoryPaths . DotGitHead . ReadAllLines ( ) . FirstOrDefault ( ) ;
361- Logger . Trace ( "UpdateHead: {0}" , head ?? "[NULL]" ) ;
362- UpdateCurrentBranchAndRemote ( head ) ;
378+ Logger . Trace ( "UpdateHead" ) ;
379+ UpdateCurrentBranchAndRemote ( ) ;
380+ UpdateGitLog ( ) ;
381+ }
382+
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 ) ;
363397 }
364398
365- private void UpdateCurrentBranchAndRemote ( string head )
399+ private void GetCurrentBranchAndRemote ( out ConfigBranch ? branch , out ConfigRemote ? remote )
366400 {
367- ConfigBranch ? branch = null ;
401+ branch = null ;
402+ remote = null ;
368403
404+ var head = GetCurrentHead ( ) ;
369405 if ( head . StartsWith ( "ref:" ) )
370406 {
371407 var branchName = head . Substring ( head . IndexOf ( "refs/heads/" ) + "refs/heads/" . Length ) ;
@@ -378,7 +414,6 @@ private void UpdateCurrentBranchAndRemote(string head)
378414 }
379415
380416 var defaultRemote = "origin" ;
381- ConfigRemote ? remote = null ;
382417
383418 if ( branch . HasValue && branch . Value . IsTracking )
384419 {
@@ -398,10 +433,6 @@ private void UpdateCurrentBranchAndRemote(string head)
398433 remote = configRemotes . FirstOrDefault ( ) ;
399434 }
400435 }
401-
402- Logger . Trace ( "CurrentBranch: {0}" , branch . HasValue ? branch . Value . ToString ( ) : "[NULL]" ) ;
403- Logger . Trace ( "CurrentRemote: {0}" , remote . HasValue ? remote . Value . ToString ( ) : "[NULL]" ) ;
404- CurrentBranchUpdated ? . Invoke ( branch , remote ) ;
405436 }
406437
407438 private void WatcherOnRemoteBranchesChanged ( )
@@ -420,6 +451,7 @@ private void WatcherOnRepositoryCommitted()
420451 {
421452 Logger . Trace ( "WatcherOnRepositoryCommitted" ) ;
422453 UpdateGitLog ( ) ;
454+ UpdateGitAheadBehindStatus ( ) ;
423455 }
424456
425457 private void WatcherOnRepositoryChanged ( )
@@ -518,6 +550,8 @@ private void UpdateRemoteBranches()
518550
519551 Logger . Trace ( "OnRemoteBranchListUpdated {0} remotes" , remotes . Count ) ;
520552 RemoteBranchesUpdated ? . Invoke ( remotes , remoteBranches ) ;
553+
554+ UpdateGitAheadBehindStatus ( ) ;
521555 }
522556
523557 private bool disposed ;
0 commit comments