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

Commit 5cb93e4

Browse files
Updating GitAheadBehind after commit
1 parent 8a8716a commit 5cb93e4

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public interface IRepositoryManager : IDisposable
3535
ITask UnlockFile(string file, bool force);
3636
void UpdateGitLog();
3737
void UpdateGitStatus();
38-
void UpdateGitAheadBehindStatus(string gitRef, string otherRef);
38+
void UpdateGitAheadBehindStatus();
3939
void UpdateLocks();
4040
int WaitForEvents();
4141

@@ -284,17 +284,27 @@ public void UpdateGitStatus()
284284
}).Start();
285285
}
286286

287-
public void UpdateGitAheadBehindStatus(string gitRef, string otherRef)
287+
public void UpdateGitAheadBehindStatus()
288288
{
289-
var task = GitClient.AheadBehindStatus(gitRef, otherRef);
290-
task = HookupHandlers(task, true, false);
291-
task.Then((success, status) =>
289+
ConfigBranch? configBranch;
290+
ConfigRemote? configRemote;
291+
GetCurrentBranchAndRemote(out configBranch, out configRemote);
292+
293+
if (configBranch.HasValue && configBranch.Value.Remote.HasValue)
292294
{
293-
if (success)
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) =>
294301
{
295-
GitAheadBehindStatusUpdated?.Invoke(status);
296-
}
297-
}).Start();
302+
if (success)
303+
{
304+
GitAheadBehindStatusUpdated?.Invoke(status);
305+
}
306+
}).Start();
307+
}
298308
}
299309

300310
public void UpdateLocks()
@@ -437,6 +447,7 @@ private void WatcherOnRepositoryCommitted()
437447
{
438448
Logger.Trace("WatcherOnRepositoryCommitted");
439449
UpdateGitLog();
450+
UpdateGitAheadBehindStatus();
440451
}
441452

442453
private void WatcherOnRepositoryChanged()
@@ -536,17 +547,7 @@ private void UpdateRemoteBranches()
536547
Logger.Trace("OnRemoteBranchListUpdated {0} remotes", remotes.Count);
537548
RemoteBranchesUpdated?.Invoke(remotes, remoteBranches);
538549

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-
}
550+
UpdateGitAheadBehindStatus();
550551
}
551552

552553
private bool disposed;

src/tests/IntegrationTests/Events/RepositoryManagerTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,11 @@ await RepositoryManager
171171
repositoryManagerEvents.LocalBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
172172
repositoryManagerEvents.GitStatusUpdated.WaitOne(Timeout).Should().BeTrue();
173173
repositoryManagerEvents.GitLogUpdated.WaitOne(Timeout).Should().BeTrue();
174+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
174175

175176
repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool);
176177
repositoryManagerListener.DidNotReceive().CurrentBranchUpdated(Args.NullableConfigBranch, Args.NullableConfigRemote);
177-
repositoryManagerListener.DidNotReceive().GitAheadBehindStatusUpdated(Args.GitAheadBehindStatus);
178+
repositoryManagerListener.Received().GitAheadBehindStatusUpdated(Args.GitAheadBehindStatus);
178179
repositoryManagerListener.Received().GitStatusUpdated(Args.GitStatus);
179180
repositoryManagerListener.DidNotReceive().GitLocksUpdated(Args.GitLocks);
180181
repositoryManagerListener.Received().GitLogUpdated(Args.GitLogs);
@@ -248,10 +249,11 @@ await RepositoryManager
248249
repositoryManagerEvents.GitStatusUpdated.WaitOne(Timeout).Should().BeTrue();
249250
repositoryManagerEvents.LocalBranchesUpdated.WaitOne(Timeout).Should().BeTrue();
250251
repositoryManagerEvents.GitLogUpdated.WaitOne(Timeout).Should().BeTrue();
252+
repositoryManagerEvents.GitAheadBehindStatusUpdated.WaitOne(Timeout).Should().BeTrue();
251253

252254
repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool);
253255
repositoryManagerListener.DidNotReceive().CurrentBranchUpdated(Args.NullableConfigBranch, Args.NullableConfigRemote);
254-
repositoryManagerListener.DidNotReceive().GitAheadBehindStatusUpdated(Args.GitAheadBehindStatus);
256+
repositoryManagerListener.Received().GitAheadBehindStatusUpdated(Args.GitAheadBehindStatus);
255257
repositoryManagerListener.Received().GitStatusUpdated(Args.GitStatus);
256258
repositoryManagerListener.DidNotReceive().GitLocksUpdated(Args.GitLocks);
257259
repositoryManagerListener.Received().GitLogUpdated(Args.GitLogs);

0 commit comments

Comments
 (0)