Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 6f10366

Browse files
Moving the check for AheadBehindStatus to RepositoryManager
1 parent 476cad3 commit 6f10366

File tree

4 files changed

+74
-21
lines changed

4 files changed

+74
-21
lines changed

src/GitHub.Api/Git/Repository.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,6 @@ private void RepositoryManagerOnRemoteBranchesUpdated(Dictionary<string, ConfigR
411411
cacheContainer.BranchCache.SetRemotes(remotes, branches);
412412
Remotes = ConfigRemotes.Values.Select(GetGitRemote).ToArray();
413413
RemoteBranches = RemoteConfigBranches.Values.SelectMany(x => x.Values).Select(GetRemoteGitBranch).ToArray();
414-
415-
var currentBranch = CurrentBranch;
416-
if(!string.IsNullOrEmpty(currentBranch?.Tracking))
417-
{
418-
repositoryManager.UpdateGitAheadBehindStatus(currentBranch.Value.name, currentBranch.Value.tracking);
419-
}
420414
}) { Affinity = TaskAffinity.UI }.Start();
421415
}
422416

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -361,16 +361,33 @@ private void SetupWatcher()
361361

362362
private void UpdateHead()
363363
{
364-
var head = repositoryPaths.DotGitHead.ReadAllLines().FirstOrDefault();
365-
Logger.Trace("UpdateHead: {0}", head ?? "[NULL]");
366-
UpdateCurrentBranchAndRemote(head);
364+
Logger.Trace("UpdateHead");
365+
UpdateCurrentBranchAndRemote();
367366
UpdateGitLog();
368367
}
369368

370-
private void UpdateCurrentBranchAndRemote(string head)
369+
private string GetCurrentHead()
371370
{
372-
ConfigBranch? branch = null;
371+
return repositoryPaths.DotGitHead.ReadAllLines().FirstOrDefault();
372+
}
373+
374+
private void UpdateCurrentBranchAndRemote()
375+
{
376+
ConfigBranch? branch;
377+
ConfigRemote? remote;
378+
GetCurrentBranchAndRemote(out branch, out remote);
379+
380+
Logger.Trace("CurrentBranch: {0}", branch.HasValue ? branch.Value.ToString() : "[NULL]");
381+
Logger.Trace("CurrentRemote: {0}", remote.HasValue ? remote.Value.ToString() : "[NULL]");
382+
CurrentBranchUpdated?.Invoke(branch, remote);
383+
}
384+
385+
private void GetCurrentBranchAndRemote(out ConfigBranch? branch, out ConfigRemote? remote)
386+
{
387+
branch = null;
388+
remote = null;
373389

390+
var head = GetCurrentHead();
374391
if (head.StartsWith("ref:"))
375392
{
376393
var branchName = head.Substring(head.IndexOf("refs/heads/") + "refs/heads/".Length);
@@ -383,7 +400,6 @@ private void UpdateCurrentBranchAndRemote(string head)
383400
}
384401

385402
var defaultRemote = "origin";
386-
ConfigRemote? remote = null;
387403

388404
if (branch.HasValue && branch.Value.IsTracking)
389405
{
@@ -403,10 +419,6 @@ private void UpdateCurrentBranchAndRemote(string head)
403419
remote = configRemotes.FirstOrDefault();
404420
}
405421
}
406-
407-
Logger.Trace("CurrentBranch: {0}", branch.HasValue ? branch.Value.ToString() : "[NULL]");
408-
Logger.Trace("CurrentRemote: {0}", remote.HasValue ? remote.Value.ToString() : "[NULL]");
409-
CurrentBranchUpdated?.Invoke(branch, remote);
410422
}
411423

412424
private void WatcherOnRemoteBranchesChanged()
@@ -523,6 +535,18 @@ private void UpdateRemoteBranches()
523535

524536
Logger.Trace("OnRemoteBranchListUpdated {0} remotes", remotes.Count);
525537
RemoteBranchesUpdated?.Invoke(remotes, remoteBranches);
538+
539+
ConfigBranch? configBranch;
540+
ConfigRemote? configRemote;
541+
GetCurrentBranchAndRemote(out configBranch,out configRemote);
542+
543+
if (configBranch.HasValue && configBranch.Value.Remote.HasValue)
544+
{
545+
var name = configBranch.Value.Name;
546+
var trackingName = configBranch.Value.IsTracking ? configBranch.Value.Remote.Value.Name + "/" + name : "[None]";
547+
548+
UpdateGitAheadBehindStatus(name, trackingName);
549+
}
526550
}
527551

528552
private bool disposed;

src/tests/IntegrationTests/Events/RepositoryManagerTests.cs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ await Initialize(TestRepoMasterCleanSynchronized, initializeRepository: false,
4141
repositoryManagerEvents.LocalBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
4242
repositoryManagerEvents.RemoteBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
4343
repositoryManagerEvents.GitLogUpdated.WaitOne(Timeout).Should().BeTrue();
44+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
45+
repositoryManagerEvents.IsBusy.WaitOne(Timeout).Should().BeTrue();
46+
repositoryManagerEvents.IsNotBusy.WaitOne(Timeout).Should().BeTrue();
4447

45-
repositoryManagerListener.DidNotReceive().OnIsBusyChanged(Args.Bool);
48+
repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool);
4649
repositoryManagerListener.Received().CurrentBranchUpdated(Args.NullableConfigBranch, Args.NullableConfigRemote);
47-
repositoryManagerListener.DidNotReceive().GitAheadBehindStatusUpdated(Args.GitAheadBehindStatus);
50+
repositoryManagerListener.Received().GitAheadBehindStatusUpdated(Args.GitAheadBehindStatus);
4851
repositoryManagerListener.DidNotReceive().GitStatusUpdated(Args.GitStatus);
4952
repositoryManagerListener.DidNotReceive().GitLocksUpdated(Args.GitLocks);
5053
repositoryManagerListener.Received().GitLogUpdated(Args.GitLogs);
@@ -75,6 +78,9 @@ await Initialize(TestRepoMasterCleanSynchronized, initializeRepository: false,
7578
repositoryManagerEvents.LocalBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
7679
repositoryManagerEvents.RemoteBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
7780
repositoryManagerEvents.GitLogUpdated.WaitOne(Timeout).Should().BeTrue();
81+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
82+
repositoryManagerEvents.IsBusy.WaitOne(Timeout).Should().BeTrue();
83+
repositoryManagerEvents.IsNotBusy.WaitOne(Timeout).Should().BeTrue();
7884

7985
repositoryManagerListener.ClearReceivedCalls();
8086
repositoryManagerEvents.Reset();
@@ -122,6 +128,9 @@ await Initialize(TestRepoMasterCleanSynchronized, initializeRepository: false,
122128
repositoryManagerEvents.LocalBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
123129
repositoryManagerEvents.RemoteBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
124130
repositoryManagerEvents.GitLogUpdated.WaitOne(Timeout).Should().BeTrue();
131+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
132+
repositoryManagerEvents.IsBusy.WaitOne(Timeout).Should().BeTrue();
133+
repositoryManagerEvents.IsNotBusy.WaitOne(Timeout).Should().BeTrue();
125134

126135
repositoryManagerListener.ClearReceivedCalls();
127136
repositoryManagerEvents.Reset();
@@ -196,6 +205,9 @@ await Initialize(TestRepoMasterCleanSynchronized, initializeRepository: false,
196205
repositoryManagerEvents.LocalBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
197206
repositoryManagerEvents.RemoteBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
198207
repositoryManagerEvents.GitLogUpdated.WaitOne(Timeout).Should().BeTrue();
208+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
209+
repositoryManagerEvents.IsBusy.WaitOne(Timeout).Should().BeTrue();
210+
repositoryManagerEvents.IsNotBusy.WaitOne(Timeout).Should().BeTrue();
199211

200212
repositoryManagerListener.ClearReceivedCalls();
201213
repositoryManagerEvents.Reset();
@@ -269,6 +281,9 @@ await Initialize(TestRepoMasterCleanSynchronized, initializeRepository: false,
269281
repositoryManagerEvents.LocalBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
270282
repositoryManagerEvents.RemoteBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
271283
repositoryManagerEvents.GitLogUpdated.WaitOne(Timeout).Should().BeTrue();
284+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
285+
repositoryManagerEvents.IsBusy.WaitOne(Timeout).Should().BeTrue();
286+
repositoryManagerEvents.IsNotBusy.WaitOne(Timeout).Should().BeTrue();
272287

273288
repositoryManagerListener.ClearReceivedCalls();
274289
repositoryManagerEvents.Reset();
@@ -316,6 +331,9 @@ await Initialize(TestRepoMasterCleanSynchronized, initializeRepository: false,
316331
repositoryManagerEvents.LocalBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
317332
repositoryManagerEvents.RemoteBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
318333
repositoryManagerEvents.GitLogUpdated.WaitOne(Timeout).Should().BeTrue();
334+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
335+
repositoryManagerEvents.IsBusy.WaitOne(Timeout).Should().BeTrue();
336+
repositoryManagerEvents.IsNotBusy.WaitOne(Timeout).Should().BeTrue();
319337

320338
repositoryManagerListener.ClearReceivedCalls();
321339
repositoryManagerEvents.Reset();
@@ -363,6 +381,9 @@ await Initialize(TestRepoMasterCleanSynchronized, initializeRepository: false,
363381
repositoryManagerEvents.LocalBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
364382
repositoryManagerEvents.RemoteBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
365383
repositoryManagerEvents.GitLogUpdated.WaitOne(Timeout).Should().BeTrue();
384+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
385+
repositoryManagerEvents.IsBusy.WaitOne(Timeout).Should().BeTrue();
386+
repositoryManagerEvents.IsNotBusy.WaitOne(Timeout).Should().BeTrue();
366387

367388
repositoryManagerListener.ClearReceivedCalls();
368389

@@ -428,6 +449,9 @@ await Initialize(TestRepoMasterCleanSynchronized, initializeRepository: false,
428449
repositoryManagerEvents.LocalBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
429450
repositoryManagerEvents.RemoteBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
430451
repositoryManagerEvents.GitLogUpdated.WaitOne(Timeout).Should().BeTrue();
452+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
453+
repositoryManagerEvents.IsBusy.WaitOne(Timeout).Should().BeTrue();
454+
repositoryManagerEvents.IsNotBusy.WaitOne(Timeout).Should().BeTrue();
431455

432456
repositoryManagerListener.ClearReceivedCalls();
433457
repositoryManagerEvents.Reset();
@@ -498,6 +522,9 @@ await Initialize(TestRepoMasterTwoRemotes, initializeRepository: false,
498522
repositoryManagerEvents.LocalBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
499523
repositoryManagerEvents.RemoteBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
500524
repositoryManagerEvents.GitLogUpdated.WaitOne(Timeout).Should().BeTrue();
525+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
526+
repositoryManagerEvents.IsBusy.WaitOne(Timeout).Should().BeTrue();
527+
repositoryManagerEvents.IsNotBusy.WaitOne(Timeout).Should().BeTrue();
501528

502529
repositoryManagerListener.ClearReceivedCalls();
503530
repositoryManagerEvents.Reset();
@@ -512,11 +539,12 @@ await RepositoryManager.CreateBranch("branch2", "another/master")
512539
repositoryManagerEvents.CurrentBranchUpdated.WaitOne(Timeout).Should().BeTrue();
513540
repositoryManagerEvents.LocalBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
514541
repositoryManagerEvents.RemoteBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
542+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
515543
repositoryManagerEvents.GitLogUpdated.WaitOne(Timeout).Should().BeTrue();
516544

517545
repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool);
518546
repositoryManagerListener.Received().CurrentBranchUpdated(Args.NullableConfigBranch, Args.NullableConfigRemote);
519-
repositoryManagerListener.DidNotReceive().GitAheadBehindStatusUpdated(Args.GitAheadBehindStatus);
547+
repositoryManagerListener.Received().GitAheadBehindStatusUpdated(Args.GitAheadBehindStatus);
520548
repositoryManagerListener.DidNotReceive().GitStatusUpdated(Args.GitStatus);
521549
repositoryManagerListener.DidNotReceive().GitLocksUpdated(Args.GitLocks);
522550
repositoryManagerListener.Received().GitLogUpdated(Args.GitLogs);
@@ -569,6 +597,9 @@ await Initialize(TestRepoMasterCleanSynchronized, initializeRepository: false,
569597
repositoryManagerEvents.LocalBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
570598
repositoryManagerEvents.RemoteBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
571599
repositoryManagerEvents.GitLogUpdated.WaitOne(Timeout).Should().BeTrue();
600+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
601+
repositoryManagerEvents.IsBusy.WaitOne(Timeout).Should().BeTrue();
602+
repositoryManagerEvents.IsNotBusy.WaitOne(Timeout).Should().BeTrue();
572603

573604
repositoryManagerListener.ClearReceivedCalls();
574605

@@ -613,6 +644,9 @@ await Initialize(TestRepoMasterCleanUnsynchronized, initializeRepository: false,
613644
repositoryManagerEvents.LocalBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
614645
repositoryManagerEvents.RemoteBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
615646
repositoryManagerEvents.GitLogUpdated.WaitOne(Timeout).Should().BeTrue();
647+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
648+
repositoryManagerEvents.IsBusy.WaitOne(Timeout).Should().BeTrue();
649+
repositoryManagerEvents.IsNotBusy.WaitOne(Timeout).Should().BeTrue();
616650

617651
repositoryManagerListener.ClearReceivedCalls();
618652
repositoryManagerEvents.Reset();
@@ -624,10 +658,11 @@ await Initialize(TestRepoMasterCleanUnsynchronized, initializeRepository: false,
624658
repositoryManagerEvents.WaitForNotBusy();
625659

626660
repositoryManagerEvents.RemoteBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
661+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
627662

628663
repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool);
629664
repositoryManagerListener.DidNotReceive().CurrentBranchUpdated(Args.NullableConfigBranch, Args.NullableConfigRemote);
630-
repositoryManagerListener.DidNotReceive().GitAheadBehindStatusUpdated(Args.GitAheadBehindStatus);
665+
repositoryManagerListener.Received().GitAheadBehindStatusUpdated(Args.GitAheadBehindStatus);
631666
repositoryManagerListener.DidNotReceive().GitStatusUpdated(Args.GitStatus);
632667
repositoryManagerListener.DidNotReceive().GitLocksUpdated(Args.GitLocks);
633668
repositoryManagerListener.DidNotReceive().GitLogUpdated(Args.GitLogs);

src/tests/IntegrationTests/SetUpFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void Setup()
1414

1515
Logging.LogAdapter = new MultipleLogAdapter(
1616
new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-integration-tests.log")
17-
//, new ConsoleLogAdapter()
17+
, new ConsoleLogAdapter()
1818
);
1919
}
2020
}

0 commit comments

Comments
 (0)