From f9f2818523f0155a51d542c7fe3756f0cf465456 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Thu, 14 Sep 2017 11:02:23 -0400 Subject: [PATCH 01/57] Starting to refactor --- src/GitHub.Api/Git/IRepository.cs | 4 +- src/GitHub.Api/Git/Repository.cs | 194 ++++++++++++++--- src/GitHub.Api/Git/RepositoryManager.cs | 200 ++++-------------- .../Editor/GitHub.Unity/UI/BranchesView.cs | 8 +- .../Editor/GitHub.Unity/UI/HistoryView.cs | 8 +- .../Editor/GitHub.Unity/UI/SettingsView.cs | 4 +- .../Events/RepositoryManagerTests.cs | 34 --- .../Events/IRepositoryManagerListener.cs | 20 -- .../Repository/RepositoryManagerTests.cs | 8 - 9 files changed, 227 insertions(+), 253 deletions(-) diff --git a/src/GitHub.Api/Git/IRepository.cs b/src/GitHub.Api/Git/IRepository.cs index f55902b54..b51e4faee 100644 --- a/src/GitHub.Api/Git/IRepository.cs +++ b/src/GitHub.Api/Git/IRepository.cs @@ -58,8 +58,8 @@ interface IRepository : IEquatable string CurrentBranchName { get; } event Action OnStatusUpdated; - event Action OnActiveBranchChanged; - event Action OnActiveRemoteChanged; + event Action OnCurrentBranchChanged; + event Action OnCurrentRemoteChanged; event Action OnLocalBranchListChanged; event Action OnHeadChanged; event Action> OnLocksUpdated; diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 24ed96b67..0e99444e6 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -14,20 +14,42 @@ class Repository : IRepository, IEquatable private ConfigBranch? currentBranch; private ConfigRemote? currentRemote; private GitStatus currentStatus; + private string head; + + private Dictionary localBranches = new Dictionary(); + + private IEnumerable locks; + private Dictionary> remoteBranches = new Dictionary>(); + private Dictionary remotes; public event Action OnStatusUpdated; - public event Action OnActiveBranchChanged; - public event Action OnActiveRemoteChanged; + public event Action OnCurrentBranchChanged; + public event Action OnCurrentRemoteChanged; public event Action OnLocalBranchListChanged; + public event Action OnRemoteBranchListChanged; public event Action OnHeadChanged; public event Action> OnLocksUpdated; public event Action OnRepositoryInfoChanged; - public IEnumerable LocalBranches => repositoryManager.LocalBranches.Values.Select( - x => new GitBranch(x.Name, (x.IsTracking ? (x.Remote.Value.Name + "/" + x.Name) : "[None]"), x.Name == CurrentBranch?.Name)); + public IEnumerable LocalBranches + { + get + { + throw new NotImplementedException(); +// return repositoryManager.LocalBranches.Values.Select(x => new GitBranch(x.Name, +// (x.IsTracking ? (x.Remote.Value.Name + "/" + x.Name) : "[None]"), x.Name == CurrentBranch?.Name)); + } + } - public IEnumerable RemoteBranches => repositoryManager.RemoteBranches.Values.SelectMany( - x => x.Values).Select(x => new GitBranch(x.Remote.Value.Name + "/" + x.Name, "[None]", false)); + public IEnumerable RemoteBranches + { + get + { + throw new NotImplementedException(); +// return repositoryManager.RemoteBranches.Values.SelectMany(x => x.Values).Select(x => +// new GitBranch(x.Remote.Value.Name + "/" + x.Name, "[None]", false)); + } + } /// /// Initializes a new instance of the class. @@ -51,12 +73,15 @@ public void Initialize(IRepositoryManager repositoryManager) Guard.ArgumentNotNull(repositoryManager, nameof(repositoryManager)); this.repositoryManager = repositoryManager; - repositoryManager.OnLocalBranchListChanged += RepositoryManager_OnLocalBranchListChanged; - repositoryManager.OnCommitChanged += RepositoryManager_OnHeadChanged; - repositoryManager.OnLocksUpdated += RepositoryManager_OnLocksUpdated; + + repositoryManager.OnHeadUpdated += RepositoryManager_OnHeadUpdated; repositoryManager.OnStatusUpdated += RepositoryManager_OnStatusUpdated; - repositoryManager.OnActiveBranchChanged += RepositoryManager_OnActiveBranchChanged; - repositoryManager.OnActiveRemoteChanged += RepositoryManager_OnActiveRemoteChanged; + repositoryManager.OnLocksUpdated += RepositoryManager_OnLocksUpdated; + repositoryManager.OnLocalBranchListUpdated += RepositoryManager_OnLocalBranchListUpdated; + repositoryManager.OnRemoteBranchListUpdated += RepositoryManager_OnRemoteBranchListUpdated; + repositoryManager.OnUpdateLocalBranch += RepositoryManager_OnUpdateLocalBranch; + repositoryManager.OnAddLocalBranch += RepositoryManager_OnAddLocalBranch; + repositoryManager.OnRemoveLocalBranch += RepositoryManager_OnRemoveLocalBranch; repositoryManager.OnGitUserLoaded += user => User = user; } @@ -149,30 +174,151 @@ private void RepositoryManager_OnStatusUpdated(GitStatus status) CurrentStatus = status; } - private void RepositoryManager_OnActiveRemoteChanged(ConfigRemote? remote) + private void RepositoryManager_OnLocksUpdated(IEnumerable locks) + { + CurrentLocks = locks; + OnLocksUpdated?.Invoke(CurrentLocks); + } + + private void RepositoryManager_OnHeadUpdated(string h) + { + if (head != h) + { + head = h; + var branch = GetCurrentBranch(); + var remote = GetCurrentRemote(); + + if (!Nullable.Equals(currentBranch, branch)) + { + currentBranch = branch; + OnCurrentBranchChanged?.Invoke(currentBranch.HasValue ? currentBranch.Value.Name : null); + } + + if (!Nullable.Equals(currentRemote, remote)) + { + currentRemote = remote; + OnCurrentRemoteChanged?.Invoke(currentRemote.HasValue ? currentRemote.Value.Name : null); + } + } + } + + private void RepositoryManager_OnRemoteBranchListUpdated(Dictionary> branches) { - CurrentRemote = remote; + remoteBranches = branches; + OnRemoteBranchListChanged?.Invoke(); } - private void RepositoryManager_OnActiveBranchChanged(ConfigBranch? branch) + private void RepositoryManager_OnLocalBranchListUpdated(Dictionary obj) { - CurrentBranch = branch; + localBranches = obj; } - private void RepositoryManager_OnHeadChanged() + private void RepositoryManager_OnRemoveLocalBranch(string name) { - OnHeadChanged?.Invoke(); + if (localBranches.ContainsKey(name)) + { + localBranches.Remove(name); + OnLocalBranchListChanged?.Invoke(); + } } - private void RepositoryManager_OnLocalBranchListChanged() + private void RepositoryManager_OnAddLocalBranch(string name) { - OnLocalBranchListChanged?.Invoke(); + if (!localBranches.ContainsKey(name)) + { + var branch = repositoryManager.Config.GetBranch(name); + if (!branch.HasValue) + { + branch = new ConfigBranch { Name = name }; + } + localBranches.Add(name, branch.Value); + OnLocalBranchListChanged?.Invoke(); + } } - private void RepositoryManager_OnLocksUpdated(IEnumerable locks) + private void RepositoryManager_OnUpdateLocalBranch(string name) { - CurrentLocks = locks; - OnLocksUpdated?.Invoke(CurrentLocks); + if (name == currentBranch?.Name) + { + // commit of current branch changed, trigger OnHeadChanged + OnHeadChanged?.Invoke(); + repositoryManager.Refresh(); + } + } + + + private void AddRemoteBranch(string remote, string name) + { + Dictionary branchList = null; + if (remoteBranches.TryGetValue(remote, out branchList)) + { + if (!branchList.ContainsKey(name)) + { + branchList.Add(name, new ConfigBranch { Name = name, Remote = remotes[remote] }); + OnRemoteBranchListChanged?.Invoke(); + } + } + } + + private void RemoveRemoteBranch(string remote, string name) + { + Dictionary branchList = null; + if (remoteBranches.TryGetValue(remote, out branchList)) + { + if (localBranches.ContainsKey(name)) + { + localBranches.Remove(name); + OnRemoteBranchListChanged?.Invoke(); + } + } + } + + private ConfigBranch? GetCurrentBranch() + { + if (head.StartsWith("ref:")) + { + var branch = head.Substring(head.IndexOf("refs/heads/") + "refs/heads/".Length); + currentBranch = GetBranch(branch); + } + else + { + currentBranch = null; + } + return currentBranch; + } + + private ConfigBranch? GetBranch(string name) + { + if (localBranches.ContainsKey(name)) + { + return localBranches[name]; + } + + return null; + } + + private ConfigRemote? GetCurrentRemote(string defaultRemote = "origin") + { + if (currentBranch.HasValue && currentBranch.Value.IsTracking) + { + return currentBranch.Value.Remote; + } + + var remote = repositoryManager.Config.GetRemote(defaultRemote); + if (remote.HasValue) + { + return remote; + } + + using (var remoteEnumerator = repositoryManager.Config.GetRemotes().GetEnumerator()) + { + if (remoteEnumerator.MoveNext()) + { + return remoteEnumerator.Current; + } + } + + return null; } /// @@ -215,7 +361,7 @@ public ConfigBranch? CurrentBranch { currentBranch = value; Logger.Trace("OnActiveBranchChanged: {0}", value?.ToString() ?? "NULL"); - OnActiveBranchChanged?.Invoke(CurrentBranch.HasValue ? CurrentBranch.Value.Name : null); + OnCurrentBranchChanged?.Invoke(CurrentBranch.HasValue ? CurrentBranch.Value.Name : null); } } } @@ -238,7 +384,7 @@ public ConfigRemote? CurrentRemote currentRemote = value; SetCloneUrl(); Logger.Trace("OnActiveRemoteChanged: {0}", value?.ToString() ?? "NULL"); - OnActiveRemoteChanged?.Invoke(CurrentRemote.HasValue ? CurrentRemote.Value.Name : null); + OnCurrentRemoteChanged?.Invoke(CurrentRemote.HasValue ? CurrentRemote.Value.Name : null); } } } diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index 0caf78850..fa21a1630 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -9,18 +9,18 @@ namespace GitHub.Unity interface IRepositoryManager : IDisposable { event Action OnIsBusyChanged; - - event Action OnCommitChanged; - event Action OnLocalBranchListChanged; - event Action OnRemoteBranchListChanged; + event Action OnHeadUpdated; event Action OnStatusUpdated; - event Action OnActiveBranchChanged; - event Action OnActiveRemoteChanged; + event Action> OnLocksUpdated; + event Action> OnLocalBranchListUpdated; + event Action>> OnRemoteBranchListUpdated; + event Action OnUpdateLocalBranch; + event Action OnAddLocalBranch; + event Action OnRemoveLocalBranch; + event Action OnRemoteBranchAdded; + event Action OnRemoteBranchDeleted; event Action OnGitUserLoaded; - event Action> OnLocksUpdated; - Dictionary LocalBranches { get; } - Dictionary> RemoteBranches { get; } IGitConfig Config { get; } IGitClient GitClient { get; } bool IsBusy { get; } @@ -92,7 +92,6 @@ public RepositoryPathConfiguration(NPath repositoryPath) class RepositoryManager : IRepositoryManager { - private readonly Dictionary branches = new Dictionary(); private readonly CancellationToken cancellationToken; private readonly IGitConfig config; private readonly IGitClient gitClient; @@ -102,28 +101,26 @@ class RepositoryManager : IRepositoryManager private readonly IUsageTracker usageTracker; private readonly IRepositoryWatcher watcher; - private string head; private bool isBusy; - private IEnumerable locks; - private Dictionary> remoteBranches = new Dictionary>(); - private Dictionary remotes; private Action repositoryUpdateCallback; - private ConfigBranch? activeBranch; // internal busy flag signal public event Action OnIsBusyChanged; - // branches loaded from config file - public event Action OnLocalBranchListChanged; - public event Action OnRemoteBranchListChanged; + public event Action> OnLocalBranchListUpdated; + public event Action>> OnRemoteBranchListUpdated; public event Action> OnLocksUpdated; - public event Action OnCommitChanged; +// public event Action OnCommitChanged; public event Action OnStatusUpdated; - public event Action OnActiveBranchChanged; - public event Action OnActiveRemoteChanged; + public event Action OnHeadUpdated; + public event Action OnUpdateLocalBranch; + public event Action OnAddLocalBranch; + public event Action OnRemoveLocalBranch; public event Action OnGitUserLoaded; + public event Action OnRemoteBranchAdded; + public event Action OnRemoteBranchDeleted; public static RepositoryManager CreateInstance(IPlatform platform, ITaskManager taskManager, IUsageTracker usageTracker, IGitClient gitClient, NPath repositoryRoot) @@ -164,8 +161,8 @@ public void Start() { Logger.Trace("Start"); - ReadHead(); - RefreshConfigData(); + UpdateHead(); + UpdateConfigData(); LoadGitUser(); watcher.Start(); } @@ -249,7 +246,7 @@ public ITask RemoteAdd(string remote, string url) if (!platform.Environment.IsWindows) { task.Then(_ => { - RefreshConfigData(true); + UpdateConfigData(true); }); } return task; @@ -262,7 +259,7 @@ public ITask RemoteRemove(string remote) if (!platform.Environment.IsWindows) { task.Then(_ => { - RefreshConfigData(true); + UpdateConfigData(true); }); } return task; @@ -298,11 +295,10 @@ public ITask ListLocks(bool local) .ListLocks(local) .Then((s, t) => { - if (locks == null || !locks.SequenceEqual(t)) + if (s) { - locks = t; Logger.Trace("OnLocksUpdated"); - OnLocksUpdated(locks); + OnLocksUpdated?.Invoke(t); } }); return HookupHandlers(task); @@ -348,9 +344,10 @@ private void SetupWatcher() watcher.RemoteBranchDeleted += Watcher_OnRemoteBranchDeleted; } - private void ReadHead() + private void UpdateHead() { - head = repositoryPaths.DotGitHead.ReadAllLines().FirstOrDefault(); + var head = repositoryPaths.DotGitHead.ReadAllLines().FirstOrDefault(); + OnHeadUpdated?.Invoke(head); } private ITask HookupHandlers(ITask task, bool disableWatcher = false) @@ -380,12 +377,12 @@ private ITask HookupHandlers(ITask task, bool disableWatcher = false) private void Watcher_OnRemoteBranchDeleted(string remote, string name) { - RemoveRemoteBranch(remote, name); + OnRemoteBranchDeleted?.Invoke(remote, name); } private void Watcher_OnRemoteBranchCreated(string remote, string name) { - AddRemoteBranch(remote, name); + OnRemoteBranchAdded?.Invoke(remote, name); } private void Watcher_OnRepositoryChanged() @@ -400,12 +397,12 @@ private void UpdateGitStatus() var task = GitClient.Status() .Finally((success, ex, data) => { - Logger.Trace($"GitStatus update: {success} {(data.HasValue ? data.Value.ToString() : "null")}"); + Logger.Trace($"GitStatus update: {success} {(data.HasValue ? data.Value.ToString() : "[null]")}"); if (success && data.HasValue) { OnStatusUpdated?.Invoke(data.Value); + Logger.Trace("Updated Git Status"); } - Logger.Trace("Updated Git Status"); }); HookupHandlers(task).Start(); @@ -413,15 +410,13 @@ private void UpdateGitStatus() private void Watcher_OnConfigChanged() { - RefreshConfigData(true); + UpdateConfigData(true); } private void Watcher_OnHeadChanged(string contents) { Logger.Trace("Watcher_OnHeadChanged"); - head = contents; - OnActiveBranchChanged?.Invoke(GetActiveBranch()); - OnActiveRemoteChanged?.Invoke(GetActiveRemote()); + OnHeadUpdated?.Invoke(contents); UpdateGitStatus(); } @@ -430,25 +425,20 @@ private void Watcher_OnIndexChanged() private void Watcher_OnLocalBranchCreated(string name) { - AddLocalBranch(name); + OnAddLocalBranch?.Invoke(name); } private void Watcher_OnLocalBranchDeleted(string name) { - RemoveLocalBranch(name); + OnRemoveLocalBranch?.Invoke(name); } private void Watcher_OnLocalBranchChanged(string name) { - if (name == activeBranch?.Name) - { - // commit of current branch changed, trigger OnHeadChanged - OnCommitChanged?.Invoke(); - UpdateGitStatus(); - } + OnUpdateLocalBranch?.Invoke(name); } - private void RefreshConfigData(bool resetConfig = false) + private void UpdateConfigData(bool resetConfig = false) { if (resetConfig) { @@ -459,18 +449,16 @@ private void RefreshConfigData(bool resetConfig = false) LoadBranchesFromConfig(); LoadRemotesFromConfig(); - - OnActiveBranchChanged?.Invoke(GetActiveBranch()); - OnActiveRemoteChanged?.Invoke(GetActiveRemote()); } private void LoadBranchesFromConfig() { - branches.Clear(); - LoadBranchesFromConfig(repositoryPaths.BranchesPath, config.GetBranches().Where(x => x.IsTracking), ""); + var branches = new Dictionary(); + LoadBranchesFromConfig(branches, repositoryPaths.BranchesPath, config.GetBranches().Where(x => x.IsTracking), ""); + OnLocalBranchListUpdated?.Invoke(branches); } - private void LoadBranchesFromConfig(NPath path, IEnumerable configBranches, string prefix) + private void LoadBranchesFromConfig(Dictionary branches, NPath path, IEnumerable configBranches, string prefix) { Logger.Trace("LoadBranchesFromConfig"); @@ -488,7 +476,7 @@ private void LoadBranchesFromConfig(NPath path, IEnumerable config foreach (var dir in path.Directories()) { - LoadBranchesFromConfig(dir, configBranches, prefix + dir.FileName + "/"); + LoadBranchesFromConfig(branches, dir, configBranches, prefix + dir.FileName + "/"); } } @@ -496,8 +484,8 @@ private void LoadRemotesFromConfig() { Logger.Trace("LoadRemotesFromConfig"); - remotes = config.GetRemotes().ToDictionary(x => x.Name, x => x); - remoteBranches = new Dictionary>(); + var remotes = config.GetRemotes().ToDictionary(x => x.Name, x => x); + var remoteBranches = new Dictionary>(); foreach (var remote in remotes.Keys) { @@ -516,103 +504,8 @@ private void LoadRemotesFromConfig() remoteBranches.Add(remote, branchList); } } - } - - private ConfigRemote? GetActiveRemote(string defaultRemote = "origin") - { - if (activeBranch.HasValue && activeBranch.Value.IsTracking) - { - return activeBranch.Value.Remote; - } - - var remote = config.GetRemote(defaultRemote); - if (remote.HasValue) - { - return remote; - } - - using (var remoteEnumerator = config.GetRemotes().GetEnumerator()) - { - if (remoteEnumerator.MoveNext()) - { - return remoteEnumerator.Current; - } - } - - return null; - } - - private ConfigBranch? GetActiveBranch() - { - if (head.StartsWith("ref:")) - { - var branch = head.Substring(head.IndexOf("refs/heads/") + "refs/heads/".Length); - activeBranch = GetBranch(branch); - } - else - { - activeBranch = null; - } - return activeBranch; - } - - private ConfigBranch? GetBranch(string name) - { - if (branches.ContainsKey(name)) - { - return branches[name]; - } - - return null; - } - - private void AddLocalBranch(string name) - { - if (!branches.ContainsKey(name)) - { - var branch = config.GetBranch(name); - if (!branch.HasValue) - { - branch = new ConfigBranch { Name = name }; - } - branches.Add(name, branch.Value); - OnLocalBranchListChanged?.Invoke(); - } - } - - private void RemoveLocalBranch(string oldName) - { - if (branches.ContainsKey(oldName)) - { - branches.Remove(oldName); - OnLocalBranchListChanged?.Invoke(); - } - } - - private void AddRemoteBranch(string remote, string name) - { - Dictionary branchList = null; - if (remoteBranches.TryGetValue(remote, out branchList)) - { - if (!branchList.ContainsKey(name)) - { - branchList.Add(name, new ConfigBranch { Name = name, Remote = remotes[remote] }); - OnRemoteBranchListChanged?.Invoke(); - } - } - } - private void RemoveRemoteBranch(string remote, string name) - { - Dictionary branchList = null; - if (remoteBranches.TryGetValue(remote, out branchList)) - { - if (branches.ContainsKey(name)) - { - branches.Remove(name); - OnRemoteBranchListChanged?.Invoke(); - } - } + OnRemoteBranchListUpdated?.Invoke(remoteBranches); } private bool disposed; @@ -635,9 +528,6 @@ public void Dispose() GC.SuppressFinalize(this); } - public Dictionary LocalBranches => branches; - public Dictionary> RemoteBranches => remoteBranches; - public IGitConfig Config => config; public IGitClient GitClient => gitClient; diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs index 3f77ce74f..9d12b5ab5 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs @@ -101,8 +101,8 @@ private void AttachHandlers(IRepository repository) return; repository.OnLocalBranchListChanged += RunRefreshEmbeddedOnMainThread; - repository.OnActiveBranchChanged += HandleRepositoryBranchChangeEvent; - repository.OnActiveRemoteChanged += HandleRepositoryBranchChangeEvent; + repository.OnCurrentBranchChanged += HandleRepositoryBranchChangeEvent; + repository.OnCurrentRemoteChanged += HandleRepositoryBranchChangeEvent; } private void DetachHandlers(IRepository repository) @@ -110,8 +110,8 @@ private void DetachHandlers(IRepository repository) if (repository == null) return; repository.OnLocalBranchListChanged -= RunRefreshEmbeddedOnMainThread; - repository.OnActiveBranchChanged -= HandleRepositoryBranchChangeEvent; - repository.OnActiveRemoteChanged -= HandleRepositoryBranchChangeEvent; + repository.OnCurrentBranchChanged -= HandleRepositoryBranchChangeEvent; + repository.OnCurrentRemoteChanged -= HandleRepositoryBranchChangeEvent; } private void RunRefreshEmbeddedOnMainThread() diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs index 19b3987ad..4a4bec04e 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs @@ -131,8 +131,8 @@ private void AttachHandlers(IRepository repository) return; repository.OnHeadChanged += Refresh; repository.OnStatusUpdated += UpdateStatusOnMainThread; - repository.OnActiveBranchChanged += s => Refresh(); - repository.OnActiveRemoteChanged += s => Refresh(); + repository.OnCurrentBranchChanged += s => Refresh(); + repository.OnCurrentRemoteChanged += s => Refresh(); } private void DetachHandlers(IRepository repository) @@ -141,8 +141,8 @@ private void DetachHandlers(IRepository repository) return; repository.OnHeadChanged -= Refresh; repository.OnStatusUpdated -= UpdateStatusOnMainThread; - repository.OnActiveBranchChanged -= s => Refresh(); - repository.OnActiveRemoteChanged -= s => Refresh(); + repository.OnCurrentBranchChanged -= s => Refresh(); + repository.OnCurrentRemoteChanged -= s => Refresh(); } private void UpdateStatusOnMainThread(GitStatus status) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs index 24bcbeb05..3b60918ae 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs @@ -105,7 +105,7 @@ private void AttachHandlers(IRepository repository) if (repository == null) return; - repository.OnActiveRemoteChanged += Repository_OnActiveRemoteChanged; + repository.OnCurrentRemoteChanged += Repository_OnActiveRemoteChanged; repository.OnLocksUpdated += RunLocksUpdateOnMainThread; } @@ -114,7 +114,7 @@ private void DetachHandlers(IRepository repository) if (repository == null) return; - repository.OnActiveRemoteChanged -= Repository_OnActiveRemoteChanged; + repository.OnCurrentRemoteChanged -= Repository_OnActiveRemoteChanged; repository.OnLocksUpdated -= RunLocksUpdateOnMainThread; } diff --git a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs index 7057a74ea..c567ff385 100644 --- a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs @@ -51,8 +51,6 @@ public async Task ShouldDetectFileChanges() WaitForNotBusy(repositoryManagerEvents, 1); repositoryManagerListener.Received().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -98,8 +96,6 @@ public async Task ShouldAddAndCommitFiles() WaitForNotBusy(repositoryManagerEvents, 1); repositoryManagerListener.Received().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -120,8 +116,6 @@ await RepositoryManager WaitForNotBusy(repositoryManagerEvents, 1); repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -165,8 +159,6 @@ public async Task ShouldAddAndCommitAllFiles() WaitForNotBusy(repositoryManagerEvents, 1); repositoryManagerListener.Received().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -187,8 +179,6 @@ await RepositoryManager WaitForNotBusy(repositoryManagerEvents, 1); repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -219,8 +209,6 @@ public async Task ShouldDetectBranchChange() WaitForNotBusy(repositoryManagerEvents, 5); repositoryManagerListener.Received().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.Received(1).OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.Received(1).OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -245,8 +233,6 @@ public async Task ShouldDetectBranchDelete() repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); //TODO: Deleting a branch causes a config reload, which raises OnActiveBranchChanged/OnActiveRemoteChanged - repositoryManagerListener.Received().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.Received().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.Received(1).OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -267,8 +253,6 @@ public async Task ShouldDetectBranchCreate() RepositoryManager.WaitForEvents(); repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.Received(1).OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -283,8 +267,6 @@ public async Task ShouldDetectBranchCreate() RepositoryManager.WaitForEvents(); repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.Received(1).OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -317,8 +299,6 @@ public async Task ShouldDetectChangesToRemotes() Environment.Repository.Owner.Should().BeNull(); repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.Received().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.Received().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -340,8 +320,6 @@ public async Task ShouldDetectChangesToRemotes() Environment.Repository.Owner.Should().Be("EvilShana"); repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.Received().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.Received().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -372,8 +350,6 @@ await RepositoryManager.CreateBranch("branch2", "another/master") RepositoryManager.WaitForEvents(); repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.Received().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.Received().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.Received().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -398,8 +374,6 @@ await RepositoryManager.SwitchBranch("branch2") Environment.Repository.Owner.Should().Be("Owner"); repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.Received().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.Received().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -433,8 +407,6 @@ public async Task ShouldUpdateCloneUrlIfRemoteIsDeleted() repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); - repositoryManagerListener.Received().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.Received().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -455,8 +427,6 @@ public async Task ShouldUpdateCloneUrlIfRemoteIsDeleted() repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); - repositoryManagerListener.Received().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.Received().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -486,8 +456,6 @@ public async Task ShouldDetectGitPull() repositoryManagerListener.Received().OnStatusUpdate(Args.GitStatus); repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); - repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -513,8 +481,6 @@ public async Task ShouldDetectGitFetch() repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); - repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.Received(2).OnRemoteBranchListChanged(); diff --git a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs index be0aafa76..37dfcd45f 100644 --- a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs +++ b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs @@ -9,8 +9,6 @@ namespace TestUtils.Events interface IRepositoryManagerListener { void OnStatusUpdate(GitStatus status); - void OnActiveBranchChanged(ConfigBranch? branch); - void OnActiveRemoteChanged(ConfigRemote? remote); void OnHeadChanged(); void OnLocalBranchListChanged(); void OnRemoteBranchListChanged(); @@ -23,8 +21,6 @@ class RepositoryManagerEvents public EventWaitHandle OnIsBusy { get; } = new ManualResetEvent(false); public EventWaitHandle OnIsNotBusy { get; } = new ManualResetEvent(false); public AutoResetEvent OnStatusUpdate { get; } = new AutoResetEvent(false); - public EventWaitHandle OnActiveBranchChanged { get; } = new ManualResetEvent(false); - public EventWaitHandle OnActiveRemoteChanged { get; } = new ManualResetEvent(false); public EventWaitHandle OnLocalBranchListChanged { get; } = new ManualResetEvent(false); public EventWaitHandle OnRemoteBranchListChanged { get; } = new ManualResetEvent(false); public EventWaitHandle OnLocksUpdated { get; } = new ManualResetEvent(false); @@ -34,8 +30,6 @@ public void Reset() OnIsBusy.Reset(); OnIsNotBusy.Reset(); OnStatusUpdate.Reset(); - OnActiveBranchChanged.Reset(); - OnActiveRemoteChanged.Reset(); OnLocalBranchListChanged.Reset(); OnRemoteBranchListChanged.Reset(); OnLocksUpdated.Reset(); @@ -64,18 +58,6 @@ public static void AttachListener(this IRepositoryManagerListener listener, IRep managerEvents?.OnStatusUpdate.Set(); }; - repositoryManager.OnActiveBranchChanged += (branch) => { - logger?.Trace($"OnActiveBranchChanged {branch}"); - listener.OnActiveBranchChanged(branch); - managerEvents?.OnActiveBranchChanged.Set(); - }; - - repositoryManager.OnActiveRemoteChanged += (remote) => { - logger?.Trace($"OnActiveRemoteChanged {(remote.HasValue ? remote.Value.Name : null)}"); - listener.OnActiveRemoteChanged(remote); - managerEvents?.OnActiveRemoteChanged.Set(); - }; - repositoryManager.OnLocalBranchListChanged += () => { logger?.Trace("OnLocalBranchListChanged"); listener.OnLocalBranchListChanged(); @@ -99,8 +81,6 @@ public static void AttachListener(this IRepositoryManagerListener listener, IRep public static void AssertDidNotReceiveAnyCalls(this IRepositoryManagerListener repositoryManagerListener) { repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); diff --git a/src/tests/UnitTests/Repository/RepositoryManagerTests.cs b/src/tests/UnitTests/Repository/RepositoryManagerTests.cs index aa4ed882c..08070eef4 100644 --- a/src/tests/UnitTests/Repository/RepositoryManagerTests.cs +++ b/src/tests/UnitTests/Repository/RepositoryManagerTests.cs @@ -179,8 +179,6 @@ public async Task ShouldRefreshAndReturnCombinedStatusAndLockInformation1() result.HasValue.Should().BeTrue(); result.Value.AssertEqual(expectedGitStatus); - repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -241,8 +239,6 @@ public void ShouldRefreshAndReturnCombinedStatusAndLockInformation2() result.HasValue.Should().BeTrue(); result.Value.AssertNotEqual(expectedGitStatus); - repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -280,8 +276,6 @@ public void ShouldRefreshAndReturnWithEmptyGitLockResponse() result.HasValue.Should().BeTrue(); result.Value.AssertEqual(responseGitStatus); - repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); @@ -319,8 +313,6 @@ public void ShouldRefreshAndReturnWithNoGitLockResponse() result.HasValue.Should().BeTrue(); result.Value.AssertEqual(responseGitStatus); - repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any()); repositoryManagerListener.DidNotReceive().OnHeadChanged(); repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); From 95be3e61ebe95256c6edd03b0d1db5ffabeb11dd Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 15 Sep 2017 09:32:14 -0400 Subject: [PATCH 02/57] Tweaking spaces --- src/GitHub.Api/Git/Repository.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 0e99444e6..d44ba9ccf 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -15,9 +15,7 @@ class Repository : IRepository, IEquatable private ConfigRemote? currentRemote; private GitStatus currentStatus; private string head; - private Dictionary localBranches = new Dictionary(); - private IEnumerable locks; private Dictionary> remoteBranches = new Dictionary>(); private Dictionary remotes; From 8af8b2668cbd3e3021d4b2ab43cedf004646995a Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 15 Sep 2017 09:54:47 -0400 Subject: [PATCH 03/57] Removing more spaces --- src/GitHub.Api/Git/RepositoryManager.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index fa21a1630..9ae338eed 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -109,10 +109,7 @@ class RepositoryManager : IRepositoryManager public event Action> OnLocalBranchListUpdated; public event Action>> OnRemoteBranchListUpdated; - public event Action> OnLocksUpdated; - -// public event Action OnCommitChanged; public event Action OnStatusUpdated; public event Action OnHeadUpdated; public event Action OnUpdateLocalBranch; From 45a0150cc1f918df7fc7bf81e62a4e6faaa5539c Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 15 Sep 2017 10:15:51 -0400 Subject: [PATCH 04/57] Restoring properties --- src/GitHub.Api/Git/Repository.cs | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index d44ba9ccf..d354cb9ff 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -29,25 +29,11 @@ class Repository : IRepository, IEquatable public event Action> OnLocksUpdated; public event Action OnRepositoryInfoChanged; - public IEnumerable LocalBranches - { - get - { - throw new NotImplementedException(); -// return repositoryManager.LocalBranches.Values.Select(x => new GitBranch(x.Name, -// (x.IsTracking ? (x.Remote.Value.Name + "/" + x.Name) : "[None]"), x.Name == CurrentBranch?.Name)); - } - } + public IEnumerable LocalBranches => localBranches.Values.Select( + x => new GitBranch(x.Name, (x.IsTracking ? (x.Remote.Value.Name + "/" + x.Name) : "[None]"), x.Name == CurrentBranch?.Name)); - public IEnumerable RemoteBranches - { - get - { - throw new NotImplementedException(); -// return repositoryManager.RemoteBranches.Values.SelectMany(x => x.Values).Select(x => -// new GitBranch(x.Remote.Value.Name + "/" + x.Name, "[None]", false)); - } - } + public IEnumerable RemoteBranches => remoteBranches.Values.SelectMany( + x => x.Values).Select(x => new GitBranch(x.Remote.Value.Name + "/" + x.Name, "[None]", false)); /// /// Initializes a new instance of the class. From c12bd652be459895a753c44f4c6080864d2112ae Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 15 Sep 2017 10:33:38 -0400 Subject: [PATCH 05/57] Renaming some events and event handlers, making sure all events are handled --- src/GitHub.Api/Git/Repository.cs | 18 ++++++++++-------- src/GitHub.Api/Git/RepositoryManager.cs | 24 ++++++++++++------------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index d354cb9ff..15588bcdb 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -63,9 +63,11 @@ public void Initialize(IRepositoryManager repositoryManager) repositoryManager.OnLocksUpdated += RepositoryManager_OnLocksUpdated; repositoryManager.OnLocalBranchListUpdated += RepositoryManager_OnLocalBranchListUpdated; repositoryManager.OnRemoteBranchListUpdated += RepositoryManager_OnRemoteBranchListUpdated; - repositoryManager.OnUpdateLocalBranch += RepositoryManager_OnUpdateLocalBranch; - repositoryManager.OnAddLocalBranch += RepositoryManager_OnAddLocalBranch; - repositoryManager.OnRemoveLocalBranch += RepositoryManager_OnRemoveLocalBranch; + repositoryManager.OnLocalBranchUpdated += RepositoryManager_OnLocalBranchUpdated; + repositoryManager.OnLocalBranchAdded += RepositoryManager_OnLocalBranchAdded; + repositoryManager.OnLocalBranchRemoved += RepositoryManager_OnLocalBranchRemoved; + repositoryManager.OnRemoteBranchAdded += RepositoryManager_OnRemoteBranchAdded; + repositoryManager.OnRemoteBranchRemoved += RepositoryManager_OnRemoteBranchRemoved; repositoryManager.OnGitUserLoaded += user => User = user; } @@ -197,7 +199,7 @@ private void RepositoryManager_OnLocalBranchListUpdated(Dictionary branchList = null; if (remoteBranches.TryGetValue(remote, out branchList)) @@ -244,7 +246,7 @@ private void AddRemoteBranch(string remote, string name) } } - private void RemoveRemoteBranch(string remote, string name) + private void RepositoryManager_OnRemoteBranchRemoved(string remote, string name) { Dictionary branchList = null; if (remoteBranches.TryGetValue(remote, out branchList)) diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index 9ae338eed..931503785 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -14,11 +14,11 @@ interface IRepositoryManager : IDisposable event Action> OnLocksUpdated; event Action> OnLocalBranchListUpdated; event Action>> OnRemoteBranchListUpdated; - event Action OnUpdateLocalBranch; - event Action OnAddLocalBranch; - event Action OnRemoveLocalBranch; + event Action OnLocalBranchUpdated; + event Action OnLocalBranchAdded; + event Action OnLocalBranchRemoved; event Action OnRemoteBranchAdded; - event Action OnRemoteBranchDeleted; + event Action OnRemoteBranchRemoved; event Action OnGitUserLoaded; IGitConfig Config { get; } @@ -112,12 +112,12 @@ class RepositoryManager : IRepositoryManager public event Action> OnLocksUpdated; public event Action OnStatusUpdated; public event Action OnHeadUpdated; - public event Action OnUpdateLocalBranch; - public event Action OnAddLocalBranch; - public event Action OnRemoveLocalBranch; + public event Action OnLocalBranchUpdated; + public event Action OnLocalBranchAdded; + public event Action OnLocalBranchRemoved; public event Action OnGitUserLoaded; public event Action OnRemoteBranchAdded; - public event Action OnRemoteBranchDeleted; + public event Action OnRemoteBranchRemoved; public static RepositoryManager CreateInstance(IPlatform platform, ITaskManager taskManager, IUsageTracker usageTracker, IGitClient gitClient, NPath repositoryRoot) @@ -374,7 +374,7 @@ private ITask HookupHandlers(ITask task, bool disableWatcher = false) private void Watcher_OnRemoteBranchDeleted(string remote, string name) { - OnRemoteBranchDeleted?.Invoke(remote, name); + OnRemoteBranchRemoved?.Invoke(remote, name); } private void Watcher_OnRemoteBranchCreated(string remote, string name) @@ -422,17 +422,17 @@ private void Watcher_OnIndexChanged() private void Watcher_OnLocalBranchCreated(string name) { - OnAddLocalBranch?.Invoke(name); + OnLocalBranchAdded?.Invoke(name); } private void Watcher_OnLocalBranchDeleted(string name) { - OnRemoveLocalBranch?.Invoke(name); + OnLocalBranchRemoved?.Invoke(name); } private void Watcher_OnLocalBranchChanged(string name) { - OnUpdateLocalBranch?.Invoke(name); + OnLocalBranchUpdated?.Invoke(name); } private void UpdateConfigData(bool resetConfig = false) From 859bd857f653bbeceb4404f98ff1cf097e3b7724 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 15 Sep 2017 11:30:08 -0400 Subject: [PATCH 06/57] Renaming events to machine other Repository events --- src/GitHub.Api/Git/IRepository.cs | 4 ++-- src/GitHub.Api/Git/Repository.cs | 8 ++++---- .../Assets/Editor/GitHub.Unity/UI/ChangesView.cs | 4 ++-- .../Assets/Editor/GitHub.Unity/UI/HistoryView.cs | 4 ++-- .../Editor/GitHub.Unity/UI/ProjectWindowInterface.cs | 4 ++-- .../Assets/Editor/GitHub.Unity/UI/SettingsView.cs | 4 ++-- .../IntegrationTests/Events/RepositoryManagerTests.cs | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/GitHub.Api/Git/IRepository.cs b/src/GitHub.Api/Git/IRepository.cs index b51e4faee..d77b87bc3 100644 --- a/src/GitHub.Api/Git/IRepository.cs +++ b/src/GitHub.Api/Git/IRepository.cs @@ -57,12 +57,12 @@ interface IRepository : IEquatable IEnumerable CurrentLocks { get; } string CurrentBranchName { get; } - event Action OnStatusUpdated; + event Action OnStatusChanged; event Action OnCurrentBranchChanged; event Action OnCurrentRemoteChanged; event Action OnLocalBranchListChanged; event Action OnHeadChanged; - event Action> OnLocksUpdated; + event Action> OnLocksChanged; event Action OnRepositoryInfoChanged; } } \ No newline at end of file diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 15588bcdb..cb765697e 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -20,13 +20,13 @@ class Repository : IRepository, IEquatable private Dictionary> remoteBranches = new Dictionary>(); private Dictionary remotes; - public event Action OnStatusUpdated; + public event Action OnStatusChanged; public event Action OnCurrentBranchChanged; public event Action OnCurrentRemoteChanged; public event Action OnLocalBranchListChanged; public event Action OnRemoteBranchListChanged; public event Action OnHeadChanged; - public event Action> OnLocksUpdated; + public event Action> OnLocksChanged; public event Action OnRepositoryInfoChanged; public IEnumerable LocalBranches => localBranches.Values.Select( @@ -163,7 +163,7 @@ private void RepositoryManager_OnStatusUpdated(GitStatus status) private void RepositoryManager_OnLocksUpdated(IEnumerable locks) { CurrentLocks = locks; - OnLocksUpdated?.Invoke(CurrentLocks); + OnLocksChanged?.Invoke(CurrentLocks); } private void RepositoryManager_OnHeadUpdated(string h) @@ -403,7 +403,7 @@ public GitStatus CurrentStatus { Logger.Trace("OnStatusUpdated: {0}", value.ToString()); currentStatus = value; - OnStatusUpdated?.Invoke(CurrentStatus); + OnStatusChanged?.Invoke(CurrentStatus); } } diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs index 9938072fb..2c560ef44 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs @@ -40,7 +40,7 @@ public override void OnEnable() return; OnStatusUpdate(Repository.CurrentStatus); - Repository.OnStatusUpdated += RunStatusUpdateOnMainThread; + Repository.OnStatusChanged += RunStatusUpdateOnMainThread; Repository.Refresh(); } @@ -49,7 +49,7 @@ public override void OnDisable() base.OnDisable(); if (Repository == null) return; - Repository.OnStatusUpdated -= RunStatusUpdateOnMainThread; + Repository.OnStatusChanged -= RunStatusUpdateOnMainThread; } private void RunStatusUpdateOnMainThread(GitStatus status) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs index 4a4bec04e..f865ced32 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs @@ -130,7 +130,7 @@ private void AttachHandlers(IRepository repository) if (repository == null) return; repository.OnHeadChanged += Refresh; - repository.OnStatusUpdated += UpdateStatusOnMainThread; + repository.OnStatusChanged += UpdateStatusOnMainThread; repository.OnCurrentBranchChanged += s => Refresh(); repository.OnCurrentRemoteChanged += s => Refresh(); } @@ -140,7 +140,7 @@ private void DetachHandlers(IRepository repository) if (repository == null) return; repository.OnHeadChanged -= Refresh; - repository.OnStatusUpdated -= UpdateStatusOnMainThread; + repository.OnStatusChanged -= UpdateStatusOnMainThread; repository.OnCurrentBranchChanged -= s => Refresh(); repository.OnCurrentRemoteChanged -= s => Refresh(); } diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs index cef86203e..05fc0d66c 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs @@ -30,8 +30,8 @@ public static void Initialize(IRepository repo) repository = repo; if (repository != null) { - repository.OnStatusUpdated += RunStatusUpdateOnMainThread; - repository.OnLocksUpdated += RunLocksUpdateOnMainThread; + repository.OnStatusChanged += RunStatusUpdateOnMainThread; + repository.OnLocksChanged += RunLocksUpdateOnMainThread; } } diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs index 3b60918ae..5f0ca0208 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs @@ -106,7 +106,7 @@ private void AttachHandlers(IRepository repository) return; repository.OnCurrentRemoteChanged += Repository_OnActiveRemoteChanged; - repository.OnLocksUpdated += RunLocksUpdateOnMainThread; + repository.OnLocksChanged += RunLocksUpdateOnMainThread; } private void DetachHandlers(IRepository repository) @@ -115,7 +115,7 @@ private void DetachHandlers(IRepository repository) return; repository.OnCurrentRemoteChanged -= Repository_OnActiveRemoteChanged; - repository.OnLocksUpdated -= RunLocksUpdateOnMainThread; + repository.OnLocksChanged -= RunLocksUpdateOnMainThread; } public override void OnGUI() diff --git a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs index c567ff385..d88426569 100644 --- a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs @@ -41,7 +41,7 @@ public async Task ShouldDetectFileChanges() }; var result = new GitStatus(); - Environment.Repository.OnStatusUpdated += status => { result = status; }; + Environment.Repository.OnStatusChanged += status => { result = status; }; var foobarTxt = TestRepoMasterCleanSynchronized.Combine("foobar.txt"); foobarTxt.WriteAllText("foobar"); From 0c2d8062abc702cf950bdb172c553a024d79d2aa Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 15 Sep 2017 12:57:17 -0400 Subject: [PATCH 07/57] Missing event raise --- src/GitHub.Api/Git/Repository.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index cb765697e..1c3f04009 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -194,9 +194,10 @@ private void RepositoryManager_OnRemoteBranchListUpdated(Dictionary obj) + private void RepositoryManager_OnLocalBranchListUpdated(Dictionary branches) { - localBranches = obj; + localBranches = branches; + OnLocalBranchListChanged?.Invoke(); } private void RepositoryManager_OnLocalBranchRemoved(string name) From 756389fce80e089cc90740299482c161a1def460 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 15 Sep 2017 13:04:31 -0400 Subject: [PATCH 08/57] Renaming variables --- src/GitHub.Api/Git/RepositoryManager.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index 931503785..2d4a5cbfb 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -290,12 +290,12 @@ public ITask ListLocks(bool local) { var task = GitClient .ListLocks(local) - .Then((s, t) => + .Then((success, locks) => { - if (s) + if (success) { Logger.Trace("OnLocksUpdated"); - OnLocksUpdated?.Invoke(t); + OnLocksUpdated?.Invoke(locks); } }); return HookupHandlers(task); From 7dd3a3b9e1336ee60f842792bec7b7a993e0c869 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 15 Sep 2017 13:08:11 -0400 Subject: [PATCH 09/57] Removing space --- src/GitHub.Api/Git/Repository.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 1c3f04009..8e5f14a5b 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -233,7 +233,6 @@ private void RepositoryManager_OnLocalBranchUpdated(string name) } } - private void RepositoryManager_OnRemoteBranchAdded(string remote, string name) { Dictionary branchList = null; From a3c60e691e775105dc6e9fae563f673a284aac6c Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 15 Sep 2017 13:11:55 -0400 Subject: [PATCH 10/57] Fixing the build of tests --- .../TestUtils/Events/IRepositoryManagerListener.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs index 37dfcd45f..91ccc9b60 100644 --- a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs +++ b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs @@ -58,18 +58,6 @@ public static void AttachListener(this IRepositoryManagerListener listener, IRep managerEvents?.OnStatusUpdate.Set(); }; - repositoryManager.OnLocalBranchListChanged += () => { - logger?.Trace("OnLocalBranchListChanged"); - listener.OnLocalBranchListChanged(); - managerEvents?.OnLocalBranchListChanged.Set(); - }; - - repositoryManager.OnRemoteBranchListChanged += () => { - logger?.Trace("OnRemoteBranchListChanged"); - listener.OnRemoteBranchListChanged(); - managerEvents?.OnRemoteBranchListChanged.Set(); - }; - repositoryManager.OnLocksUpdated += locks => { var lockArray = locks.ToArray(); logger?.Trace("OnLocksUpdated Count:{0}", lockArray.Length); From 74c8c118c45921d3bf43e9f6e465febbd8b6a460 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 15 Sep 2017 16:14:45 -0400 Subject: [PATCH 11/57] Fixing tests --- src/GitHub.Api/Git/Repository.cs | 6 +- .../Events/RepositoryManagerTests.cs | 236 ++++++++----- src/tests/IntegrationTests/SetupFixture.cs | 5 +- .../Events/IRepositoryManagerListener.cs | 127 +++++-- .../Repository/RepositoryManagerTests.cs | 321 ------------------ src/tests/UnitTests/SetUpFixture.cs | 5 +- src/tests/UnitTests/UnitTests.csproj | 1 - 7 files changed, 264 insertions(+), 437 deletions(-) delete mode 100644 src/tests/UnitTests/Repository/RepositoryManagerTests.cs diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 8e5f14a5b..4299e087f 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -182,7 +182,7 @@ private void RepositoryManager_OnHeadUpdated(string h) if (!Nullable.Equals(currentRemote, remote)) { - currentRemote = remote; + CurrentRemote = remote; OnCurrentRemoteChanged?.Invoke(currentRemote.HasValue ? currentRemote.Value.Name : null); } } @@ -235,7 +235,7 @@ private void RepositoryManager_OnLocalBranchUpdated(string name) private void RepositoryManager_OnRemoteBranchAdded(string remote, string name) { - Dictionary branchList = null; + Dictionary branchList; if (remoteBranches.TryGetValue(remote, out branchList)) { if (!branchList.ContainsKey(name)) @@ -248,7 +248,7 @@ private void RepositoryManager_OnRemoteBranchAdded(string remote, string name) private void RepositoryManager_OnRemoteBranchRemoved(string remote, string name) { - Dictionary branchList = null; + Dictionary branchList; if (remoteBranches.TryGetValue(remote, out branchList)) { if (localBranches.ContainsKey(name)) diff --git a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs index d88426569..a872830ed 100644 --- a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs @@ -50,12 +50,18 @@ public async Task ShouldDetectFileChanges() RepositoryManager.WaitForEvents(); WaitForNotBusy(repositoryManagerEvents, 1); - repositoryManagerListener.Received().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); result.AssertEqual(expected); } @@ -68,9 +74,10 @@ public async Task ShouldAddAndCommitFiles() var repositoryManagerListener = Substitute.For(); repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); + var expectedLocalBranch = "master"; var expectedAfterChanges = new GitStatus { Behind = 1, - LocalBranch = "master", + LocalBranch = expectedLocalBranch, RemoteBranch = "origin/master", Entries = new List { @@ -95,12 +102,18 @@ public async Task ShouldAddAndCommitFiles() RepositoryManager.WaitForEvents(); WaitForNotBusy(repositoryManagerEvents, 1); - repositoryManagerListener.Received().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); - repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); result.AssertEqual(expectedAfterChanges); @@ -115,12 +128,18 @@ await RepositoryManager RepositoryManager.WaitForEvents(); WaitForNotBusy(repositoryManagerEvents, 1); - repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); - repositoryManagerListener.Received(2).OnIsBusyChanged(Args.Bool); + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.Received().OnLocalBranchUpdated(expectedLocalBranch); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); } [Test, Category("TimeSensitive")] @@ -131,9 +150,10 @@ public async Task ShouldAddAndCommitAllFiles() var repositoryManagerListener = Substitute.For(); repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); + var expectedLocalBranch = "master"; var expectedAfterChanges = new GitStatus { Behind = 1, - LocalBranch = "master", + LocalBranch = expectedLocalBranch, RemoteBranch = "origin/master", Entries = new List { @@ -158,12 +178,18 @@ public async Task ShouldAddAndCommitAllFiles() RepositoryManager.WaitForEvents(); WaitForNotBusy(repositoryManagerEvents, 1); - repositoryManagerListener.Received().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); - repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); result.AssertEqual(expectedAfterChanges); @@ -178,15 +204,21 @@ await RepositoryManager RepositoryManager.WaitForEvents(); WaitForNotBusy(repositoryManagerEvents, 1); - repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); - repositoryManagerListener.Received(2).OnIsBusyChanged(Args.Bool); + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.Received().OnLocalBranchUpdated(expectedLocalBranch); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); } - [Test, Category("TimeSensitive")] + [Test] public async Task ShouldDetectBranchChange() { await Initialize(TestRepoMasterCleanSynchronized); @@ -194,8 +226,9 @@ public async Task ShouldDetectBranchChange() var repositoryManagerListener = Substitute.For(); repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); + var expectedLocalBranch = "feature/document"; var expected = new GitStatus { - LocalBranch = "feature/document", + LocalBranch = expectedLocalBranch, RemoteBranch = "origin/feature/document", Entries = new List() }; @@ -203,17 +236,26 @@ public async Task ShouldDetectBranchChange() var result = new GitStatus(); RepositoryManager.OnStatusUpdated += status => { result = status; }; - await RepositoryManager.SwitchBranch("feature/document").StartAsAsync(); + await RepositoryManager.SwitchBranch(expectedLocalBranch).StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); WaitForNotBusy(repositoryManagerEvents, 5); - repositoryManagerListener.Received().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.Received(1).OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnIsBusyChanged(Args.Bool); + repositoryManagerEvents.OnStatusUpdated.WaitOne(TimeSpan.FromSeconds(5)); + repositoryManagerEvents.OnStatusUpdated.WaitOne(TimeSpan.FromSeconds(5)); + + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.Received().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); result.AssertEqual(expected); } @@ -226,18 +268,24 @@ public async Task ShouldDetectBranchDelete() var repositoryManagerListener = Substitute.For(); repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); - await RepositoryManager.DeleteBranch("feature/document", true).StartAsAsync(); + var deletedBranch = "feature/document"; + await RepositoryManager.DeleteBranch(deletedBranch, true).StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); WaitForNotBusy(repositoryManagerEvents, 1); - repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - //TODO: Deleting a branch causes a config reload, which raises OnActiveBranchChanged/OnActiveRemoteChanged - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.Received(1).OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); - repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.Received().OnLocalBranchRemoved(deletedBranch); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); } [Test] @@ -248,30 +296,44 @@ public async Task ShouldDetectBranchCreate() var repositoryManagerListener = Substitute.For(); repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); - await RepositoryManager.CreateBranch("feature/document2", "feature/document").StartAsAsync(); + var createdBranch1 = "feature/document2"; + await RepositoryManager.CreateBranch(createdBranch1, "feature/document").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.Received(1).OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); - repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.Received().OnLocalBranchAdded(createdBranch1); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); repositoryManagerListener.ClearReceivedCalls(); repositoryManagerEvents.Reset(); - await RepositoryManager.CreateBranch("feature2/document2", "feature/document").StartAsAsync(); + var createdBranch2 = "feature2/document2"; + await RepositoryManager.CreateBranch(createdBranch2, "feature/document").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.Received(1).OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); - repositoryManagerListener.Received(2).OnIsBusyChanged(Args.Bool); + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.Received().OnLocalBranchAdded(createdBranch2); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); } [Test] @@ -289,21 +351,33 @@ public async Task ShouldDetectChangesToRemotes() Environment.Repository.CloneUrl.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Environment.Repository.Owner.Should().Be("EvilStanleyGoldman"); + Logger.Trace("Removing Remote"); + await RepositoryManager.RemoteRemove("origin").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); + Logger.Trace("Continue Test"); + + //TODO: Continue from here + Environment.Repository.CurrentRemote.HasValue.Should().BeFalse(); Environment.Repository.CloneUrl.Should().BeNull(); Environment.Repository.Owner.Should().BeNull(); - repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); - repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); repositoryManagerListener.ClearReceivedCalls(); repositoryManagerEvents.Reset(); @@ -319,12 +393,18 @@ public async Task ShouldDetectChangesToRemotes() Environment.Repository.CloneUrl.Should().Be("https://github.com/EvilShana/IOTestsRepo.git"); Environment.Repository.Owner.Should().Be("EvilShana"); - repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); - repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); } [Test, Category("TimeSensitive")] @@ -349,10 +429,7 @@ await RepositoryManager.CreateBranch("branch2", "another/master") await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.Received().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); @@ -373,10 +450,7 @@ await RepositoryManager.SwitchBranch("branch2") Environment.Repository.CloneUrl.ToString().Should().Be(expectedRemoteUrl); Environment.Repository.Owner.Should().Be("Owner"); - repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); } @@ -405,11 +479,8 @@ public async Task ShouldUpdateCloneUrlIfRemoteIsDeleted() Environment.Repository.CloneUrl.Should().BeNull(); Environment.Repository.Owner.Should().BeNull(); - repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); repositoryManagerListener.ClearReceivedCalls(); @@ -425,11 +496,8 @@ public async Task ShouldUpdateCloneUrlIfRemoteIsDeleted() Environment.Repository.CloneUrl.Should().Be("https://github.com/EvilShana/IOTestsRepo.git"); Environment.Repository.Owner.Should().Be("EvilShana"); - repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); } @@ -454,11 +522,8 @@ public async Task ShouldDetectGitPull() await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - repositoryManagerListener.Received().OnStatusUpdate(Args.GitStatus); + repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); result.AssertEqual(expected); @@ -479,11 +544,8 @@ public async Task ShouldDetectGitFetch() await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.Received(2).OnRemoteBranchListChanged(); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); } diff --git a/src/tests/IntegrationTests/SetupFixture.cs b/src/tests/IntegrationTests/SetupFixture.cs index 4c9a43b6b..10ab573b3 100644 --- a/src/tests/IntegrationTests/SetupFixture.cs +++ b/src/tests/IntegrationTests/SetupFixture.cs @@ -12,7 +12,10 @@ public void Setup() { Logging.TracingEnabled = true; - Logging.LogAdapter = new MultipleLogAdapter(new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-integration-tests.log")); + Logging.LogAdapter = new MultipleLogAdapter( + new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-integration-tests.log"), + new ConsoleLogAdapter() + ); } } } diff --git a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs index 91ccc9b60..c289203ae 100644 --- a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs +++ b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs @@ -8,45 +8,65 @@ namespace TestUtils.Events { interface IRepositoryManagerListener { - void OnStatusUpdate(GitStatus status); - void OnHeadChanged(); - void OnLocalBranchListChanged(); - void OnRemoteBranchListChanged(); void OnIsBusyChanged(bool busy); + void OnStatusUpdated(GitStatus status); void OnLocksUpdated(IEnumerable locks); + void OnHeadUpdated(string head); + void OnLocalBranchListUpdated(Dictionary branchList); + void OnRemoteBranchListUpdated(Dictionary> remoteBranchList); + void OnLocalBranchUpdated(string name); + void OnLocalBranchAdded(string name); + void OnLocalBranchRemoved(string name); + void OnRemoteBranchAdded(string origin, string name); + void OnRemoteBranchRemoved(string origin, string name); + void OnGitUserLoaded(IUser user); } class RepositoryManagerEvents { public EventWaitHandle OnIsBusy { get; } = new ManualResetEvent(false); public EventWaitHandle OnIsNotBusy { get; } = new ManualResetEvent(false); - public AutoResetEvent OnStatusUpdate { get; } = new AutoResetEvent(false); - public EventWaitHandle OnLocalBranchListChanged { get; } = new ManualResetEvent(false); - public EventWaitHandle OnRemoteBranchListChanged { get; } = new ManualResetEvent(false); + public EventWaitHandle OnStatusUpdated { get; } = new ManualResetEvent(false); public EventWaitHandle OnLocksUpdated { get; } = new ManualResetEvent(false); + public EventWaitHandle OnHeadUpdated { get; } = new ManualResetEvent(false); + public EventWaitHandle OnLocalBranchListUpdated { get; } = new ManualResetEvent(false); + public EventWaitHandle OnRemoteBranchListUpdated { get; } = new ManualResetEvent(false); + public EventWaitHandle OnLocalBranchUpdated { get; } = new ManualResetEvent(false); + public EventWaitHandle OnLocalBranchAdded { get; } = new ManualResetEvent(false); + public EventWaitHandle OnLocalBranchRemoved { get; } = new ManualResetEvent(false); + public EventWaitHandle OnRemoteBranchAdded { get; } = new ManualResetEvent(false); + public EventWaitHandle OnRemoteBranchRemoved { get; } = new ManualResetEvent(false); + public EventWaitHandle OnGitUserLoaded { get; } = new ManualResetEvent(false); public void Reset() { OnIsBusy.Reset(); OnIsNotBusy.Reset(); - OnStatusUpdate.Reset(); - OnLocalBranchListChanged.Reset(); - OnRemoteBranchListChanged.Reset(); + OnStatusUpdated.Reset(); OnLocksUpdated.Reset(); + OnHeadUpdated.Reset(); + OnLocalBranchListUpdated.Reset(); + OnRemoteBranchListUpdated.Reset(); + OnLocalBranchUpdated.Reset(); + OnLocalBranchAdded.Reset(); + OnLocalBranchRemoved.Reset(); + OnRemoteBranchAdded.Reset(); + OnRemoteBranchRemoved.Reset(); + OnGitUserLoaded.Reset(); } } static class RepositoryManagerListenerExtensions { - public static void AttachListener(this IRepositoryManagerListener listener, IRepositoryManager repositoryManager, - RepositoryManagerEvents managerEvents = null, bool trace = true) + public static void AttachListener(this IRepositoryManagerListener listener, + IRepositoryManager repositoryManager, RepositoryManagerEvents managerEvents = null, bool trace = true) { var logger = trace ? Logging.GetLogger() : null; - repositoryManager.OnIsBusyChanged += b => { - logger?.Trace("OnIsBusyChanged: {0}", b); - listener.OnIsBusyChanged(b); - if (b) + repositoryManager.OnIsBusyChanged += isBusy => { + logger?.Trace("OnIsBusyChanged: {0}", isBusy); + listener.OnIsBusyChanged(isBusy); + if (isBusy) managerEvents?.OnIsBusy.Set(); else managerEvents?.OnIsNotBusy.Set(); @@ -54,8 +74,8 @@ public static void AttachListener(this IRepositoryManagerListener listener, IRep repositoryManager.OnStatusUpdated += status => { logger?.Debug("OnStatusUpdated: {0}", status); - listener.OnStatusUpdate(status); - managerEvents?.OnStatusUpdate.Set(); + listener.OnStatusUpdated(status); + managerEvents?.OnStatusUpdated.Set(); }; repositoryManager.OnLocksUpdated += locks => { @@ -64,15 +84,76 @@ public static void AttachListener(this IRepositoryManagerListener listener, IRep listener.OnLocksUpdated(lockArray); managerEvents?.OnLocksUpdated.Set(); }; + + repositoryManager.OnHeadUpdated += head => { + logger?.Trace("OnHeadUpdated"); + listener.OnHeadUpdated(head); + managerEvents?.OnHeadUpdated.Set(); + }; + + repositoryManager.OnLocalBranchListUpdated += branchList => { + logger?.Trace("OnLocalBranchListUpdated"); + listener.OnLocalBranchListUpdated(branchList); + managerEvents?.OnLocalBranchListUpdated.Set(); + }; + + repositoryManager.OnRemoteBranchListUpdated += branchList => { + logger?.Trace("OnRemoteBranchListUpdated"); + listener.OnRemoteBranchListUpdated(branchList); + managerEvents?.OnRemoteBranchListUpdated.Set(); + }; + + repositoryManager.OnLocalBranchUpdated += name => { + logger?.Trace("OnLocalBranchUpdated Name:{0}", name); + listener.OnLocalBranchUpdated(name); + managerEvents?.OnLocalBranchUpdated.Set(); + }; + + repositoryManager.OnLocalBranchAdded += name => { + logger?.Trace("OnLocalBranchAdded Name:{0}", name); + listener.OnLocalBranchAdded(name); + managerEvents?.OnLocalBranchAdded.Set(); + }; + + repositoryManager.OnLocalBranchRemoved += name => { + logger?.Trace("OnLocalBranchRemoved Name:{0}", name); + listener.OnLocalBranchRemoved(name); + managerEvents?.OnLocalBranchRemoved.Set(); + }; + + repositoryManager.OnRemoteBranchAdded += (origin, name) => { + logger?.Trace("OnRemoteBranchAdded Origin:{0} Name:{1}", origin, name); + listener.OnRemoteBranchAdded(origin, name); + managerEvents?.OnRemoteBranchAdded.Set(); + }; + + repositoryManager.OnRemoteBranchRemoved += (origin, name) => { + logger?.Trace("OnRemoteBranchRemoved Origin:{0} Name:{1}", origin, name); + listener.OnRemoteBranchRemoved(origin, name); + managerEvents?.OnRemoteBranchRemoved.Set(); + }; + + repositoryManager.OnGitUserLoaded += user => { + logger?.Trace("OnGitUserLoaded Name:{0}", user); + listener.OnGitUserLoaded(user); + managerEvents?.OnGitUserLoaded.Set(); + }; } public static void AssertDidNotReceiveAnyCalls(this IRepositoryManagerListener repositoryManagerListener) { - repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); + repositoryManagerListener.DidNotReceive().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); } } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/tests/UnitTests/Repository/RepositoryManagerTests.cs b/src/tests/UnitTests/Repository/RepositoryManagerTests.cs deleted file mode 100644 index 08070eef4..000000000 --- a/src/tests/UnitTests/Repository/RepositoryManagerTests.cs +++ /dev/null @@ -1,321 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Threading; -using FluentAssertions; -using GitHub.Unity; -using NSubstitute; -using NUnit.Framework; -using TestUtils; -using TestUtils.Events; -using System.Threading.Tasks; - -namespace UnitTests -{ - [TestFixture(Ignore = true, IgnoreReason = "Disabling temporarily until we mock TaskRunner properly")] - class RepositoryManagerTests - { - [SetUp] - public void SetUp() - { - NPath.FileSystem = - SubstituteFactory.CreateFileSystem(new CreateFileSystemOptions() { - ChildFiles = - new Dictionary> { - { - new SubstituteFactory.ContentsKey(@"c:\Temp\.git\refs\heads", "*", - SearchOption.TopDirectoryOnly), - new[] { "master" } - }, { - new SubstituteFactory.ContentsKey(@"c:\Temp\.git\refs\heads\features", "*", - SearchOption.TopDirectoryOnly), - new[] { "feature1" } - }, - }, - ChildDirectories = - new Dictionary> { - { - new SubstituteFactory.ContentsKey(@"c:\Temp\.git\refs\heads", "*", - SearchOption.TopDirectoryOnly), - new[] { @"c:\Temp\.git\refs\heads\features" } - }, { - new SubstituteFactory.ContentsKey(@"c:\Temp\.git\refs\heads\features", "*", - SearchOption.TopDirectoryOnly), - new string[0] - }, - }, - FileContents = - new Dictionary> { - { @"c:\Temp\.git\HEAD", new[] { "ref: refs/heads/fixes/repository-manager-refresh" } } - } - }); - - platform = SubstituteFactory.CreatePlatform(); - SynchronizationContext.SetSynchronizationContext(new TestSynchronizationContext()); - taskManager = new TaskManager(TaskScheduler.FromCurrentSynchronizationContext()); - repositoryPathConfiguration = new RepositoryPathConfiguration(@"/Temp".ToNPath()); - gitConfig = SubstituteFactory.CreateGitConfig(); - - repositoryWatcher = SubstituteFactory.CreateRepositoryWatcher(); - - gitConfigGetResults = new Dictionary { - { - new CreateRepositoryProcessRunnerOptions.GitConfigGetKey("user.email", GitConfigSource.User), - "someone@somewhere.com" - }, { - new CreateRepositoryProcessRunnerOptions.GitConfigGetKey("user.name", GitConfigSource.User), - "Someone Somewhere" - } - }; - } - - [TestFixtureSetUp] - public void TestFixtureSetUp() - { - SubstituteFactory = new SubstituteFactory(); - } - - private readonly CancellationToken cancellationToken = CancellationToken.None; - private IRepositoryWatcher repositoryWatcher; - private IPlatform platform; - private ITaskManager taskManager; - private RepositoryPathConfiguration repositoryPathConfiguration; - private IGitConfig gitConfig; - private Dictionary gitConfigGetResults; - - protected SubstituteFactory SubstituteFactory { get; private set; } - - private RepositoryManager CreateRepositoryManager(IGitClient gitClient) - { - return new RepositoryManager(platform, taskManager, new NullUsageTracker(), gitConfig, repositoryWatcher, - gitClient, repositoryPathConfiguration, cancellationToken); - } - - private IGitClient CreateRepositoryProcessRunner(GitStatus? gitStatusResults = null, - List gitListLocksResults = null) - { - return - SubstituteFactory.CreateRepositoryProcessRunner(new CreateRepositoryProcessRunnerOptions { - GitConfigGetResults = gitConfigGetResults, - GitStatusResults = gitStatusResults, - GitListLocksResults = gitListLocksResults - }); - } - - [Test] - public void ShouldBeConstructable() - { - var repositoryProcessRunner = CreateRepositoryProcessRunner(); - var repositoryManager = CreateRepositoryManager(repositoryProcessRunner); - repositoryManager.Should().NotBeNull(); - } - - [Test] - public void ShouldNotRefreshIfNoGitStatusIsReturned() - { - var repositoryProcessRunner = CreateRepositoryProcessRunner(null, new List()); - var repositoryManager = CreateRepositoryManager(repositoryProcessRunner); - repositoryManager.Initialize(); - repositoryManager.Start(); - - var repositoryManagerListener = Substitute.For(); - repositoryManagerListener.AttachListener(repositoryManager); - - repositoryManager.Refresh(); - - Thread.Sleep(1000); - - repositoryManagerListener.AssertDidNotReceiveAnyCalls(); - } - - [Test] - public async Task ShouldRefreshAndReturnCombinedStatusAndLockInformation1() - { - var responseGitStatus = new GitStatus { - LocalBranch = "master", - Entries = - new List { - new GitStatusEntry("SomeLockedBinary.psd", null, "SomeLockedBinary.psd", GitFileStatus.Modified), - new GitStatusEntry("subFolder/AnotherLockedBinary.psd", null, "subFolder/AnotherLockedBinary.psd", GitFileStatus.Modified), - new GitStatusEntry("subFolder/UnLockedBinary.psd", null, "subFolder/UnLockedBinary.psd", GitFileStatus.Modified), - } - }; - - var responseGitLocks = new List { - new GitLock("SomeLockedBinary.psd", "SomeLockedBinary.psd", "Someone", 1), - new GitLock("SomeoneElsesBinary.psd", "SomeoneElsesBinary.psd", "SomeoneElse", 2), - new GitLock("subFolder/AnotherLockedBinary.psd", "subFolder/AnotherLockedBinary.psd", "Someone", 3), - }; - - var expectedGitStatus = new GitStatus { - LocalBranch = "master", - Entries = - new List { - new GitStatusEntry("SomeLockedBinary.psd", null, "SomeLockedBinary.psd", - GitFileStatus.Modified), - new GitStatusEntry("subFolder/AnotherLockedBinary.psd", null, "subFolder/AnotherLockedBinary.psd", - GitFileStatus.Modified), - new GitStatusEntry("subFolder/UnLockedBinary.psd", null, "subFolder/UnLockedBinary.psd", GitFileStatus.Modified), - } - }; - - var repositoryProcessRunner = CreateRepositoryProcessRunner(responseGitStatus, responseGitLocks); - - var repositoryManager = CreateRepositoryManager(repositoryProcessRunner); - repositoryManager.Initialize(); - repositoryManager.Start(); - - var repositoryManagerListener = Substitute.For(); - repositoryManagerListener.AttachListener(repositoryManager); - - GitStatus? result = null; - repositoryManager.OnStatusUpdated += s => { result = s; }; - - repositoryManager.Refresh(); - - await TaskEx.Delay(1000); - - repositoryManagerListener.Received(1).OnStatusUpdate(Args.GitStatus); - - result.HasValue.Should().BeTrue(); - result.Value.AssertEqual(expectedGitStatus); - - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); - } - - [Test] - public void ShouldRefreshAndReturnCombinedStatusAndLockInformation2() - { - var responseGitStatus = new GitStatus { - LocalBranch = "master", - Entries = - new List { - new GitStatusEntry("SomeLockedBinary.psd", null, "SomeLockedBinary.psd", GitFileStatus.Modified), - new GitStatusEntry("subFolder/AnotherLockedBinary.psd", null, "subFolder/AnotherLockedBinary.psd", GitFileStatus.Modified), - new GitStatusEntry("subFolder/UnLockedBinary.psd", null, "subFolder/UnLockedBinary.psd", GitFileStatus.Modified), - } - }; - - var responseGitLocks = new List { - new GitLock("SomeLockedBinary.psd", "SomeLockedBinary.psd", "Someone", 1), - new GitLock("SomeoneElsesBinary.psd", "SomeoneElsesBinary.psd", "SomeoneElse", 2), - new GitLock("subFolder/AnotherLockedBinary.psd", "subFolder/AnotherLockedBinary.psd", "Someone", 3), - }; - - var expectedGitStatus = new GitStatus { - LocalBranch = "master", - Entries = - new List { - new GitStatusEntry("SomeLockedBinary.psd", null, "SomeLockedBinary.psd", GitFileStatus.Modified), - new GitStatusEntry("subFolder/AnotherLockedBinary.psd", null, "subFolder/AnotherLockedBinary.psd", GitFileStatus.Modified), - new GitStatusEntry("subFolder/UnLockedBinary.psd", null, "subFolder/UnLockedBinary.psd", GitFileStatus.Modified - - //This lock intentionally left missing to catch false positives - //,gitLock: new GitLock("subFolder/AnotherLockedBinary.psd", "subFolder/AnotherLockedBinary.psd", "Someone") - - ), - } - }; - - var repositoryProcessRunner = CreateRepositoryProcessRunner(responseGitStatus, responseGitLocks); - - var repositoryManager = CreateRepositoryManager(repositoryProcessRunner); - repositoryManager.Initialize(); - repositoryManager.Start(); - - var repositoryManagerListener = Substitute.For(); - repositoryManagerListener.AttachListener(repositoryManager); - - GitStatus? result = null; - repositoryManager.OnStatusUpdated += s => { result = s; }; - - repositoryManager.Refresh(); - - Thread.Sleep(1000); - - repositoryManagerListener.Received(1).OnStatusUpdate(Args.GitStatus); - - result.HasValue.Should().BeTrue(); - result.Value.AssertNotEqual(expectedGitStatus); - - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); - } - - [Test] - public void ShouldRefreshAndReturnWithEmptyGitLockResponse() - { - var responseGitStatus = new GitStatus { - LocalBranch = "master", - Entries = - new List { - new GitStatusEntry("Some.sln", null, "Some.sln", GitFileStatus.Modified) - } - }; - - var repositoryProcessRunner = CreateRepositoryProcessRunner(responseGitStatus, new List()); - - var repositoryManager = CreateRepositoryManager(repositoryProcessRunner); - repositoryManager.Initialize(); - repositoryManager.Start(); - - var repositoryManagerListener = Substitute.For(); - repositoryManagerListener.AttachListener(repositoryManager); - - GitStatus? result = null; - repositoryManager.OnStatusUpdated += s => { result = s; }; - - repositoryManager.Refresh(); - - Thread.Sleep(1000); - - repositoryManagerListener.Received(1).OnStatusUpdate(Args.GitStatus); - - result.HasValue.Should().BeTrue(); - result.Value.AssertEqual(responseGitStatus); - - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); - } - - [Test] - public void ShouldRefreshAndReturnWithNoGitLockResponse() - { - var responseGitStatus = new GitStatus { - LocalBranch = "master", - Entries = - new List { - new GitStatusEntry("Some.sln", null, "Some.sln", GitFileStatus.Modified) - } - }; - - var repositoryProcessRunner = CreateRepositoryProcessRunner(responseGitStatus, new List()); - - var repositoryManager = CreateRepositoryManager(repositoryProcessRunner); - repositoryManager.Initialize(); - repositoryManager.Start(); - - var repositoryManagerListener = Substitute.For(); - repositoryManagerListener.AttachListener(repositoryManager); - - GitStatus? result = null; - repositoryManager.OnStatusUpdated += s => { result = s; }; - - repositoryManager.Refresh(); - - Thread.Sleep(1000); - - repositoryManagerListener.Received(1).OnStatusUpdate(Args.GitStatus); - - result.HasValue.Should().BeTrue(); - result.Value.AssertEqual(responseGitStatus); - - repositoryManagerListener.DidNotReceive().OnHeadChanged(); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); - } - } -} diff --git a/src/tests/UnitTests/SetUpFixture.cs b/src/tests/UnitTests/SetUpFixture.cs index 61032b102..879a2a475 100644 --- a/src/tests/UnitTests/SetUpFixture.cs +++ b/src/tests/UnitTests/SetUpFixture.cs @@ -12,7 +12,10 @@ public void SetUp() { Logging.TracingEnabled = true; - Logging.LogAdapter = new MultipleLogAdapter(new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-unit-tests.log"), new ConsoleLogAdapter()); + Logging.LogAdapter = new MultipleLogAdapter( + new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-unit-tests.log"), + new ConsoleLogAdapter() + ); } } } \ No newline at end of file diff --git a/src/tests/UnitTests/UnitTests.csproj b/src/tests/UnitTests/UnitTests.csproj index 2be5fd1db..a6f9d70ad 100644 --- a/src/tests/UnitTests/UnitTests.csproj +++ b/src/tests/UnitTests/UnitTests.csproj @@ -100,7 +100,6 @@ - From 398ae8d49fbe15755f8401b0767988366e31195c Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 15 Sep 2017 17:37:07 -0400 Subject: [PATCH 12/57] Moving log message to external function --- src/GitHub.Api/Git/RepositoryManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index 2d4a5cbfb..8580d1f31 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -450,6 +450,8 @@ private void UpdateConfigData(bool resetConfig = false) private void LoadBranchesFromConfig() { + Logger.Trace("LoadBranchesFromConfig"); + var branches = new Dictionary(); LoadBranchesFromConfig(branches, repositoryPaths.BranchesPath, config.GetBranches().Where(x => x.IsTracking), ""); OnLocalBranchListUpdated?.Invoke(branches); @@ -457,8 +459,6 @@ private void LoadBranchesFromConfig() private void LoadBranchesFromConfig(Dictionary branches, NPath path, IEnumerable configBranches, string prefix) { - Logger.Trace("LoadBranchesFromConfig"); - foreach (var file in path.Files()) { var branchName = prefix + file.FileName; From b025c2cb0e3c8c7e7cf9cfb11affe67f9704a509 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 15 Sep 2017 18:09:05 -0400 Subject: [PATCH 13/57] Removing references from UnitTest project --- src/tests/UnitTests/UnitTests.csproj | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/tests/UnitTests/UnitTests.csproj b/src/tests/UnitTests/UnitTests.csproj index a6f9d70ad..f5b4b5ed4 100644 --- a/src/tests/UnitTests/UnitTests.csproj +++ b/src/tests/UnitTests/UnitTests.csproj @@ -68,12 +68,6 @@ - - $(UnityDir)UnityEditor.dll - - - $(UnityDir)UnityEngine.dll - From b7076c3f17017588d5544598ef6135c1122eb7c7 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 15 Sep 2017 19:08:05 -0400 Subject: [PATCH 14/57] Fixing up tests --- src/GitHub.Api/Git/Repository.cs | 47 ++-- .../IntegrationTests/BaseIntegrationTest.cs | 1 + .../Events/RepositoryManagerTests.cs | 212 ++++++++++-------- .../Events/IRepositoryManagerListener.cs | 1 - 4 files changed, 146 insertions(+), 115 deletions(-) diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 4299e087f..2ff4d61fc 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -171,20 +171,25 @@ private void RepositoryManager_OnHeadUpdated(string h) if (head != h) { head = h; - var branch = GetCurrentBranch(); - var remote = GetCurrentRemote(); + UpdateCurrentBranchAndRemote(); + } + } - if (!Nullable.Equals(currentBranch, branch)) - { - currentBranch = branch; - OnCurrentBranchChanged?.Invoke(currentBranch.HasValue ? currentBranch.Value.Name : null); - } + private void UpdateCurrentBranchAndRemote() + { + var branch = GetCurrentBranch(); + var remote = GetCurrentRemote(); - if (!Nullable.Equals(currentRemote, remote)) - { - CurrentRemote = remote; - OnCurrentRemoteChanged?.Invoke(currentRemote.HasValue ? currentRemote.Value.Name : null); - } + if (!Nullable.Equals(currentBranch, branch)) + { + currentBranch = branch; + OnCurrentBranchChanged?.Invoke(currentBranch.HasValue ? currentBranch.Value.Name : null); + } + + if (!Nullable.Equals(currentRemote, remote)) + { + CurrentRemote = remote; + OnCurrentRemoteChanged?.Invoke(currentRemote.HasValue ? currentRemote.Value.Name : null); } } @@ -235,15 +240,15 @@ private void RepositoryManager_OnLocalBranchUpdated(string name) private void RepositoryManager_OnRemoteBranchAdded(string remote, string name) { - Dictionary branchList; - if (remoteBranches.TryGetValue(remote, out branchList)) - { - if (!branchList.ContainsKey(name)) - { - branchList.Add(name, new ConfigBranch { Name = name, Remote = remotes[remote] }); - OnRemoteBranchListChanged?.Invoke(); - } - } +// Dictionary branchList; +// if (remoteBranches.TryGetValue(remote, out branchList)) +// { +// if (!branchList.ContainsKey(name)) +// { +// branchList.Add(name, new ConfigBranch { Name = name, Remote = remotes[remote] }); +// OnRemoteBranchListChanged?.Invoke(); +// } +// } } private void RepositoryManager_OnRemoteBranchRemoved(string remote, string name) diff --git a/src/tests/IntegrationTests/BaseIntegrationTest.cs b/src/tests/IntegrationTests/BaseIntegrationTest.cs index 8dee89a8d..fce868c0b 100644 --- a/src/tests/IntegrationTests/BaseIntegrationTest.cs +++ b/src/tests/IntegrationTests/BaseIntegrationTest.cs @@ -13,6 +13,7 @@ class BaseIntegrationTest protected NPath TestBasePath { get; private set; } protected ILogging Logger { get; private set; } public IEnvironment Environment { get; set; } + public IRepository Repository => Environment.Repository; protected TestUtils.SubstituteFactory Factory { get; set; } protected static NPath SolutionDirectory => TestContext.CurrentContext.TestDirectory.ToNPath(); diff --git a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs index c74fc33be..8be8fa3ff 100644 --- a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs @@ -21,6 +21,20 @@ public override void OnSetup() repositoryManagerEvents = new RepositoryManagerEvents(); } + [Test] + public async Task ShouldDoNothingOnInitialize() + { + await Initialize(TestRepoMasterCleanSynchronized); + + var repositoryManagerListener = Substitute.For(); + repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); + + RepositoryManager.WaitForEvents(); + WaitForNotBusy(repositoryManagerEvents, 2); + + repositoryManagerListener.AssertDidNotReceiveAnyCalls(); + } + [Test] public async Task ShouldDetectFileChanges() { @@ -48,7 +62,8 @@ public async Task ShouldDetectFileChanges() await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents, 1); + WaitForNotBusy(repositoryManagerEvents); + WaitForStatusUpdated(repositoryManagerEvents); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); @@ -61,7 +76,6 @@ public async Task ShouldDetectFileChanges() repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); result.AssertEqual(expected); } @@ -97,9 +111,17 @@ public async Task ShouldAddAndCommitFiles() var testDocumentTxt = TestRepoMasterCleanSynchronized.Combine("Assets", "TestDocument.txt"); testDocumentTxt.WriteAllText("foobar"); + await TaskManager.Wait(); + + //Intentionally wait two cycles, in case the first cycle did not pick up all events RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents, 1); + WaitForNotBusy(repositoryManagerEvents); + WaitForStatusUpdated(repositoryManagerEvents); + + RepositoryManager.WaitForEvents(); + WaitForNotBusy(repositoryManagerEvents); + WaitForStatusUpdated(repositoryManagerEvents); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); @@ -112,7 +134,6 @@ public async Task ShouldAddAndCommitFiles() repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); result.AssertEqual(expectedAfterChanges); @@ -120,12 +141,12 @@ public async Task ShouldAddAndCommitFiles() repositoryManagerEvents.Reset(); await RepositoryManager - .CommitFiles(new List() { "Assets\\TestDocument.txt", "foobar.txt" }, "IntegrationTest Commit", string.Empty) + .CommitFiles(new List { "Assets\\TestDocument.txt", "foobar.txt" }, "IntegrationTest Commit", string.Empty) .StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents, 1); + WaitForNotBusy(repositoryManagerEvents); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); @@ -138,7 +159,6 @@ await RepositoryManager repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); } [Test] @@ -172,10 +192,11 @@ public async Task ShouldAddAndCommitAllFiles() var testDocumentTxt = TestRepoMasterCleanSynchronized.Combine("Assets", "TestDocument.txt"); testDocumentTxt.WriteAllText("foobar"); + await TaskManager.Wait(); - WaitForNotBusy(repositoryManagerEvents, 1); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents, 1); + WaitForNotBusy(repositoryManagerEvents); + WaitForStatusUpdated(repositoryManagerEvents); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); @@ -188,7 +209,6 @@ public async Task ShouldAddAndCommitAllFiles() repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); result.AssertEqual(expectedAfterChanges); @@ -201,7 +221,7 @@ await RepositoryManager await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents, 1); + WaitForNotBusy(repositoryManagerEvents); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); @@ -214,7 +234,6 @@ await RepositoryManager repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); } [Test] @@ -235,13 +254,14 @@ public async Task ShouldDetectBranchChange() var result = new GitStatus(); RepositoryManager.OnStatusUpdated += status => { result = status; }; + Logger.Trace("Starting test"); + await RepositoryManager.SwitchBranch(expectedLocalBranch).StartAsAsync(); + await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents, 5); - - repositoryManagerEvents.OnStatusUpdated.WaitOne(TimeSpan.FromSeconds(5)); - repositoryManagerEvents.OnStatusUpdated.WaitOne(TimeSpan.FromSeconds(5)); + WaitForNotBusy(repositoryManagerEvents); + WaitForStatusUpdated(repositoryManagerEvents); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); @@ -254,7 +274,6 @@ public async Task ShouldDetectBranchChange() repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); result.AssertEqual(expected); } @@ -271,7 +290,7 @@ public async Task ShouldDetectBranchDelete() await RepositoryManager.DeleteBranch(deletedBranch, true).StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents, 1); + WaitForNotBusy(repositoryManagerEvents); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); @@ -284,7 +303,6 @@ public async Task ShouldDetectBranchDelete() repositoryManagerListener.Received().OnLocalBranchRemoved(deletedBranch); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); } [Test] @@ -299,6 +317,7 @@ public async Task ShouldDetectBranchCreate() await RepositoryManager.CreateBranch(createdBranch1, "feature/document").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); + WaitForNotBusy(repositoryManagerEvents); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); @@ -311,7 +330,6 @@ public async Task ShouldDetectBranchCreate() repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); repositoryManagerListener.ClearReceivedCalls(); repositoryManagerEvents.Reset(); @@ -320,6 +338,7 @@ public async Task ShouldDetectBranchCreate() await RepositoryManager.CreateBranch(createdBranch2, "feature/document").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); + WaitForNotBusy(repositoryManagerEvents); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); @@ -332,7 +351,6 @@ public async Task ShouldDetectBranchCreate() repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); } [Test] @@ -342,41 +360,23 @@ public async Task ShouldDetectChangesToRemotes() var repositoryManagerListener = Substitute.For(); repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); - - Environment.Repository.CurrentRemote.HasValue.Should().BeTrue(); - Environment.Repository.CurrentRemote.Value.Name.Should().Be("origin"); - Environment.Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); - - Environment.Repository.CloneUrl.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); - Environment.Repository.Owner.Should().Be("EvilStanleyGoldman"); - - Logger.Trace("Removing Remote"); - + await RepositoryManager.RemoteRemove("origin").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - - Logger.Trace("Continue Test"); - - //TODO: Continue from here - - Environment.Repository.CurrentRemote.HasValue.Should().BeFalse(); - - Environment.Repository.CloneUrl.Should().BeNull(); - Environment.Repository.Owner.Should().BeNull(); + WaitForNotBusy(repositoryManagerEvents); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); - repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); + repositoryManagerListener.Received().OnRemoteBranchRemoved(Args.String, Args.String); repositoryManagerListener.ClearReceivedCalls(); repositoryManagerEvents.Reset(); @@ -384,26 +384,19 @@ public async Task ShouldDetectChangesToRemotes() await RepositoryManager.RemoteAdd("origin", "https://github.com/EvilShana/IOTestsRepo.git").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - - Environment.Repository.CurrentRemote.HasValue.Should().BeTrue(); - Environment.Repository.CurrentRemote.Value.Name.Should().Be("origin"); - Environment.Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilShana/IOTestsRepo.git"); - - Environment.Repository.CloneUrl.Should().Be("https://github.com/EvilShana/IOTestsRepo.git"); - Environment.Repository.Owner.Should().Be("EvilShana"); + WaitForNotBusy(repositoryManagerEvents); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); - repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); } [Test] @@ -416,21 +409,24 @@ public async Task ShouldDetectChangesToRemotesWhenSwitchingBranches() var repositoryManagerListener = Substitute.For(); repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); - Environment.Repository.CurrentRemote.HasValue.Should().BeTrue(); - Environment.Repository.CurrentRemote.Value.Name.Should().Be("origin"); - Environment.Repository.CurrentRemote.Value.Url.Should().Be(expectedCloneUrl); - Environment.Repository.Owner.Should().Be("EvilStanleyGoldman"); - await RepositoryManager.CreateBranch("branch2", "another/master") - //.Then(RepositoryManager.SwitchBranch("branch2")) .StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); + WaitForNotBusy(repositoryManagerEvents); + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); - repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.Received().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); repositoryManagerListener.ClearReceivedCalls(); repositoryManagerEvents.Reset(); @@ -440,18 +436,20 @@ await RepositoryManager.SwitchBranch("branch2") await TaskManager.Wait(); RepositoryManager.WaitForEvents(); + WaitForNotBusy(repositoryManagerEvents); + WaitForHeadUpdated(repositoryManagerEvents); - Environment.Repository.CurrentRemote.HasValue.Should().BeTrue(); - Environment.Repository.CurrentRemote.Value.Name.Should().Be("another"); - - var expectedRemoteUrl = "https://another.remote/Owner/Url.git"; - Environment.Repository.CurrentRemote.Value.Url.Should().Be(expectedRemoteUrl); - Environment.Repository.CloneUrl.ToString().Should().Be(expectedRemoteUrl); - Environment.Repository.Owner.Should().Be("Owner"); - - repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.Received().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); } [Test] @@ -462,25 +460,22 @@ public async Task ShouldUpdateCloneUrlIfRemoteIsDeleted() var repositoryManagerListener = Substitute.For(); repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); - Environment.Repository.CurrentRemote.HasValue.Should().BeTrue(); - Environment.Repository.CurrentRemote.Value.Name.Should().Be("origin"); - Environment.Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); - - Environment.Repository.CloneUrl.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); - Environment.Repository.Owner.Should().Be("EvilStanleyGoldman"); - await RepositoryManager.RemoteRemove("origin").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); + WaitForNotBusy(repositoryManagerEvents); - Environment.Repository.CurrentRemote.HasValue.Should().BeFalse(); - - Environment.Repository.CloneUrl.Should().BeNull(); - Environment.Repository.Owner.Should().BeNull(); - + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); - repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.Received().OnRemoteBranchRemoved(Args.String, Args.String); repositoryManagerListener.ClearReceivedCalls(); repositoryManagerEvents.Reset(); @@ -489,15 +484,17 @@ public async Task ShouldUpdateCloneUrlIfRemoteIsDeleted() await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - Environment.Repository.CurrentRemote.HasValue.Should().BeTrue(); - Environment.Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilShana/IOTestsRepo.git"); - - Environment.Repository.CloneUrl.Should().Be("https://github.com/EvilShana/IOTestsRepo.git"); - Environment.Repository.Owner.Should().Be("EvilShana"); - + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); - repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); } [Test] @@ -520,15 +517,25 @@ public async Task ShouldDetectGitPull() await RepositoryManager.Pull("origin", "master").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); + WaitForNotBusy(repositoryManagerEvents); + WaitForStatusUpdated(repositoryManagerEvents); + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); - repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.Received().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); result.AssertEqual(expected); repositoryManagerEvents.Reset(); - WaitForNotBusy(repositoryManagerEvents, 1); + WaitForNotBusy(repositoryManagerEvents); } [Test] @@ -542,10 +549,19 @@ public async Task ShouldDetectGitFetch() await RepositoryManager.Fetch("origin").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); + WaitForNotBusy(repositoryManagerEvents); + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); - repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.Received().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); } private void WaitForNotBusy(RepositoryManagerEvents managerEvents, int seconds = 1) @@ -553,5 +569,15 @@ private void WaitForNotBusy(RepositoryManagerEvents managerEvents, int seconds = managerEvents.OnIsBusy.WaitOne(TimeSpan.FromSeconds(seconds)); managerEvents.OnIsNotBusy.WaitOne(TimeSpan.FromSeconds(seconds)); } + + private void WaitForStatusUpdated(RepositoryManagerEvents managerEvents, int seconds = 1) + { + managerEvents.OnStatusUpdated.WaitOne(TimeSpan.FromSeconds(seconds)); + } + + private void WaitForHeadUpdated(RepositoryManagerEvents managerEvents, int seconds = 1) + { + managerEvents.OnHeadUpdated.WaitOne(TimeSpan.FromSeconds(seconds)); + } } } diff --git a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs index c289203ae..6b7e6c7c1 100644 --- a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs +++ b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs @@ -153,7 +153,6 @@ public static void AssertDidNotReceiveAnyCalls(this IRepositoryManagerListener r repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnGitUserLoaded(Arg.Any()); } } }; \ No newline at end of file From db2d304f85a007f4bbab7340c4553a116db1a76a Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 15 Sep 2017 19:51:03 -0400 Subject: [PATCH 15/57] Last bit of test fixes --- src/GitHub.Api/Git/RepositoryManager.cs | 5 +++- .../Events/IRepositoryManagerListener.cs | 26 +++++++++---------- src/tests/TestUtils/Helpers/Args.cs | 1 + 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index 8580d1f31..0f27bfa16 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -324,7 +324,10 @@ private void LoadGitUser() .Then((success, value) => user.Name = value).Then( GitClient.GetConfig("user.email", GitConfigSource.User) .Then((success, value) => user.Email = value)) - .Then(() => OnGitUserLoaded?.Invoke(user)) + .Then(() => { + Logger.Trace("OnGitUserLoaded: {0}", user); + OnGitUserLoaded?.Invoke(user); + }) .Start(); } diff --git a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs index 6b7e6c7c1..271a05b90 100644 --- a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs +++ b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs @@ -24,19 +24,19 @@ interface IRepositoryManagerListener class RepositoryManagerEvents { - public EventWaitHandle OnIsBusy { get; } = new ManualResetEvent(false); - public EventWaitHandle OnIsNotBusy { get; } = new ManualResetEvent(false); - public EventWaitHandle OnStatusUpdated { get; } = new ManualResetEvent(false); - public EventWaitHandle OnLocksUpdated { get; } = new ManualResetEvent(false); - public EventWaitHandle OnHeadUpdated { get; } = new ManualResetEvent(false); - public EventWaitHandle OnLocalBranchListUpdated { get; } = new ManualResetEvent(false); - public EventWaitHandle OnRemoteBranchListUpdated { get; } = new ManualResetEvent(false); - public EventWaitHandle OnLocalBranchUpdated { get; } = new ManualResetEvent(false); - public EventWaitHandle OnLocalBranchAdded { get; } = new ManualResetEvent(false); - public EventWaitHandle OnLocalBranchRemoved { get; } = new ManualResetEvent(false); - public EventWaitHandle OnRemoteBranchAdded { get; } = new ManualResetEvent(false); - public EventWaitHandle OnRemoteBranchRemoved { get; } = new ManualResetEvent(false); - public EventWaitHandle OnGitUserLoaded { get; } = new ManualResetEvent(false); + public EventWaitHandle OnIsBusy { get; } = new AutoResetEvent(false); + public EventWaitHandle OnIsNotBusy { get; } = new AutoResetEvent(false); + public EventWaitHandle OnStatusUpdated { get; } = new AutoResetEvent(false); + public EventWaitHandle OnLocksUpdated { get; } = new AutoResetEvent(false); + public EventWaitHandle OnHeadUpdated { get; } = new AutoResetEvent(false); + public EventWaitHandle OnLocalBranchListUpdated { get; } = new AutoResetEvent(false); + public EventWaitHandle OnRemoteBranchListUpdated { get; } = new AutoResetEvent(false); + public EventWaitHandle OnLocalBranchUpdated { get; } = new AutoResetEvent(false); + public EventWaitHandle OnLocalBranchAdded { get; } = new AutoResetEvent(false); + public EventWaitHandle OnLocalBranchRemoved { get; } = new AutoResetEvent(false); + public EventWaitHandle OnRemoteBranchAdded { get; } = new AutoResetEvent(false); + public EventWaitHandle OnRemoteBranchRemoved { get; } = new AutoResetEvent(false); + public EventWaitHandle OnGitUserLoaded { get; } = new AutoResetEvent(false); public void Reset() { diff --git a/src/tests/TestUtils/Helpers/Args.cs b/src/tests/TestUtils/Helpers/Args.cs index c9bee3617..650d65e73 100644 --- a/src/tests/TestUtils/Helpers/Args.cs +++ b/src/tests/TestUtils/Helpers/Args.cs @@ -17,6 +17,7 @@ static class Args public static GitConfigSource GitConfigSource { get { return Arg.Any(); } } public static GitStatus GitStatus { get { return Arg.Any(); } } public static IEnumerable EnumerableGitLock { get { return Arg.Any>(); } } + public static IUser User { get { return Arg.Any(); } } public static ITask GitStatusTask { From 175603585535415f2ab8dbc4cf4aaa9e370e69ce Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 11:16:03 -0400 Subject: [PATCH 16/57] Adding tests for Repository --- src/GitHub.Api/Git/IRepository.cs | 1 + src/GitHub.Api/Git/Repository.cs | 83 +++++------- src/GitHub.Api/Git/RepositoryManager.cs | 2 +- .../TestUtils/Events/IRepositoryListener.cs | 120 ++++++++++++++++++ src/tests/TestUtils/TestUtils.csproj | 1 + src/tests/UnitTests/Git/RepositoryTests.cs | 107 ++++++++++++++++ src/tests/UnitTests/UnitTests.csproj | 1 + 7 files changed, 264 insertions(+), 51 deletions(-) create mode 100644 src/tests/TestUtils/Events/IRepositoryListener.cs create mode 100644 src/tests/UnitTests/Git/RepositoryTests.cs diff --git a/src/GitHub.Api/Git/IRepository.cs b/src/GitHub.Api/Git/IRepository.cs index d77b87bc3..24b300edb 100644 --- a/src/GitHub.Api/Git/IRepository.cs +++ b/src/GitHub.Api/Git/IRepository.cs @@ -64,5 +64,6 @@ interface IRepository : IEquatable event Action OnHeadChanged; event Action> OnLocksChanged; event Action OnRepositoryInfoChanged; + event Action OnRemoteBranchListChanged; } } \ No newline at end of file diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 2ff4d61fc..faa22c184 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -168,6 +168,8 @@ private void RepositoryManager_OnLocksUpdated(IEnumerable locks) private void RepositoryManager_OnHeadUpdated(string h) { + Logger.Trace("HeadUpdated"); + if (head != h) { head = h; @@ -177,30 +179,49 @@ private void RepositoryManager_OnHeadUpdated(string h) private void UpdateCurrentBranchAndRemote() { - var branch = GetCurrentBranch(); - var remote = GetCurrentRemote(); + ConfigBranch? branch = null; + + if (head.StartsWith("ref:")) + { + var branchName = head.Substring(head.IndexOf("refs/heads/") + "refs/heads/".Length); + branch = GetBranch(branchName); + } + + CurrentBranch = branch; + + var defaultRemote = "origin"; + ConfigRemote? remote = null; + + if (currentBranch.HasValue && currentBranch.Value.IsTracking) + { + remote = currentBranch.Value.Remote; + } - if (!Nullable.Equals(currentBranch, branch)) + if (!remote.HasValue) { - currentBranch = branch; - OnCurrentBranchChanged?.Invoke(currentBranch.HasValue ? currentBranch.Value.Name : null); + remote = repositoryManager.Config.GetRemote(defaultRemote); } - if (!Nullable.Equals(currentRemote, remote)) + if (!remote.HasValue) { - CurrentRemote = remote; - OnCurrentRemoteChanged?.Invoke(currentRemote.HasValue ? currentRemote.Value.Name : null); + remote = repositoryManager.Config.GetRemotes().FirstOrDefault(); } + + CurrentRemote = remote; } private void RepositoryManager_OnRemoteBranchListUpdated(Dictionary> branches) { + Logger.Trace("RemoveBranchListUpdated"); + remoteBranches = branches; OnRemoteBranchListChanged?.Invoke(); } private void RepositoryManager_OnLocalBranchListUpdated(Dictionary branches) { + Logger.Trace("LocalBranchListUpdated"); + localBranches = branches; OnLocalBranchListChanged?.Invoke(); } @@ -263,20 +284,6 @@ private void RepositoryManager_OnRemoteBranchRemoved(string remote, string name) } } } - - private ConfigBranch? GetCurrentBranch() - { - if (head.StartsWith("ref:")) - { - var branch = head.Substring(head.IndexOf("refs/heads/") + "refs/heads/".Length); - currentBranch = GetBranch(branch); - } - else - { - currentBranch = null; - } - return currentBranch; - } private ConfigBranch? GetBranch(string name) { @@ -288,30 +295,6 @@ private void RepositoryManager_OnRemoteBranchRemoved(string remote, string name) return null; } - private ConfigRemote? GetCurrentRemote(string defaultRemote = "origin") - { - if (currentBranch.HasValue && currentBranch.Value.IsTracking) - { - return currentBranch.Value.Remote; - } - - var remote = repositoryManager.Config.GetRemote(defaultRemote); - if (remote.HasValue) - { - return remote; - } - - using (var remoteEnumerator = repositoryManager.Config.GetRemotes().GetEnumerator()) - { - if (remoteEnumerator.MoveNext()) - { - return remoteEnumerator.Current; - } - } - - return null; - } - /// /// Note: We don't consider CloneUrl a part of the hash code because it can change during the lifetime /// of a repository. Equals takes care of any hash collisions because of this @@ -348,10 +331,10 @@ public ConfigBranch? CurrentBranch get { return currentBranch; } set { - if (currentBranch.HasValue != value.HasValue || (currentBranch.HasValue && !currentBranch.Value.Equals(value.Value))) + if (!Nullable.Equals(currentBranch, value)) { currentBranch = value; - Logger.Trace("OnActiveBranchChanged: {0}", value?.ToString() ?? "NULL"); + Logger.Trace("OnCurrentBranchChanged: {0}", value?.ToString() ?? "NULL"); OnCurrentBranchChanged?.Invoke(CurrentBranch.HasValue ? CurrentBranch.Value.Name : null); } } @@ -370,11 +353,11 @@ public ConfigRemote? CurrentRemote get { return currentRemote; } set { - if (currentRemote.HasValue != value.HasValue || (currentRemote.HasValue && !currentRemote.Value.Equals(value.Value))) + if (!Nullable.Equals(currentRemote, value)) { currentRemote = value; SetCloneUrl(); - Logger.Trace("OnActiveRemoteChanged: {0}", value?.ToString() ?? "NULL"); + Logger.Trace("OnCurrentRemoteChanged: {0}", value?.ToString() ?? "NULL"); OnCurrentRemoteChanged?.Invoke(CurrentRemote.HasValue ? CurrentRemote.Value.Name : null); } } diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index 0f27bfa16..2ff1a40aa 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -158,8 +158,8 @@ public void Start() { Logger.Trace("Start"); - UpdateHead(); UpdateConfigData(); + UpdateHead(); LoadGitUser(); watcher.Start(); } diff --git a/src/tests/TestUtils/Events/IRepositoryListener.cs b/src/tests/TestUtils/Events/IRepositoryListener.cs new file mode 100644 index 000000000..0b4ab2276 --- /dev/null +++ b/src/tests/TestUtils/Events/IRepositoryListener.cs @@ -0,0 +1,120 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using GitHub.Unity; +using NSubstitute; + +namespace TestUtils.Events +{ + interface IRepositoryListener + { + void OnStatusChanged(GitStatus status); + void OnCurrentBranchChanged(string branch); + void OnCurrentRemoteChanged(string remote); + void OnLocalBranchListChanged(); + void OnRemoteBranchListChanged(); + void OnHeadChanged(); + void OnLocksChanged(IEnumerable locks); + void OnRepositoryInfoChanged(); + } + + class RepositoryEvents + { + public EventWaitHandle OnStatusChanged { get; } = new AutoResetEvent(false); + public EventWaitHandle OnCurrentBranchChanged { get; } = new AutoResetEvent(false); + public EventWaitHandle OnCurrentRemoteChanged { get; } = new AutoResetEvent(false); + public EventWaitHandle OnLocalBranchListChanged { get; } = new AutoResetEvent(false); + public EventWaitHandle OnRemoteBranchListChanged { get; } = new AutoResetEvent(false); + public EventWaitHandle OnHeadChanged { get; } = new AutoResetEvent(false); + public EventWaitHandle OnLocksChanged { get; } = new AutoResetEvent(false); + public EventWaitHandle OnRepositoryInfoChanged { get; } = new AutoResetEvent(false); + + public void Reset() + { + OnStatusChanged.Reset(); + OnCurrentBranchChanged.Reset(); + OnCurrentRemoteChanged.Reset(); + OnLocalBranchListChanged.Reset(); + OnRemoteBranchListChanged.Reset(); + OnHeadChanged.Reset(); + OnLocksChanged.Reset(); + OnRepositoryInfoChanged.Reset(); + } + } + + static class RepositoryListenerExtensions + { + public static void AttachListener(this IRepositoryListener listener, + IRepository repository, RepositoryEvents repositoryEvents = null, bool trace = true) + { + var logger = trace ? Logging.GetLogger() : null; + + repository.OnStatusChanged += gitStatus => + { + logger?.Trace("OnStatusChanged: {0}", gitStatus); + listener.OnStatusChanged(gitStatus); + repositoryEvents?.OnStatusChanged.Set(); + }; + + repository.OnCurrentBranchChanged += name => + { + logger?.Debug("OnCurrentBranchChanged: {0}", name); + listener.OnCurrentBranchChanged(name); + repositoryEvents?.OnCurrentBranchChanged.Set(); + }; + + repository.OnCurrentRemoteChanged += name => + { + logger?.Debug("OnCurrentRemoteChanged: {0}", name); + listener.OnCurrentRemoteChanged(name); + repositoryEvents?.OnCurrentRemoteChanged.Set(); + }; + + repository.OnLocalBranchListChanged += () => + { + logger?.Debug("OnLocalBranchListChanged"); + listener.OnLocalBranchListChanged(); + repositoryEvents?.OnLocalBranchListChanged.Set(); + }; + + repository.OnRemoteBranchListChanged += () => + { + logger?.Debug("OnRemoteBranchListChanged"); + listener.OnRemoteBranchListChanged(); + repositoryEvents?.OnRemoteBranchListChanged.Set(); + }; + + repository.OnHeadChanged += () => + { + logger?.Debug("OnHeadChanged"); + listener.OnHeadChanged(); + repositoryEvents?.OnHeadChanged.Set(); + }; + + repository.OnLocksChanged += locks => + { + logger?.Debug("OnLocksChanged: {0}", locks); + listener.OnLocksChanged(locks); + repositoryEvents?.OnLocksChanged.Set(); + }; + + repository.OnRepositoryInfoChanged += () => + { + logger?.Debug("OnRepositoryInfoChanged"); + listener.OnRepositoryInfoChanged(); + repositoryEvents?.OnRepositoryInfoChanged.Set(); + }; + } + + public static void AssertDidNotReceiveAnyCalls(this IRepositoryListener repositoryListener) + { + repositoryListener.DidNotReceive().OnStatusChanged(Args.GitStatus); + repositoryListener.DidNotReceive().OnCurrentBranchChanged(Args.String); + repositoryListener.DidNotReceive().OnCurrentRemoteChanged(Args.String); + repositoryListener.DidNotReceive().OnLocalBranchListChanged(); + repositoryListener.DidNotReceive().OnHeadChanged(); + repositoryListener.DidNotReceive().OnLocksChanged(Arg.Any>()); + repositoryListener.DidNotReceive().OnRepositoryInfoChanged(); + } + } +}; \ No newline at end of file diff --git a/src/tests/TestUtils/TestUtils.csproj b/src/tests/TestUtils/TestUtils.csproj index d0f7c53f4..e2072b12b 100644 --- a/src/tests/TestUtils/TestUtils.csproj +++ b/src/tests/TestUtils/TestUtils.csproj @@ -58,6 +58,7 @@ + diff --git a/src/tests/UnitTests/Git/RepositoryTests.cs b/src/tests/UnitTests/Git/RepositoryTests.cs new file mode 100644 index 000000000..0bae7bf40 --- /dev/null +++ b/src/tests/UnitTests/Git/RepositoryTests.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using FluentAssertions; +using GitHub.Unity; +using NCrunch.Framework; +using NSubstitute; +using NUnit.Framework; +using TestUtils; +using TestUtils.Events; + +namespace UnitTests +{ + [TestFixture, Isolated] + public class RepositoryTests + { + private static readonly SubstituteFactory SubstituteFactory = new SubstituteFactory(); + + private static Repository LoadRepository() + { + var fileSystem = SubstituteFactory.CreateFileSystem( + new CreateFileSystemOptions + { + + }); + + NPath.FileSystem = fileSystem; + + return new Repository("TestRepo", @"C:\Repo".ToNPath()); + } + + private RepositoryEvents repositoryEvents; + + [SetUp] + public void OnSetup() + { + repositoryEvents = new RepositoryEvents(); + } + + [Test] + public void Repository() + { + var repository = LoadRepository(); + var repositoryManager = Substitute.For(); + + var repositoryListener = Substitute.For(); + repositoryListener.AttachListener(repository, repositoryEvents); + + var origin = new ConfigRemote + { + Name = "origin", + Url = "https://github.com/someUser/someRepo.git" + }; + + var remotes = new[] { origin }; + + var remoteDictionary = remotes.ToDictionary(remote => remote.Name); + + var branches = new[] { + new ConfigBranch { Name = "master", Remote = origin }, + new ConfigBranch { Name = "features/feature-1", Remote = origin } + }; + + var branchDictionary = branches.ToDictionary(branch => branch.Name); + + var remoteBranches = new[] { + new ConfigBranch { Name = "master", Remote = origin }, + new ConfigBranch { Name = "features/feature-1", Remote = origin }, + new ConfigBranch { Name = "features/feature-2", Remote = origin } + }; + + var remoteBranchDictionary = remoteBranches + .GroupBy(branch => branch.Remote.Value.Name) + .ToDictionary(grouping => grouping.Key, + grouping => grouping.ToDictionary(branch => branch.Name)); + + repository.Initialize(repositoryManager); + + string expectedBranch = null; + repository.OnCurrentBranchChanged += branch => { + expectedBranch = branch; + }; + + string expectedRemote = null; + repository.OnCurrentRemoteChanged += remote => { + expectedRemote = remote; + }; + + repositoryManager.OnLocalBranchListUpdated += Raise.Event>>(branchDictionary); + + repositoryEvents.OnLocalBranchListChanged.WaitOne().Should().BeTrue(); + + repositoryManager.OnRemoteBranchListUpdated += Raise.Event>>>(remoteBranchDictionary); + + repositoryEvents.OnRemoteBranchListChanged.WaitOne().Should().BeTrue(); + + repositoryManager.OnHeadUpdated += Raise.Event>("ref:refs/heads/master"); + + repositoryEvents.OnCurrentBranchChanged.WaitOne().Should().BeTrue(); + repositoryEvents.OnCurrentRemoteChanged.WaitOne().Should().BeTrue(); + + expectedBranch.Should().Be("master"); + expectedRemote.Should().Be("origin"); + } + } +} diff --git a/src/tests/UnitTests/UnitTests.csproj b/src/tests/UnitTests/UnitTests.csproj index f5b4b5ed4..bf298220e 100644 --- a/src/tests/UnitTests/UnitTests.csproj +++ b/src/tests/UnitTests/UnitTests.csproj @@ -72,6 +72,7 @@ + From 9b5088a31e8a3afcaaf1f1c0fd24eef725c98c4b Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 14:06:42 -0400 Subject: [PATCH 17/57] Properly updating repository info --- src/GitHub.Api/Git/Repository.cs | 28 +++++++++++++++------- src/tests/UnitTests/Git/RepositoryTests.cs | 11 +++++---- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index faa22c184..d05ce0f67 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -145,13 +145,21 @@ public ITask ReleaseLock(string file, bool force) return repositoryManager.UnlockFile(file, force); } - private void SetCloneUrl() + private void UpdateRepositoryInfo() { if (CurrentRemote.HasValue) + { CloneUrl = new UriString(CurrentRemote.Value.Url); + Name = CloneUrl.RepositoryName; + Logger.Trace("CloneUrl: {0}", CloneUrl.ToString()); + } else + { CloneUrl = null; - Name = CloneUrl != null ? CloneUrl.RepositoryName : LocalPath.FileName; + Name = LocalPath.FileName; + Logger.Trace("CloneUrl: [NULL]"); + } + OnRepositoryInfoChanged?.Invoke(); } @@ -204,7 +212,11 @@ private void UpdateCurrentBranchAndRemote() if (!remote.HasValue) { - remote = repositoryManager.Config.GetRemotes().FirstOrDefault(); + var configRemotes = repositoryManager.Config.GetRemotes().ToArray(); + if (configRemotes.Any()) + { + remote = configRemotes.FirstOrDefault(); + } } CurrentRemote = remote; @@ -334,8 +346,8 @@ public ConfigBranch? CurrentBranch if (!Nullable.Equals(currentBranch, value)) { currentBranch = value; - Logger.Trace("OnCurrentBranchChanged: {0}", value?.ToString() ?? "NULL"); - OnCurrentBranchChanged?.Invoke(CurrentBranch.HasValue ? CurrentBranch.Value.Name : null); + Logger.Trace("OnCurrentBranchChanged: {0}", currentBranch.HasValue ? currentBranch.ToString() : "[NULL]"); + OnCurrentBranchChanged?.Invoke(currentBranch.HasValue ? currentBranch.Value.Name : null); } } } @@ -356,9 +368,9 @@ public ConfigRemote? CurrentRemote if (!Nullable.Equals(currentRemote, value)) { currentRemote = value; - SetCloneUrl(); - Logger.Trace("OnCurrentRemoteChanged: {0}", value?.ToString() ?? "NULL"); - OnCurrentRemoteChanged?.Invoke(CurrentRemote.HasValue ? CurrentRemote.Value.Name : null); + Logger.Trace("OnCurrentRemoteChanged: {0}", currentRemote.HasValue ? currentRemote.Value.ToString() : "[NULL]"); + OnCurrentRemoteChanged?.Invoke(currentRemote.HasValue ? currentRemote.Value.Name : null); + UpdateRepositoryInfo(); } } } diff --git a/src/tests/UnitTests/Git/RepositoryTests.cs b/src/tests/UnitTests/Git/RepositoryTests.cs index 0bae7bf40..ce1f36869 100644 --- a/src/tests/UnitTests/Git/RepositoryTests.cs +++ b/src/tests/UnitTests/Git/RepositoryTests.cs @@ -31,11 +31,13 @@ private static Repository LoadRepository() } private RepositoryEvents repositoryEvents; + private TimeSpan repositoryEventsTimeout; [SetUp] public void OnSetup() { repositoryEvents = new RepositoryEvents(); + repositoryEventsTimeout = TimeSpan.FromSeconds(0.5); } [Test] @@ -89,16 +91,17 @@ public void Repository() repositoryManager.OnLocalBranchListUpdated += Raise.Event>>(branchDictionary); - repositoryEvents.OnLocalBranchListChanged.WaitOne().Should().BeTrue(); + repositoryEvents.OnLocalBranchListChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnLocalBranchListChanged not raised"); repositoryManager.OnRemoteBranchListUpdated += Raise.Event>>>(remoteBranchDictionary); - repositoryEvents.OnRemoteBranchListChanged.WaitOne().Should().BeTrue(); + repositoryEvents.OnRemoteBranchListChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnRemoteBranchListChanged not raised"); repositoryManager.OnHeadUpdated += Raise.Event>("ref:refs/heads/master"); - repositoryEvents.OnCurrentBranchChanged.WaitOne().Should().BeTrue(); - repositoryEvents.OnCurrentRemoteChanged.WaitOne().Should().BeTrue(); + repositoryEvents.OnCurrentBranchChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnCurrentBranchChanged not raised"); + repositoryEvents.OnCurrentRemoteChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnCurrentRemoteChanged not raised"); + repositoryEvents.OnRepositoryInfoChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnRepositoryInfoChanged not raised"); expectedBranch.Should().Be("master"); expectedRemote.Should().Be("origin"); From e8fb83b685006d81310644d0156da0f03b4b7780 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 15:45:45 -0400 Subject: [PATCH 18/57] Uncommenting some code --- src/GitHub.Api/Git/Repository.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 17220f867..4efe39c25 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -273,15 +273,15 @@ private void RepositoryManager_OnLocalBranchUpdated(string name) private void RepositoryManager_OnRemoteBranchAdded(string remote, string name) { -// Dictionary branchList; -// if (remoteBranches.TryGetValue(remote, out branchList)) -// { -// if (!branchList.ContainsKey(name)) -// { -// branchList.Add(name, new ConfigBranch { Name = name, Remote = remotes[remote] }); -// OnRemoteBranchListChanged?.Invoke(); -// } -// } + Dictionary branchList; + if (remoteBranches.TryGetValue(remote, out branchList)) + { + if (!branchList.ContainsKey(name)) + { + branchList.Add(name, new ConfigBranch { Name = name, Remote = remotes[remote] }); + OnRemoteBranchListChanged?.Invoke(); + } + } } private void RepositoryManager_OnRemoteBranchRemoved(string remote, string name) From 090c54c786c15e46f1a2621304d8189d7f7c4c03 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 15:46:00 -0400 Subject: [PATCH 19/57] Removing ConsoleLogAdapter from SetUpFixtures --- src/tests/IntegrationTests/SetupFixture.cs | 4 ++-- src/tests/UnitTests/SetUpFixture.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tests/IntegrationTests/SetupFixture.cs b/src/tests/IntegrationTests/SetupFixture.cs index 10ab573b3..d418fecfc 100644 --- a/src/tests/IntegrationTests/SetupFixture.cs +++ b/src/tests/IntegrationTests/SetupFixture.cs @@ -13,8 +13,8 @@ public void Setup() Logging.TracingEnabled = true; Logging.LogAdapter = new MultipleLogAdapter( - new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-integration-tests.log"), - new ConsoleLogAdapter() + new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-integration-tests.log") + //,new ConsoleLogAdapter() ); } } diff --git a/src/tests/UnitTests/SetUpFixture.cs b/src/tests/UnitTests/SetUpFixture.cs index 879a2a475..1185e8146 100644 --- a/src/tests/UnitTests/SetUpFixture.cs +++ b/src/tests/UnitTests/SetUpFixture.cs @@ -13,8 +13,8 @@ public void SetUp() Logging.TracingEnabled = true; Logging.LogAdapter = new MultipleLogAdapter( - new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-unit-tests.log"), - new ConsoleLogAdapter() + new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-unit-tests.log") + //,new ConsoleLogAdapter() ); } } From cb17d016b4ca90e0a4afc1b8a826a9738fc4b059 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 16:07:40 -0400 Subject: [PATCH 20/57] Firing RepositoryWatcher events as soon as possible --- src/GitHub.Api/Events/RepositoryWatcher.cs | 55 +++++++--------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/src/GitHub.Api/Events/RepositoryWatcher.cs b/src/GitHub.Api/Events/RepositoryWatcher.cs index 066788dbc..788fdff93 100644 --- a/src/GitHub.Api/Events/RepositoryWatcher.cs +++ b/src/GitHub.Api/Events/RepositoryWatcher.cs @@ -11,7 +11,7 @@ interface IRepositoryWatcher : IDisposable { void Start(); void Stop(); - event Action HeadChanged; + event Action HeadChanged; event Action IndexChanged; event Action ConfigChanged; event Action LocalBranchChanged; @@ -38,7 +38,7 @@ class RepositoryWatcher : IRepositoryWatcher private bool processingEvents; private readonly ManualResetEventSlim signalProcessingEventsDone = new ManualResetEventSlim(false); - public event Action HeadChanged; + public event Action HeadChanged; public event Action IndexChanged; public event Action ConfigChanged; public event Action LocalBranchChanged; @@ -168,8 +168,6 @@ private int ProcessEvents(Event[] fileEvents) var repositoryChanged = false; var indexChanged = false; - string headContent = null; - foreach (var fileEvent in fileEvents) { if (!running) @@ -200,19 +198,26 @@ private int ProcessEvents(Event[] fileEvents) if (!configChanged && fileA.Equals(paths.DotGitConfig)) { configChanged = true; + + Logger.Trace("ConfigChanged"); + ConfigChanged?.Invoke(); + eventsProcessed++; } else if (!headChanged && fileA.Equals(paths.DotGitHead)) { - if (fileEvent.Type != EventType.DELETED) - { - headContent = paths.DotGitHead.ReadAllLines().FirstOrDefault(); - } - headChanged = true; + + Logger.Trace("HeadChanged"); + HeadChanged?.Invoke(); + eventsProcessed++; } else if (!indexChanged && fileA.Equals(paths.DotGitIndex)) { indexChanged = true; + + Logger.Trace("IndexChanged"); + IndexChanged?.Invoke(); + eventsProcessed++; } else if (fileA.IsChildOf(paths.RemotesPath)) { @@ -349,35 +354,11 @@ private int ProcessEvents(Event[] fileEvents) } repositoryChanged = true; - } - } - - if (configChanged) - { - Logger.Trace("ConfigChanged"); - ConfigChanged?.Invoke(); - eventsProcessed++; - } - - if (headChanged) - { - Logger.Trace("HeadChanged: {0}", headContent ?? "[null]"); - HeadChanged?.Invoke(headContent); - eventsProcessed++; - } - if (indexChanged) - { - Logger.Trace("IndexChanged"); - IndexChanged?.Invoke(); - eventsProcessed++; - } - - if (repositoryChanged) - { - Logger.Trace("RepositoryChanged"); - RepositoryChanged?.Invoke(); - eventsProcessed++; + Logger.Trace("RepositoryChanged"); + RepositoryChanged?.Invoke(); + eventsProcessed++; + } } return eventsProcessed; From 2a064279be875db1f3d8551c082b59f4fd829888 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 16:12:22 -0400 Subject: [PATCH 21/57] Changing the OnHeadUpdated handler --- src/GitHub.Api/Git/RepositoryManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index c8dc66aba..238a2dc09 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -416,10 +416,10 @@ private void Watcher_OnConfigChanged() RefreshConfigData(true); } - private void Watcher_OnHeadChanged(string contents) + private void Watcher_OnHeadChanged() { Logger.Trace("Watcher_OnHeadChanged"); - head = contents; + ReadHead(); OnActiveBranchChanged?.Invoke(GetActiveBranch()); OnActiveRemoteChanged?.Invoke(GetActiveRemote()); UpdateGitStatus(); From bf4a04d505c1a7221d0d046a350833dae34806c7 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 16:20:29 -0400 Subject: [PATCH 22/57] Updating with OnHeadUpdated signature --- .../Events/RepositoryWatcherTests.cs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs b/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs index f2e1e5447..e4ee53c15 100644 --- a/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs @@ -44,7 +44,7 @@ public async Task ShouldDetectFileChanges() Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.Received().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -90,7 +90,7 @@ public async Task ShouldDetectBranchChange() Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().ConfigChanged(); - repositoryWatcherListener.Received(1).HeadChanged("ref: refs/heads/feature/document"); + repositoryWatcherListener.Received().HeadChanged(); repositoryWatcherListener.Received().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -135,7 +135,7 @@ public async Task ShouldDetectBranchDelete() Logger.Trace("Continue test"); repositoryWatcherListener.Received(1).ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.Received(1).LocalBranchDeleted("feature/document"); @@ -179,7 +179,7 @@ public async Task ShouldDetectBranchCreate() Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.Received(1).LocalBranchCreated("feature/document2"); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -201,7 +201,7 @@ public async Task ShouldDetectBranchCreate() Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.Received(1).LocalBranchCreated("feature2/document2"); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -250,7 +250,7 @@ public async Task ShouldDetectChangesToRemotes() Logger.Trace("Continue test"); repositoryWatcherListener.Received().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -275,7 +275,7 @@ public async Task ShouldDetectChangesToRemotes() Logger.Trace("Continue 2nd test"); repositoryWatcherListener.Received().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -321,7 +321,7 @@ public async Task ShouldDetectGitPull() Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.Received().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -366,7 +366,7 @@ public async Task ShouldDetectGitFetch() Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -394,7 +394,7 @@ private RepositoryWatcher CreateRepositoryWatcher(NPath path) public interface IRepositoryWatcherListener { void ConfigChanged(); - void HeadChanged(string obj); + void HeadChanged(); void IndexChanged(); void LocalBranchCreated(string branch); void LocalBranchDeleted(string branch); @@ -411,10 +411,10 @@ public static void AttachListener(this IRepositoryWatcherListener listener, IRep { var logger = trace ? Logging.GetLogger() : null; - repositoryWatcher.HeadChanged += s => + repositoryWatcher.HeadChanged += () => { - logger?.Trace("HeadChanged: {0}", s); - listener.HeadChanged(s); + logger?.Trace("HeadChanged"); + listener.HeadChanged(); autoResetEvent?.HeadChanged.Set(); }; @@ -485,7 +485,7 @@ public static void AttachListener(this IRepositoryWatcherListener listener, IRep public static void AssertDidNotReceiveAnyCalls(this IRepositoryWatcherListener repositoryWatcherListener) { repositoryWatcherListener.DidNotReceive().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); From 3439858e4315e71581294b1dd1655a8c498fd8ec Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 16:24:08 -0400 Subject: [PATCH 23/57] Updating test --- .../IntegrationTests/Events/RepositoryWatcherTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs b/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs index f2e1e5447..8a39be747 100644 --- a/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs @@ -394,7 +394,7 @@ private RepositoryWatcher CreateRepositoryWatcher(NPath path) public interface IRepositoryWatcherListener { void ConfigChanged(); - void HeadChanged(string obj); + void HeadChanged(); void IndexChanged(); void LocalBranchCreated(string branch); void LocalBranchDeleted(string branch); @@ -411,10 +411,10 @@ public static void AttachListener(this IRepositoryWatcherListener listener, IRep { var logger = trace ? Logging.GetLogger() : null; - repositoryWatcher.HeadChanged += s => + repositoryWatcher.HeadChanged += () => { - logger?.Trace("HeadChanged: {0}", s); - listener.HeadChanged(s); + logger?.Trace("HeadChanged"); + listener.HeadChanged(); autoResetEvent?.HeadChanged.Set(); }; From 8abdd38062a108d1d8497b01527ac9c09dd93cdb Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 16:36:32 -0400 Subject: [PATCH 24/57] Populating list of remotes --- src/GitHub.Api/Git/Repository.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 4efe39c25..fb369eb9d 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -224,9 +224,11 @@ private void UpdateCurrentBranchAndRemote() private void RepositoryManager_OnRemoteBranchListUpdated(Dictionary> branches) { - Logger.Trace("RemoveBranchListUpdated"); + Logger.Trace("RemoteBranchListUpdated"); remoteBranches = branches; + remotes = branches.ToDictionary(pair => pair.Key, pair => pair.Value.Values.First().Remote.Value); + OnRemoteBranchListChanged?.Invoke(); } From fac41598d3aa9863c657e287a70f542d78a0e9e4 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 16:54:21 -0400 Subject: [PATCH 25/57] Fixing tests --- .../Events/RepositoryWatcherTests.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs b/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs index 8a39be747..9b250f318 100644 --- a/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs @@ -90,7 +90,7 @@ public async Task ShouldDetectBranchChange() Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().ConfigChanged(); - repositoryWatcherListener.Received(1).HeadChanged("ref: refs/heads/feature/document"); + repositoryWatcherListener.Received().HeadChanged(); repositoryWatcherListener.Received().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -135,7 +135,7 @@ public async Task ShouldDetectBranchDelete() Logger.Trace("Continue test"); repositoryWatcherListener.Received(1).ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.Received(1).LocalBranchDeleted("feature/document"); @@ -179,7 +179,7 @@ public async Task ShouldDetectBranchCreate() Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.Received(1).LocalBranchCreated("feature/document2"); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -201,7 +201,7 @@ public async Task ShouldDetectBranchCreate() Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.Received(1).LocalBranchCreated("feature2/document2"); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -250,7 +250,7 @@ public async Task ShouldDetectChangesToRemotes() Logger.Trace("Continue test"); repositoryWatcherListener.Received().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -275,7 +275,7 @@ public async Task ShouldDetectChangesToRemotes() Logger.Trace("Continue 2nd test"); repositoryWatcherListener.Received().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -321,7 +321,7 @@ public async Task ShouldDetectGitPull() Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.Received().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -366,7 +366,7 @@ public async Task ShouldDetectGitFetch() Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); @@ -485,7 +485,7 @@ public static void AttachListener(this IRepositoryWatcherListener listener, IRep public static void AssertDidNotReceiveAnyCalls(this IRepositoryWatcherListener repositoryWatcherListener) { repositoryWatcherListener.DidNotReceive().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); From 7ac8b0485c962421eb5fda7799bf79116c4cb1b3 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 17:07:00 -0400 Subject: [PATCH 26/57] Removing some commented out test code --- .../IntegrationTests/Events/RepositoryWatcherTests.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs b/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs index 9b250f318..00a7f4a2d 100644 --- a/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs @@ -453,13 +453,6 @@ public static void AttachListener(this IRepositoryWatcherListener listener, IRep autoResetEvent?.LocalBranchDeleted.Set(); }; - //repositoryWatcher.RemoteBranchChanged += (s, s1) => - //{ - // logger?.Trace("RemoteBranchChanged: {0} {1}", s, s1); - // listener.RemoteBranchChanged(s, s1); - // autoResetEvent?.RemoteBranchChanged.Set(); - //}; - repositoryWatcher.RemoteBranchCreated += (s, s1) => { logger?.Trace("RemoteBranchCreated: {0} {1}", s, s1); From 0773af03aec63ecdc344b5255e846adc7a691958 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 17:41:12 -0400 Subject: [PATCH 27/57] Removing unused test --- .../Events/RepositoryManagerTests.cs | 45 ------------------- 1 file changed, 45 deletions(-) diff --git a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs index 8be8fa3ff..5fe73322b 100644 --- a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs @@ -452,51 +452,6 @@ await RepositoryManager.SwitchBranch("branch2") repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); } - [Test] - public async Task ShouldUpdateCloneUrlIfRemoteIsDeleted() - { - await Initialize(TestRepoMasterCleanSynchronized); - - var repositoryManagerListener = Substitute.For(); - repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); - - await RepositoryManager.RemoteRemove("origin").StartAsAsync(); - await TaskManager.Wait(); - RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); - - repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); - repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); - repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); - repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); - repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); - repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); - repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); - repositoryManagerListener.Received().OnRemoteBranchRemoved(Args.String, Args.String); - - repositoryManagerListener.ClearReceivedCalls(); - repositoryManagerEvents.Reset(); - - await RepositoryManager.RemoteAdd("origin", "https://github.com/EvilShana/IOTestsRepo.git").StartAsAsync(); - await TaskManager.Wait(); - RepositoryManager.WaitForEvents(); - - repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); - repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); - repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); - repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); - repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); - repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); - repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); - } - [Test] public async Task ShouldDetectGitPull() { From 6dcc6c76d1a215ee95efa5de9ec7c837ffba6b57 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 17:42:19 -0400 Subject: [PATCH 28/57] Preventing exception for remotes without branches --- src/GitHub.Api/Git/Repository.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index fb369eb9d..3b1ae5423 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -227,7 +227,9 @@ private void RepositoryManager_OnRemoteBranchListUpdated(Dictionary pair.Key, pair => pair.Value.Values.First().Remote.Value); + remotes = branches + .Where(pair => pair.Value.Any()) + .ToDictionary(pair => pair.Key, pair => pair.Value.First().Value.Remote.Value); OnRemoteBranchListChanged?.Invoke(); } From 7d4bd5492259de050d2461ce95554fcd98dcd669 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 17:42:48 -0400 Subject: [PATCH 29/57] Adding more detail to tests --- src/tests/IntegrationTests/Events/RepositoryManagerTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs index 5fe73322b..38b5ccf09 100644 --- a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs @@ -365,6 +365,8 @@ public async Task ShouldDetectChangesToRemotes() await TaskManager.Wait(); RepositoryManager.WaitForEvents(); WaitForNotBusy(repositoryManagerEvents); + repositoryManagerEvents.OnRemoteBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); + repositoryManagerEvents.OnLocalBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); @@ -385,6 +387,8 @@ public async Task ShouldDetectChangesToRemotes() await TaskManager.Wait(); RepositoryManager.WaitForEvents(); WaitForNotBusy(repositoryManagerEvents); + repositoryManagerEvents.OnRemoteBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); + repositoryManagerEvents.OnLocalBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); From 3b4d77e70400250728e7bc0e04c7faf26165eee8 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 18 Sep 2017 17:45:03 -0400 Subject: [PATCH 30/57] Missing fix --- src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs b/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs index 00a7f4a2d..6427fac6c 100644 --- a/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryWatcherTests.cs @@ -44,7 +44,7 @@ public async Task ShouldDetectFileChanges() Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().ConfigChanged(); - repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); + repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.Received().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); From 553c13bca287a6e522c1c2b8ae2c8a9721f3341f Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 19 Sep 2017 08:25:52 -0400 Subject: [PATCH 31/57] Fixing tests --- src/GitHub.Api/Git/RepositoryManager.cs | 3 +++ .../Events/RepositoryManagerTests.cs | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index 238a2dc09..14cfac99d 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -460,6 +460,9 @@ private void RefreshConfigData(bool resetConfig = false) LoadBranchesFromConfig(); LoadRemotesFromConfig(); + OnLocalBranchListChanged?.Invoke(); + OnRemoteBranchListChanged?.Invoke(); + OnActiveBranchChanged?.Invoke(GetActiveBranch()); OnActiveRemoteChanged?.Invoke(GetActiveRemote()); } diff --git a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs index c8d84ebd2..58513519a 100644 --- a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs @@ -301,6 +301,8 @@ public async Task ShouldDetectChangesToRemotes() await RepositoryManager.RemoteRemove("origin").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); + WaitForNotBusy(repositoryManagerEvents); + repositoryManagerEvents.OnRemoteBranchListChanged.WaitOne(TimeSpan.FromSeconds(1)); Environment.Repository.CurrentRemote.HasValue.Should().BeFalse(); @@ -310,7 +312,7 @@ public async Task ShouldDetectChangesToRemotes() repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); repositoryManagerListener.Received().OnActiveBranchChanged(Arg.Any()); repositoryManagerListener.Received().OnActiveRemoteChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); + repositoryManagerListener.Received().OnLocalBranchListChanged(); repositoryManagerListener.Received().OnRemoteBranchListChanged(); repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); @@ -321,6 +323,8 @@ public async Task ShouldDetectChangesToRemotes() await RepositoryManager.RemoteAdd("origin", "https://github.com/EvilShana/IOTestsRepo.git").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); + WaitForNotBusy(repositoryManagerEvents); + repositoryManagerEvents.OnRemoteBranchListChanged.WaitOne(TimeSpan.FromSeconds(1)); Environment.Repository.CurrentRemote.HasValue.Should().BeTrue(); Environment.Repository.CurrentRemote.Value.Name.Should().Be("origin"); @@ -332,8 +336,8 @@ public async Task ShouldDetectChangesToRemotes() repositoryManagerListener.DidNotReceive().OnStatusUpdate(Args.GitStatus); repositoryManagerListener.Received().OnActiveBranchChanged(Arg.Any()); repositoryManagerListener.Received().OnActiveRemoteChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); + repositoryManagerListener.Received().OnLocalBranchListChanged(); + repositoryManagerListener.Received().OnRemoteBranchListChanged(); repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); } @@ -422,7 +426,7 @@ public async Task ShouldUpdateCloneUrlIfRemoteIsDeleted() repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnActiveBranchChanged(Arg.Any()); repositoryManagerListener.Received().OnActiveRemoteChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); + repositoryManagerListener.Received().OnLocalBranchListChanged(); repositoryManagerListener.Received().OnRemoteBranchListChanged(); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); @@ -443,8 +447,8 @@ public async Task ShouldUpdateCloneUrlIfRemoteIsDeleted() repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnActiveBranchChanged(Arg.Any()); repositoryManagerListener.Received().OnActiveRemoteChanged(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged(); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged(); + repositoryManagerListener.Received().OnLocalBranchListChanged(); + repositoryManagerListener.Received().OnRemoteBranchListChanged(); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); } From 9218b2cb4bff4ab39b72cd1e22c68faf3bbb8ab6 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 19 Sep 2017 09:45:53 -0400 Subject: [PATCH 32/57] Fixing the name casing of this file --- src/tests/IntegrationTests/IntegrationTests.csproj | 2 +- src/tests/IntegrationTests/{SetupFixture.cs => SetUpFixture.cs} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/tests/IntegrationTests/{SetupFixture.cs => SetUpFixture.cs} (93%) diff --git a/src/tests/IntegrationTests/IntegrationTests.csproj b/src/tests/IntegrationTests/IntegrationTests.csproj index 6d5c2fbdf..36f83c206 100644 --- a/src/tests/IntegrationTests/IntegrationTests.csproj +++ b/src/tests/IntegrationTests/IntegrationTests.csproj @@ -83,8 +83,8 @@ - + diff --git a/src/tests/IntegrationTests/SetupFixture.cs b/src/tests/IntegrationTests/SetUpFixture.cs similarity index 93% rename from src/tests/IntegrationTests/SetupFixture.cs rename to src/tests/IntegrationTests/SetUpFixture.cs index d418fecfc..f77cdec8d 100644 --- a/src/tests/IntegrationTests/SetupFixture.cs +++ b/src/tests/IntegrationTests/SetUpFixture.cs @@ -5,7 +5,7 @@ namespace IntegrationTests { [SetUpFixture] - public class SetupFixture + public class SetUpFixture { [SetUp] public void Setup() From 73c873ebb3b05640d4e3e9c84232eda8f19b2d71 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 19 Sep 2017 16:07:40 -0400 Subject: [PATCH 33/57] Adding warning messages in the event that branch operations cannot be completed --- GitHub.Unity.sln.DotSettings | 1 + src/GitHub.Api/Git/Repository.cs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/GitHub.Unity.sln.DotSettings b/GitHub.Unity.sln.DotSettings index ded507d07..d4374a413 100644 --- a/GitHub.Unity.sln.DotSettings +++ b/GitHub.Unity.sln.DotSettings @@ -342,6 +342,7 @@ True True True + True False x64 \ No newline at end of file diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 3b1ae5423..5f3b228eb 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -249,6 +249,10 @@ private void RepositoryManager_OnLocalBranchRemoved(string name) localBranches.Remove(name); OnLocalBranchListChanged?.Invoke(); } + else + { + Logger.Warning("Branch {0} is not found", name); + } } private void RepositoryManager_OnLocalBranchAdded(string name) @@ -263,6 +267,10 @@ private void RepositoryManager_OnLocalBranchAdded(string name) localBranches.Add(name, branch.Value); OnLocalBranchListChanged?.Invoke(); } + else + { + Logger.Warning("Branch {0} is already present", name); + } } private void RepositoryManager_OnLocalBranchUpdated(string name) @@ -285,6 +293,14 @@ private void RepositoryManager_OnRemoteBranchAdded(string remote, string name) branchList.Add(name, new ConfigBranch { Name = name, Remote = remotes[remote] }); OnRemoteBranchListChanged?.Invoke(); } + else + { + Logger.Warning("Branch {0} is already present in Remote {1}", name, remote); + } + } + else + { + Logger.Warning("Remote {0} is not found", remote); } } @@ -298,6 +314,14 @@ private void RepositoryManager_OnRemoteBranchRemoved(string remote, string name) localBranches.Remove(name); OnRemoteBranchListChanged?.Invoke(); } + else + { + Logger.Warning("Branch {0} is not found in Remote {1}", name, remote); + } + } + else + { + Logger.Warning("Remote {0} is not found", remote); } } From 8602fba0ba1edfab6bc0cff1948f7b09832e2e21 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 19 Sep 2017 17:09:19 -0400 Subject: [PATCH 34/57] Updating tests with value checks --- .../Events/RepositoryManagerTests.cs | 326 ++++++++++++++++++ 1 file changed, 326 insertions(+) diff --git a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs index 38b5ccf09..636353799 100644 --- a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using FluentAssertions; using GitHub.Unity; using NSubstitute; @@ -33,6 +34,31 @@ public async Task ShouldDoNothingOnInitialize() WaitForNotBusy(repositoryManagerEvents, 2); repositoryManagerListener.AssertDidNotReceiveAnyCalls(); + + Repository.Name.Should().Be("IOTestsRepo"); + Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.Owner.Should().Be("EvilStanleyGoldman"); + Repository.LocalPath.Should().Be(TestRepoMasterCleanSynchronized); + Repository.IsGitHub.Should().BeTrue(); + Repository.CurrentBranchName.Should().Be("master"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("master"); + Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); + Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.CurrentRemote.HasValue.Should().BeTrue(); + Repository.CurrentRemote.Value.Name.Should().Be("origin"); + Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.LocalBranches.Should().BeEquivalentTo(new[] { + new GitBranch("master", "origin/master", true), + new GitBranch("feature/document", "origin/feature/document", false), + new GitBranch("feature/other-feature", "origin/feature/other-feature", false), + }); + Repository.RemoteBranches.Should().BeEquivalentTo(new[] { + new GitBranch("origin/master", "[None]", false), + new GitBranch("origin/feature/document-2", "[None]", false), + new GitBranch("origin/feature/other-feature", "[None]", false), + }); } [Test] @@ -276,6 +302,31 @@ public async Task ShouldDetectBranchChange() repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); result.AssertEqual(expected); + + Repository.Name.Should().Be("IOTestsRepo"); + Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.Owner.Should().Be("EvilStanleyGoldman"); + Repository.LocalPath.Should().Be(TestRepoMasterCleanSynchronized); + Repository.IsGitHub.Should().BeTrue(); + Repository.CurrentBranchName.Should().Be("feature/document"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("feature/document"); + Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); + Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.CurrentRemote.HasValue.Should().BeTrue(); + Repository.CurrentRemote.Value.Name.Should().Be("origin"); + Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.LocalBranches.Should().BeEquivalentTo(new[] { + new GitBranch("master", "origin/master", false), + new GitBranch("feature/document", "origin/feature/document", true), + new GitBranch("feature/other-feature", "origin/feature/other-feature", false), + }); + Repository.RemoteBranches.Should().BeEquivalentTo(new[] { + new GitBranch("origin/master", "[None]", false), + new GitBranch("origin/feature/document-2", "[None]", false), + new GitBranch("origin/feature/other-feature", "[None]", false), + }); } [Test] @@ -303,6 +354,30 @@ public async Task ShouldDetectBranchDelete() repositoryManagerListener.Received().OnLocalBranchRemoved(deletedBranch); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + + Repository.Name.Should().Be("IOTestsRepo"); + Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.Owner.Should().Be("EvilStanleyGoldman"); + Repository.LocalPath.Should().Be(TestRepoMasterCleanSynchronized); + Repository.IsGitHub.Should().BeTrue(); + Repository.CurrentBranchName.Should().Be("master"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("master"); + Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); + Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.CurrentRemote.HasValue.Should().BeTrue(); + Repository.CurrentRemote.Value.Name.Should().Be("origin"); + Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.LocalBranches.Should().BeEquivalentTo(new[] { + new GitBranch("master", "origin/master", true), + new GitBranch("feature/other-feature", "origin/feature/other-feature", false), + }); + Repository.RemoteBranches.Should().BeEquivalentTo(new[] { + new GitBranch("origin/master", "[None]", false), + new GitBranch("origin/feature/document-2", "[None]", false), + new GitBranch("origin/feature/other-feature", "[None]", false), + }); } [Test] @@ -331,6 +406,32 @@ public async Task ShouldDetectBranchCreate() repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + Repository.Name.Should().Be("IOTestsRepo"); + Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.Owner.Should().Be("EvilStanleyGoldman"); + Repository.LocalPath.Should().Be(TestRepoMasterCleanSynchronized); + Repository.IsGitHub.Should().BeTrue(); + Repository.CurrentBranchName.Should().Be("master"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("master"); + Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); + Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.CurrentRemote.HasValue.Should().BeTrue(); + Repository.CurrentRemote.Value.Name.Should().Be("origin"); + Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.LocalBranches.Should().BeEquivalentTo(new[] { + new GitBranch("master", "origin/master", true), + new GitBranch("feature/document", "origin/feature/document", false), + new GitBranch("feature/document2", "[None]", false), + new GitBranch("feature/other-feature", "origin/feature/other-feature", false), + }); + Repository.RemoteBranches.Should().BeEquivalentTo(new[] { + new GitBranch("origin/master", "[None]", false), + new GitBranch("origin/feature/document-2", "[None]", false), + new GitBranch("origin/feature/other-feature", "[None]", false), + }); + repositoryManagerListener.ClearReceivedCalls(); repositoryManagerEvents.Reset(); @@ -351,6 +452,33 @@ public async Task ShouldDetectBranchCreate() repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + + Repository.Name.Should().Be("IOTestsRepo"); + Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.Owner.Should().Be("EvilStanleyGoldman"); + Repository.LocalPath.Should().Be(TestRepoMasterCleanSynchronized); + Repository.IsGitHub.Should().BeTrue(); + Repository.CurrentBranchName.Should().Be("master"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("master"); + Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); + Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.CurrentRemote.HasValue.Should().BeTrue(); + Repository.CurrentRemote.Value.Name.Should().Be("origin"); + Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.LocalBranches.Should().BeEquivalentTo(new[] { + new GitBranch("master", "origin/master", true), + new GitBranch("feature/document", "origin/feature/document", false), + new GitBranch("feature/document2", "[None]", false), + new GitBranch("feature2/document2", "[None]", false), + new GitBranch("feature/other-feature", "origin/feature/other-feature", false), + }); + Repository.RemoteBranches.Should().BeEquivalentTo(new[] { + new GitBranch("origin/master", "[None]", false), + new GitBranch("origin/feature/document-2", "[None]", false), + new GitBranch("origin/feature/other-feature", "[None]", false), + }); } [Test] @@ -380,6 +508,27 @@ public async Task ShouldDetectChangesToRemotes() repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.Received().OnRemoteBranchRemoved(Args.String, Args.String); + Repository.Name.Should().Be("IOTestsRepo"); + Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.Owner.Should().Be("EvilStanleyGoldman"); + Repository.LocalPath.Should().Be(TestRepoMasterCleanSynchronized); + Repository.IsGitHub.Should().BeTrue(); + Repository.CurrentBranchName.Should().Be("master"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("master"); + Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); + Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.CurrentRemote.HasValue.Should().BeTrue(); + Repository.CurrentRemote.Value.Name.Should().Be("origin"); + Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.LocalBranches.Should().BeEquivalentTo(new[] { + new GitBranch("master", "[None]", true), + new GitBranch("feature/document", "[None]", false), + new GitBranch("feature/other-feature", "[None]", false), + }); + Repository.RemoteBranches.Should().BeEmpty(); + repositoryManagerListener.ClearReceivedCalls(); repositoryManagerEvents.Reset(); @@ -401,6 +550,27 @@ public async Task ShouldDetectChangesToRemotes() repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + + Repository.Name.Should().Be("IOTestsRepo"); + Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.Owner.Should().Be("EvilStanleyGoldman"); + Repository.LocalPath.Should().Be(TestRepoMasterCleanSynchronized); + Repository.IsGitHub.Should().BeTrue(); + Repository.CurrentBranchName.Should().Be("master"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("master"); + Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); + Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.CurrentRemote.HasValue.Should().BeTrue(); + Repository.CurrentRemote.Value.Name.Should().Be("origin"); + Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.LocalBranches.Should().BeEquivalentTo(new[] { + new GitBranch("master", "[None]", true), + new GitBranch("feature/document", "[None]", false), + new GitBranch("feature/other-feature", "[None]", false), + }); + Repository.RemoteBranches.Should().BeEmpty(); } [Test] @@ -413,6 +583,34 @@ public async Task ShouldDetectChangesToRemotesWhenSwitchingBranches() var repositoryManagerListener = Substitute.For(); repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); + Repository.Name.Should().Be("IOTestsRepo"); + Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.Owner.Should().Be("EvilStanleyGoldman"); + Repository.LocalPath.Should().Be(TestRepoMasterTwoRemotes); + Repository.IsGitHub.Should().BeTrue(); + Repository.CurrentBranchName.Should().Be("master"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("master"); + Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); + Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.CurrentRemote.HasValue.Should().BeTrue(); + Repository.CurrentRemote.Value.Name.Should().Be("origin"); + Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.LocalBranches.Should().BeEquivalentTo(new[] { + new GitBranch("master", "origin/master", true), + new GitBranch("feature/document", "origin/feature/document", false), + new GitBranch("feature/other-feature", "origin/feature/other-feature", false), + }); + Repository.RemoteBranches.Should().BeEquivalentTo(new[] { + new GitBranch("origin/master", "[None]", false), + new GitBranch("origin/feature/document-2", "[None]", false), + new GitBranch("origin/feature/other-feature", "[None]", false), + new GitBranch("another/master", "[None]", false), + new GitBranch("another/feature/document-2", "[None]", false), + new GitBranch("another/feature/other-feature", "[None]", false), + }); + await RepositoryManager.CreateBranch("branch2", "another/master") .StartAsAsync(); @@ -432,6 +630,35 @@ await RepositoryManager.CreateBranch("branch2", "another/master") repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + Repository.Name.Should().Be("IOTestsRepo"); + Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.Owner.Should().Be("EvilStanleyGoldman"); + Repository.LocalPath.Should().Be(TestRepoMasterTwoRemotes); + Repository.IsGitHub.Should().BeTrue(); + Repository.CurrentBranchName.Should().Be("master"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("master"); + Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); + Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.CurrentRemote.HasValue.Should().BeTrue(); + Repository.CurrentRemote.Value.Name.Should().Be("origin"); + Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.LocalBranches.Should().BeEquivalentTo(new[] { + new GitBranch("master", "origin/master", true), + new GitBranch("branch2", "another/branch2", false), + new GitBranch("feature/document", "origin/feature/document", false), + new GitBranch("feature/other-feature", "origin/feature/other-feature", false), + }); + Repository.RemoteBranches.Should().BeEquivalentTo(new[] { + new GitBranch("origin/master", "[None]", false), + new GitBranch("origin/feature/document-2", "[None]", false), + new GitBranch("origin/feature/other-feature", "[None]", false), + new GitBranch("another/master", "[None]", false), + new GitBranch("another/feature/document-2", "[None]", false), + new GitBranch("another/feature/other-feature", "[None]", false), + }); + repositoryManagerListener.ClearReceivedCalls(); repositoryManagerEvents.Reset(); @@ -454,6 +681,35 @@ await RepositoryManager.SwitchBranch("branch2") repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + + Repository.Name.Should().Be("Url"); + Repository.CloneUrl.ToString().Should().Be("https://another.remote/Owner/Url.git"); + Repository.Owner.Should().Be("Owner"); + Repository.LocalPath.Should().Be(TestRepoMasterTwoRemotes); + Repository.IsGitHub.Should().BeFalse(); + Repository.CurrentBranchName.Should().Be("branch2"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("branch2"); + Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("another"); + Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://another.remote/Owner/Url.git"); + Repository.CurrentRemote.HasValue.Should().BeTrue(); + Repository.CurrentRemote.Value.Name.Should().Be("another"); + Repository.CurrentRemote.Value.Url.Should().Be("https://another.remote/Owner/Url.git"); + Repository.LocalBranches.Should().BeEquivalentTo(new[] { + new GitBranch("master", "origin/master", false), + new GitBranch("branch2", "another/branch2", true), + new GitBranch("feature/document", "origin/feature/document", false), + new GitBranch("feature/other-feature", "origin/feature/other-feature", false), + }); + Repository.RemoteBranches.Should().BeEquivalentTo(new[] { + new GitBranch("origin/master", "[None]", false), + new GitBranch("origin/feature/document-2", "[None]", false), + new GitBranch("origin/feature/other-feature", "[None]", false), + new GitBranch("another/master", "[None]", false), + new GitBranch("another/feature/document-2", "[None]", false), + new GitBranch("another/feature/other-feature", "[None]", false), + }); } [Test] @@ -493,6 +749,31 @@ public async Task ShouldDetectGitPull() result.AssertEqual(expected); + Repository.Name.Should().Be("IOTestsRepo"); + Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.Owner.Should().Be("EvilStanleyGoldman"); + Repository.LocalPath.Should().Be(TestRepoMasterCleanSynchronized); + Repository.IsGitHub.Should().BeTrue(); + Repository.CurrentBranchName.Should().Be("master"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("master"); + Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); + Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.CurrentRemote.HasValue.Should().BeTrue(); + Repository.CurrentRemote.Value.Name.Should().Be("origin"); + Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.LocalBranches.Should().BeEquivalentTo(new[] { + new GitBranch("master", "origin/master", true), + new GitBranch("feature/document", "origin/feature/document", false), + new GitBranch("feature/other-feature", "origin/feature/other-feature", false), + }); + Repository.RemoteBranches.Should().BeEquivalentTo(new[] { + new GitBranch("origin/master", "[None]", false), + new GitBranch("origin/feature/document-2", "[None]", false), + new GitBranch("origin/feature/other-feature", "[None]", false), + }); + repositoryManagerEvents.Reset(); WaitForNotBusy(repositoryManagerEvents); } @@ -505,6 +786,30 @@ public async Task ShouldDetectGitFetch() var repositoryManagerListener = Substitute.For(); repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); + RepositoryManager.WaitForEvents(); + WaitForNotBusy(repositoryManagerEvents, 2); + + repositoryManagerListener.AssertDidNotReceiveAnyCalls(); + + Repository.Name.Should().Be("IOTestsRepo"); + Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.Owner.Should().Be("EvilStanleyGoldman"); + Repository.LocalPath.Should().Be(TestRepoMasterCleanUnsynchronized); + Repository.IsGitHub.Should().BeTrue(); + Repository.CurrentBranchName.Should().Be(null); + Repository.CurrentBranch.HasValue.Should().BeFalse(); + Repository.CurrentRemote.HasValue.Should().BeTrue(); + Repository.CurrentRemote.Value.Name.Should().Be("origin"); + Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.LocalBranches.Should().BeEquivalentTo(new[] { + new GitBranch("feature/document", "origin/feature/document", false), + }); + Repository.RemoteBranches.Should().BeEquivalentTo(new[] { + new GitBranch("origin/master", "[None]", false), + new GitBranch("origin/feature/document", "[None]", false), + new GitBranch("origin/feature/document-2", "[None]", false), + }); + await RepositoryManager.Fetch("origin").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); @@ -521,6 +826,27 @@ public async Task ShouldDetectGitFetch() repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); repositoryManagerListener.Received().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + + Repository.Name.Should().Be("IOTestsRepo"); + Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.Owner.Should().Be("EvilStanleyGoldman"); + Repository.LocalPath.Should().Be(TestRepoMasterCleanUnsynchronized); + Repository.IsGitHub.Should().BeTrue(); + Repository.CurrentBranchName.Should().Be(null); + Repository.CurrentBranch.HasValue.Should().BeFalse(); + Repository.CurrentRemote.HasValue.Should().BeTrue(); + Repository.CurrentRemote.Value.Name.Should().Be("origin"); + Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.LocalBranches.Should().BeEquivalentTo(new[] { + new GitBranch("feature/document", "origin/feature/document", false), + }); + Repository.RemoteBranches.Should().BeEquivalentTo(new[] { + new GitBranch("origin/master", "[None]", false), + new GitBranch("origin/feature/document", "[None]", false), + new GitBranch("origin/feature/document-2", "[None]", false), + new GitBranch("origin/feature/new-feature", "[None]", false), + new GitBranch("origin/feature/other-feature", "[None]", false), + }); } private void WaitForNotBusy(RepositoryManagerEvents managerEvents, int seconds = 1) From 4efffc921c3cf1d1881f6d906c07272d865ffbe4 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Wed, 20 Sep 2017 12:14:47 -0400 Subject: [PATCH 35/57] Moving head processing back to RepositoryManager --- src/GitHub.Api/Git/Repository.cs | 58 ++----------------- src/GitHub.Api/Git/RepositoryManager.cs | 47 +++++++++++++-- .../Events/IRepositoryManagerListener.cs | 25 ++++++-- 3 files changed, 67 insertions(+), 63 deletions(-) diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 5f3b228eb..84568efa2 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -14,7 +14,6 @@ class Repository : IRepository, IEquatable private ConfigBranch? currentBranch; private ConfigRemote? currentRemote; private GitStatus currentStatus; - private string head; private Dictionary localBranches = new Dictionary(); private IEnumerable locks; private Dictionary> remoteBranches = new Dictionary>(); @@ -58,7 +57,8 @@ public void Initialize(IRepositoryManager repositoryManager) this.repositoryManager = repositoryManager; - repositoryManager.OnHeadUpdated += RepositoryManager_OnHeadUpdated; + repositoryManager.OnCurrentBranchUpdated += RepositoryManager_OnCurrentBranchUpdated; + repositoryManager.OnCurrentRemoteUpdated += RepositoryManager_OnCurrentRemoteUpdated; repositoryManager.OnStatusUpdated += RepositoryManager_OnStatusUpdated; repositoryManager.OnLocksUpdated += RepositoryManager_OnLocksUpdated; repositoryManager.OnLocalBranchListUpdated += RepositoryManager_OnLocalBranchListUpdated; @@ -174,51 +174,13 @@ private void RepositoryManager_OnLocksUpdated(IEnumerable locks) OnLocksChanged?.Invoke(CurrentLocks); } - private void RepositoryManager_OnHeadUpdated(string h) + private void RepositoryManager_OnCurrentBranchUpdated(ConfigBranch? branch) { - Logger.Trace("HeadUpdated"); - - if (head != h) - { - head = h; - UpdateCurrentBranchAndRemote(); - } + CurrentBranch = branch; } - private void UpdateCurrentBranchAndRemote() + private void RepositoryManager_OnCurrentRemoteUpdated(ConfigRemote? remote) { - ConfigBranch? branch = null; - - if (head.StartsWith("ref:")) - { - var branchName = head.Substring(head.IndexOf("refs/heads/") + "refs/heads/".Length); - branch = GetBranch(branchName); - } - - CurrentBranch = branch; - - var defaultRemote = "origin"; - ConfigRemote? remote = null; - - if (currentBranch.HasValue && currentBranch.Value.IsTracking) - { - remote = currentBranch.Value.Remote; - } - - if (!remote.HasValue) - { - remote = repositoryManager.Config.GetRemote(defaultRemote); - } - - if (!remote.HasValue) - { - var configRemotes = repositoryManager.Config.GetRemotes().ToArray(); - if (configRemotes.Any()) - { - remote = configRemotes.FirstOrDefault(); - } - } - CurrentRemote = remote; } @@ -324,16 +286,6 @@ private void RepositoryManager_OnRemoteBranchRemoved(string remote, string name) Logger.Warning("Remote {0} is not found", remote); } } - - private ConfigBranch? GetBranch(string name) - { - if (localBranches.ContainsKey(name)) - { - return localBranches[name]; - } - - return null; - } /// /// Note: We don't consider CloneUrl a part of the hash code because it can change during the lifetime diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index 20e99460a..f4405f467 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -9,11 +9,12 @@ namespace GitHub.Unity public interface IRepositoryManager : IDisposable { event Action OnIsBusyChanged; - event Action OnHeadUpdated; event Action OnStatusUpdated; event Action> OnLocksUpdated; event Action> OnLocalBranchListUpdated; event Action>> OnRemoteBranchListUpdated; + event Action OnCurrentBranchUpdated; + event Action OnCurrentRemoteUpdated; event Action OnLocalBranchUpdated; event Action OnLocalBranchAdded; event Action OnLocalBranchRemoved; @@ -111,13 +112,14 @@ class RepositoryManager : IRepositoryManager public event Action>> OnRemoteBranchListUpdated; public event Action> OnLocksUpdated; public event Action OnStatusUpdated; - public event Action OnHeadUpdated; + public event Action OnCurrentBranchUpdated; + public event Action OnCurrentRemoteUpdated; public event Action OnLocalBranchUpdated; public event Action OnLocalBranchAdded; public event Action OnLocalBranchRemoved; - public event Action OnGitUserLoaded; public event Action OnRemoteBranchAdded; public event Action OnRemoteBranchRemoved; + public event Action OnGitUserLoaded; public static RepositoryManager CreateInstance(IPlatform platform, ITaskManager taskManager, IUsageTracker usageTracker, IGitClient gitClient, NPath repositoryRoot) @@ -347,7 +349,7 @@ private void SetupWatcher() private void UpdateHead() { var head = repositoryPaths.DotGitHead.ReadAllLines().FirstOrDefault(); - OnHeadUpdated?.Invoke(head); + UpdateCurrentBranchAndRemote(head); } private ITask HookupHandlers(ITask task, bool disableWatcher = false) @@ -387,6 +389,7 @@ private void Watcher_OnRemoteBranchCreated(string remote, string name) private void Watcher_OnRepositoryChanged() { + Logger.Trace("OnRepositoryChanged"); UpdateGitStatus(); } @@ -420,6 +423,42 @@ private void Watcher_OnHeadChanged() UpdateGitStatus(); } + private void UpdateCurrentBranchAndRemote(string head) + { + ConfigBranch? branch = null; + + if (head.StartsWith("ref:")) + { + var branchName = head.Substring(head.IndexOf("refs/heads/") + "refs/heads/".Length); + branch = config.GetBranch(branchName); + } + + var defaultRemote = "origin"; + ConfigRemote? remote = null; + + if (branch.HasValue && branch.Value.IsTracking) + { + remote = branch.Value.Remote; + } + + if (!remote.HasValue) + { + remote = config.GetRemote(defaultRemote); + } + + if (!remote.HasValue) + { + var configRemotes = config.GetRemotes().ToArray(); + if (configRemotes.Any()) + { + remote = configRemotes.FirstOrDefault(); + } + } + + OnCurrentBranchUpdated?.Invoke(branch); + OnCurrentRemoteUpdated?.Invoke(remote); + } + private void Watcher_OnIndexChanged() {} diff --git a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs index 271a05b90..61ead5be3 100644 --- a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs +++ b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -11,7 +12,6 @@ interface IRepositoryManagerListener void OnIsBusyChanged(bool busy); void OnStatusUpdated(GitStatus status); void OnLocksUpdated(IEnumerable locks); - void OnHeadUpdated(string head); void OnLocalBranchListUpdated(Dictionary branchList); void OnRemoteBranchListUpdated(Dictionary> remoteBranchList); void OnLocalBranchUpdated(string name); @@ -20,6 +20,8 @@ interface IRepositoryManagerListener void OnRemoteBranchAdded(string origin, string name); void OnRemoteBranchRemoved(string origin, string name); void OnGitUserLoaded(IUser user); + void OnCurrentBranchUpdated(ConfigBranch? configBranch); + void OnCurrentRemoteUpdated(ConfigRemote? configRemote); } class RepositoryManagerEvents @@ -28,6 +30,8 @@ class RepositoryManagerEvents public EventWaitHandle OnIsNotBusy { get; } = new AutoResetEvent(false); public EventWaitHandle OnStatusUpdated { get; } = new AutoResetEvent(false); public EventWaitHandle OnLocksUpdated { get; } = new AutoResetEvent(false); + public EventWaitHandle OnCurrentBranchUpdated { get; } = new AutoResetEvent(false); + public EventWaitHandle OnCurrentRemoteUpdated { get; } = new AutoResetEvent(false); public EventWaitHandle OnHeadUpdated { get; } = new AutoResetEvent(false); public EventWaitHandle OnLocalBranchListUpdated { get; } = new AutoResetEvent(false); public EventWaitHandle OnRemoteBranchListUpdated { get; } = new AutoResetEvent(false); @@ -44,6 +48,8 @@ public void Reset() OnIsNotBusy.Reset(); OnStatusUpdated.Reset(); OnLocksUpdated.Reset(); + OnCurrentBranchUpdated.Reset(); + OnCurrentRemoteUpdated.Reset(); OnHeadUpdated.Reset(); OnLocalBranchListUpdated.Reset(); OnRemoteBranchListUpdated.Reset(); @@ -85,10 +91,16 @@ public static void AttachListener(this IRepositoryManagerListener listener, managerEvents?.OnLocksUpdated.Set(); }; - repositoryManager.OnHeadUpdated += head => { - logger?.Trace("OnHeadUpdated"); - listener.OnHeadUpdated(head); - managerEvents?.OnHeadUpdated.Set(); + repositoryManager.OnCurrentBranchUpdated += configBranch => { + logger?.Trace("OnCurrentBranchUpdated"); + listener.OnCurrentBranchUpdated(configBranch); + managerEvents?.OnCurrentBranchUpdated.Set(); + }; + + repositoryManager.OnCurrentRemoteUpdated += configRemote => { + logger?.Trace("OnCurrentRemoteUpdated"); + listener.OnCurrentRemoteUpdated(configRemote); + managerEvents?.OnCurrentRemoteUpdated.Set(); }; repositoryManager.OnLocalBranchListUpdated += branchList => { @@ -145,7 +157,8 @@ public static void AssertDidNotReceiveAnyCalls(this IRepositoryManagerListener r repositoryManagerListener.DidNotReceive().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); From 2dbfba249a826a971fe80131bcaf3e8df0dc1386 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Wed, 20 Sep 2017 12:15:49 -0400 Subject: [PATCH 36/57] Fixing more unit tests --- .../Events/RepositoryManagerTests.cs | 63 +++++++++++++------ src/tests/UnitTests/Git/RepositoryTests.cs | 7 ++- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs index 636353799..8bdda2f71 100644 --- a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs @@ -94,7 +94,8 @@ public async Task ShouldDetectFileChanges() repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); @@ -152,7 +153,8 @@ public async Task ShouldAddAndCommitFiles() repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); @@ -177,7 +179,8 @@ await RepositoryManager repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.Received().OnLocalBranchUpdated(expectedLocalBranch); @@ -227,7 +230,8 @@ public async Task ShouldAddAndCommitAllFiles() repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); @@ -252,7 +256,8 @@ await RepositoryManager repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.Received().OnLocalBranchUpdated(expectedLocalBranch); @@ -292,7 +297,8 @@ public async Task ShouldDetectBranchChange() repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.Received().OnHeadUpdated(Args.String); + repositoryManagerListener.Received().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.Received().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); @@ -346,7 +352,8 @@ public async Task ShouldDetectBranchDelete() repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); @@ -397,7 +404,8 @@ public async Task ShouldDetectBranchCreate() repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); @@ -444,7 +452,8 @@ public async Task ShouldDetectBranchCreate() repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); @@ -499,7 +508,8 @@ public async Task ShouldDetectChangesToRemotes() repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); @@ -542,7 +552,8 @@ public async Task ShouldDetectChangesToRemotes() repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); @@ -621,7 +632,8 @@ await RepositoryManager.CreateBranch("branch2", "another/master") repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); @@ -671,9 +683,10 @@ await RepositoryManager.SwitchBranch("branch2") WaitForHeadUpdated(repositoryManagerEvents); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); - repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); + repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.Received().OnHeadUpdated(Args.String); + repositoryManagerListener.Received().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.Received().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); @@ -738,7 +751,8 @@ public async Task ShouldDetectGitPull() repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.Received().OnLocalBranchUpdated(Args.String); @@ -796,8 +810,12 @@ public async Task ShouldDetectGitFetch() Repository.Owner.Should().Be("EvilStanleyGoldman"); Repository.LocalPath.Should().Be(TestRepoMasterCleanUnsynchronized); Repository.IsGitHub.Should().BeTrue(); - Repository.CurrentBranchName.Should().Be(null); - Repository.CurrentBranch.HasValue.Should().BeFalse(); + Repository.CurrentBranchName.Should().Be("master"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("master"); + Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); + Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("origin"); Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); @@ -818,7 +836,8 @@ public async Task ShouldDetectGitFetch() repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnHeadUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); @@ -832,8 +851,12 @@ public async Task ShouldDetectGitFetch() Repository.Owner.Should().Be("EvilStanleyGoldman"); Repository.LocalPath.Should().Be(TestRepoMasterCleanUnsynchronized); Repository.IsGitHub.Should().BeTrue(); - Repository.CurrentBranchName.Should().Be(null); - Repository.CurrentBranch.HasValue.Should().BeFalse(); + Repository.CurrentBranchName.Should().Be("master"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("master"); + Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); + Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("origin"); Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); diff --git a/src/tests/UnitTests/Git/RepositoryTests.cs b/src/tests/UnitTests/Git/RepositoryTests.cs index ce1f36869..36ccc134b 100644 --- a/src/tests/UnitTests/Git/RepositoryTests.cs +++ b/src/tests/UnitTests/Git/RepositoryTests.cs @@ -59,8 +59,10 @@ public void Repository() var remoteDictionary = remotes.ToDictionary(remote => remote.Name); + var masterOriginBranch = new ConfigBranch { Name = "master", Remote = origin }; + var branches = new[] { - new ConfigBranch { Name = "master", Remote = origin }, + masterOriginBranch, new ConfigBranch { Name = "features/feature-1", Remote = origin } }; @@ -97,7 +99,8 @@ public void Repository() repositoryEvents.OnRemoteBranchListChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnRemoteBranchListChanged not raised"); - repositoryManager.OnHeadUpdated += Raise.Event>("ref:refs/heads/master"); + repositoryManager.OnCurrentBranchUpdated += Raise.Event>(masterOriginBranch); + repositoryManager.OnCurrentRemoteUpdated += Raise.Event>(origin); repositoryEvents.OnCurrentBranchChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnCurrentBranchChanged not raised"); repositoryEvents.OnCurrentRemoteChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnCurrentRemoteChanged not raised"); From c4976416af8f8a157d7c015bf1ea8789c746d10b Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Thu, 21 Sep 2017 17:18:04 -0400 Subject: [PATCH 37/57] Attempting to add a remotes list; Reordered file --- src/GitHub.Api/Git/GitRemote.cs | 4 +- src/GitHub.Api/Git/IRepository.cs | 9 +- src/GitHub.Api/Git/Repository.cs | 211 ++++++++++-------- src/GitHub.Api/Git/RepositoryManager.cs | 12 +- .../Editor/GitHub.Unity/UI/HistoryView.cs | 4 +- .../Events/RepositoryManagerTests.cs | 46 ++-- src/tests/IntegrationTests/SetUpFixture.cs | 2 +- .../TestUtils/Events/IRepositoryListener.cs | 2 +- .../Events/IRepositoryManagerListener.cs | 8 +- src/tests/UnitTests/SetUpFixture.cs | 2 +- 10 files changed, 165 insertions(+), 135 deletions(-) diff --git a/src/GitHub.Api/Git/GitRemote.cs b/src/GitHub.Api/Git/GitRemote.cs index 0a7b1b26a..d5478d897 100644 --- a/src/GitHub.Api/Git/GitRemote.cs +++ b/src/GitHub.Api/Git/GitRemote.cs @@ -3,7 +3,7 @@ namespace GitHub.Unity { - enum GitRemoteFunction + public enum GitRemoteFunction { Unknown, Fetch, @@ -12,7 +12,7 @@ enum GitRemoteFunction } [Serializable] - struct GitRemote + public struct GitRemote { public string Name; public string Url; diff --git a/src/GitHub.Api/Git/IRepository.cs b/src/GitHub.Api/Git/IRepository.cs index 63a5beab3..470baab64 100644 --- a/src/GitHub.Api/Git/IRepository.cs +++ b/src/GitHub.Api/Git/IRepository.cs @@ -51,17 +51,18 @@ public interface IRepository : IEquatable /// ConfigBranch? CurrentBranch { get; set; } GitStatus CurrentStatus { get; set; } - IEnumerable LocalBranches { get; } - IEnumerable RemoteBranches { get; } + IList Remotes { get; } + IList LocalBranches { get; } + IList RemoteBranches { get; } IUser User { get; set; } - IEnumerable CurrentLocks { get; } + IList CurrentLocks { get; } string CurrentBranchName { get; } event Action OnStatusChanged; event Action OnCurrentBranchChanged; event Action OnCurrentRemoteChanged; event Action OnLocalBranchListChanged; - event Action OnHeadChanged; + event Action OnLocalBranchChanged; event Action> OnLocksChanged; event Action OnRepositoryInfoChanged; event Action OnRemoteBranchListChanged; diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 84568efa2..b497c9669 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -8,38 +8,30 @@ namespace GitHub.Unity { [DebuggerDisplay("{DebuggerDisplay,nq}")] - class Repository : IRepository, IEquatable + class Repository : IEquatable, IRepository { - private IRepositoryManager repositoryManager; private ConfigBranch? currentBranch; + private IList currentLocks; private ConfigRemote? currentRemote; private GitStatus currentStatus; private Dictionary localBranches = new Dictionary(); - private IEnumerable locks; private Dictionary> remoteBranches = new Dictionary>(); private Dictionary remotes; - - public event Action OnStatusChanged; + private IRepositoryManager repositoryManager; public event Action OnCurrentBranchChanged; public event Action OnCurrentRemoteChanged; + public event Action OnLocalBranchChanged; public event Action OnLocalBranchListChanged; - public event Action OnRemoteBranchListChanged; - public event Action OnHeadChanged; public event Action> OnLocksChanged; + public event Action OnRemoteBranchListChanged; public event Action OnRepositoryInfoChanged; - public IEnumerable LocalBranches => localBranches.Values.Select( - x => new GitBranch(x.Name, (x.IsTracking ? (x.Remote.Value.Name + "/" + x.Name) : "[None]"), x.Name == CurrentBranch?.Name)); - - public IEnumerable RemoteBranches => remoteBranches.Values.SelectMany( - x => x.Values).Select(x => new GitBranch(x.Remote.Value.Name + "/" + x.Name, "[None]", false)); + public event Action OnStatusChanged; /// /// Initializes a new instance of the class. /// - /// /// The repository name. - /// The repository's clone URL. /// public Repository(string name, NPath localPath) { @@ -57,13 +49,13 @@ public void Initialize(IRepositoryManager repositoryManager) this.repositoryManager = repositoryManager; - repositoryManager.OnCurrentBranchUpdated += RepositoryManager_OnCurrentBranchUpdated; - repositoryManager.OnCurrentRemoteUpdated += RepositoryManager_OnCurrentRemoteUpdated; - repositoryManager.OnStatusUpdated += RepositoryManager_OnStatusUpdated; - repositoryManager.OnLocksUpdated += RepositoryManager_OnLocksUpdated; - repositoryManager.OnLocalBranchListUpdated += RepositoryManager_OnLocalBranchListUpdated; - repositoryManager.OnRemoteBranchListUpdated += RepositoryManager_OnRemoteBranchListUpdated; - repositoryManager.OnLocalBranchUpdated += RepositoryManager_OnLocalBranchUpdated; + repositoryManager.OnCurrentBranchUpdated += branch => CurrentBranch = branch; + repositoryManager.OnCurrentRemoteUpdated += remote => CurrentRemote = remote; + repositoryManager.OnStatusUpdated += status => CurrentStatus = status; + repositoryManager.OnLocksUpdated += locks => CurrentLocks = locks; + repositoryManager.OnLocalBranchListUpdated += OnRepositoryManager_OnLocalBranchListUpdated; + repositoryManager.OnRemoteBranchListUpdated += OnRepositoryManager_OnRemoteBranchListUpdated; + repositoryManager.OnLocalBranchUpdated += OnRepositoryManager_OnLocalBranchUpdated; repositoryManager.OnLocalBranchAdded += RepositoryManager_OnLocalBranchAdded; repositoryManager.OnLocalBranchRemoved += RepositoryManager_OnLocalBranchRemoved; repositoryManager.OnRemoteBranchAdded += RepositoryManager_OnRemoteBranchAdded; @@ -122,7 +114,7 @@ public ITask Fetch() { return repositoryManager.Fetch(CurrentRemote.Value.Name); } - + public ITask Revert(string changeset) { return repositoryManager.Revert(changeset); @@ -145,65 +137,109 @@ public ITask ReleaseLock(string file, bool force) return repositoryManager.UnlockFile(file, force); } - private void UpdateRepositoryInfo() + /// + /// Note: We don't consider CloneUrl a part of the hash code because it can change during the lifetime + /// of a repository. Equals takes care of any hash collisions because of this + /// + /// + public override int GetHashCode() { - if (CurrentRemote.HasValue) - { - CloneUrl = new UriString(CurrentRemote.Value.Url); - Name = CloneUrl.RepositoryName; - Logger.Trace("CloneUrl: {0}", CloneUrl.ToString()); - } - else - { - CloneUrl = null; - Name = LocalPath.FileName; - Logger.Trace("CloneUrl: [NULL]"); - } - - OnRepositoryInfoChanged?.Invoke(); + return LocalPath.GetHashCode(); } - private void RepositoryManager_OnStatusUpdated(GitStatus status) + public override bool Equals(object obj) { - CurrentStatus = status; + if (ReferenceEquals(this, obj)) + return true; + var other = obj as Repository; + return Equals(other); } - private void RepositoryManager_OnLocksUpdated(IEnumerable locks) + public bool Equals(Repository other) { - CurrentLocks = locks; - OnLocksChanged?.Invoke(CurrentLocks); + return Equals((IRepository)other); } - private void RepositoryManager_OnCurrentBranchUpdated(ConfigBranch? branch) + public bool Equals(IRepository other) { - CurrentBranch = branch; + if (ReferenceEquals(this, other)) + return true; + return other != null && + object.Equals(LocalPath, other.LocalPath); } - private void RepositoryManager_OnCurrentRemoteUpdated(ConfigRemote? remote) + private void OnRepositoryManager_OnLocalBranchUpdated(string name) { - CurrentRemote = remote; + if (name == currentBranch?.Name) + { + OnLocalBranchChanged?.Invoke(); + Refresh(); + } } - private void RepositoryManager_OnRemoteBranchListUpdated(Dictionary> branches) + private void OnRepositoryManager_OnRemoteBranchListUpdated(Dictionary updatedRemotes, Dictionary> branches) { - Logger.Trace("RemoteBranchListUpdated"); + remotes = updatedRemotes; + + Remotes = remotes.Select(pair => new GitRemote { + Name = pair.Value.Name, + Url = pair.Value.Url + }).ToArray(); remoteBranches = branches; - remotes = branches - .Where(pair => pair.Value.Any()) - .ToDictionary(pair => pair.Key, pair => pair.Value.First().Value.Remote.Value); + RemoteBranches = remoteBranches.Values + .SelectMany(x => x.Values) + .Select(x => + { + var name = x.Remote.Value.Name + "/" + x.Name; + return new GitBranch(name, "[None]", false); + }).ToArray(); + + + Logger.Trace("OnRemoteBranchListChanged"); OnRemoteBranchListChanged?.Invoke(); } - private void RepositoryManager_OnLocalBranchListUpdated(Dictionary branches) + private void OnRepositoryManager_OnLocalBranchListUpdated(Dictionary branches) { - Logger.Trace("LocalBranchListUpdated"); - localBranches = branches; + + LocalBranches = localBranches.Values.Select(x => + { + var argName = x.Name; + + var tracking = x.IsTracking + ? x.Remote.Value.Name + "/" + argName + : "[None]"; + + var active = argName == CurrentBranch?.Name; + + return new GitBranch(argName, tracking, active); + }).ToArray(); + + Logger.Trace("OnLocalBranchListChanged"); OnLocalBranchListChanged?.Invoke(); } + private void UpdateRepositoryInfo() + { + if (CurrentRemote.HasValue) + { + CloneUrl = new UriString(CurrentRemote.Value.Url); + Name = CloneUrl.RepositoryName; + Logger.Trace("CloneUrl: {0}", CloneUrl.ToString()); + } + else + { + CloneUrl = null; + Name = LocalPath.FileName; + Logger.Trace("CloneUrl: [NULL]"); + } + + OnRepositoryInfoChanged?.Invoke(); + } + private void RepositoryManager_OnLocalBranchRemoved(string name) { if (localBranches.ContainsKey(name)) @@ -235,16 +271,6 @@ private void RepositoryManager_OnLocalBranchAdded(string name) } } - private void RepositoryManager_OnLocalBranchUpdated(string name) - { - if (name == currentBranch?.Name) - { - // commit of current branch changed, trigger OnHeadChanged - OnHeadChanged?.Invoke(); - repositoryManager.Refresh(); - } - } - private void RepositoryManager_OnRemoteBranchAdded(string remote, string name) { Dictionary branchList; @@ -265,7 +291,7 @@ private void RepositoryManager_OnRemoteBranchAdded(string remote, string name) Logger.Warning("Remote {0} is not found", remote); } } - + private void RepositoryManager_OnRemoteBranchRemoved(string remote, string name) { Dictionary branchList; @@ -287,36 +313,11 @@ private void RepositoryManager_OnRemoteBranchRemoved(string remote, string name) } } - /// - /// Note: We don't consider CloneUrl a part of the hash code because it can change during the lifetime - /// of a repository. Equals takes care of any hash collisions because of this - /// - /// - public override int GetHashCode() - { - return LocalPath.GetHashCode(); - } + public IList Remotes { get; private set; } - public override bool Equals(object obj) - { - if (ReferenceEquals(this, obj)) - return true; - var other = obj as Repository; - return Equals(other); - } + public IList LocalBranches { get; private set; } - public bool Equals(Repository other) - { - return (Equals((IRepository)other)); - } - - public bool Equals(IRepository other) - { - if (ReferenceEquals(this, other)) - return true; - return other != null && - object.Equals(LocalPath, other.LocalPath); - } + public IList RemoteBranches { get; private set; } public ConfigBranch? CurrentBranch { @@ -331,6 +332,7 @@ public ConfigBranch? CurrentBranch } } } + /// /// Gets the current branch of the repository. /// @@ -381,14 +383,25 @@ public GitStatus CurrentStatus get { return currentStatus; } set { - Logger.Trace("OnStatusUpdated: {0}", value.ToString()); currentStatus = value; - OnStatusChanged?.Invoke(CurrentStatus); + Logger.Trace("OnStatusChanged: {0}", value.ToString()); + OnStatusChanged?.Invoke(value); } } public IUser User { get; set; } - public IEnumerable CurrentLocks { get; private set; } + + public IList CurrentLocks + { + get { return currentLocks; } + private set + { + Logger.Trace("OnLocksChanged: {0}", value.ToString()); + currentLocks = value; + OnLocksChanged?.Invoke(value); + } + } + protected static ILogging Logger { get; } = Logging.GetLogger(); } @@ -401,12 +414,12 @@ public interface IUser [Serializable] class User : IUser { - public string Name { get; set; } - public string Email { get; set; } - public override string ToString() { return String.Format("Name: {0} Email: {1}", Name, Email); } + + public string Name { get; set; } + public string Email { get; set; } } } \ No newline at end of file diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index f4405f467..ed3be8847 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -10,9 +10,9 @@ public interface IRepositoryManager : IDisposable { event Action OnIsBusyChanged; event Action OnStatusUpdated; - event Action> OnLocksUpdated; + event Action> OnLocksUpdated; event Action> OnLocalBranchListUpdated; - event Action>> OnRemoteBranchListUpdated; + event Action, Dictionary>> OnRemoteBranchListUpdated; event Action OnCurrentBranchUpdated; event Action OnCurrentRemoteUpdated; event Action OnLocalBranchUpdated; @@ -109,8 +109,8 @@ class RepositoryManager : IRepositoryManager public event Action OnIsBusyChanged; public event Action> OnLocalBranchListUpdated; - public event Action>> OnRemoteBranchListUpdated; - public event Action> OnLocksUpdated; + public event Action, Dictionary>> OnRemoteBranchListUpdated; + public event Action> OnLocksUpdated; public event Action OnStatusUpdated; public event Action OnCurrentBranchUpdated; public event Action OnCurrentRemoteUpdated; @@ -523,7 +523,7 @@ private void LoadRemotesFromConfig() { Logger.Trace("LoadRemotesFromConfig"); - var remotes = config.GetRemotes().ToDictionary(x => x.Name, x => x); + var remotes = config.GetRemotes().ToArray().ToDictionary(x => x.Name, x => x); var remoteBranches = new Dictionary>(); foreach (var remote in remotes.Keys) @@ -544,7 +544,7 @@ private void LoadRemotesFromConfig() } } - OnRemoteBranchListUpdated?.Invoke(remoteBranches); + OnRemoteBranchListUpdated?.Invoke(remotes, remoteBranches); } private bool disposed; diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs index d73004328..c830c39c1 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs @@ -121,7 +121,7 @@ private void AttachHandlers(IRepository repository) { if (repository == null) return; - repository.OnHeadChanged += Refresh; + repository.OnLocalBranchChanged += Refresh; repository.OnStatusChanged += UpdateStatusOnMainThread; repository.OnCurrentBranchChanged += s => Refresh(); repository.OnCurrentRemoteChanged += s => Refresh(); @@ -131,7 +131,7 @@ private void DetachHandlers(IRepository repository) { if (repository == null) return; - repository.OnHeadChanged -= Refresh; + repository.OnLocalBranchChanged -= Refresh; repository.OnStatusChanged -= UpdateStatusOnMainThread; repository.OnCurrentBranchChanged -= s => Refresh(); repository.OnCurrentRemoteChanged -= s => Refresh(); diff --git a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs index 8bdda2f71..27e4af96f 100644 --- a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs @@ -54,6 +54,7 @@ public async Task ShouldDoNothingOnInitialize() new GitBranch("feature/document", "origin/feature/document", false), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); + Repository.Remotes.Should().BeEquivalentTo(); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -97,7 +98,7 @@ public async Task ShouldDetectFileChanges() repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); @@ -156,7 +157,7 @@ public async Task ShouldAddAndCommitFiles() repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); @@ -182,7 +183,7 @@ await RepositoryManager repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.Received().OnLocalBranchUpdated(expectedLocalBranch); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); @@ -233,7 +234,7 @@ public async Task ShouldAddAndCommitAllFiles() repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); @@ -259,7 +260,7 @@ await RepositoryManager repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.Received().OnLocalBranchUpdated(expectedLocalBranch); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); @@ -300,7 +301,7 @@ public async Task ShouldDetectBranchChange() repositoryManagerListener.Received().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.Received().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); @@ -328,6 +329,10 @@ public async Task ShouldDetectBranchChange() new GitBranch("feature/document", "origin/feature/document", true), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); + Repository.Remotes.Should().BeEquivalentTo(new GitRemote { + Name = "origin", + Url = "https://github.com/EvilStanleyGoldman/IOTestsRepo.git" + }); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -355,7 +360,7 @@ public async Task ShouldDetectBranchDelete() repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.Received().OnLocalBranchRemoved(deletedBranch); @@ -380,6 +385,7 @@ public async Task ShouldDetectBranchDelete() new GitBranch("master", "origin/master", true), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); + Repository.Remotes.Should().BeEquivalentTo(); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -407,7 +413,7 @@ public async Task ShouldDetectBranchCreate() repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.Received().OnLocalBranchAdded(createdBranch1); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); @@ -434,6 +440,7 @@ public async Task ShouldDetectBranchCreate() new GitBranch("feature/document2", "[None]", false), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); + Repository.Remotes.Should().BeEquivalentTo(); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -455,7 +462,7 @@ public async Task ShouldDetectBranchCreate() repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.Received().OnLocalBranchAdded(createdBranch2); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); @@ -483,6 +490,7 @@ public async Task ShouldDetectBranchCreate() new GitBranch("feature2/document2", "[None]", false), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); + Repository.Remotes.Should().BeEquivalentTo(); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -511,7 +519,7 @@ public async Task ShouldDetectChangesToRemotes() repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); @@ -537,6 +545,7 @@ public async Task ShouldDetectChangesToRemotes() new GitBranch("feature/document", "[None]", false), new GitBranch("feature/other-feature", "[None]", false), }); + Repository.Remotes.Should().BeEquivalentTo(); Repository.RemoteBranches.Should().BeEmpty(); repositoryManagerListener.ClearReceivedCalls(); @@ -555,7 +564,7 @@ public async Task ShouldDetectChangesToRemotes() repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); @@ -581,6 +590,7 @@ public async Task ShouldDetectChangesToRemotes() new GitBranch("feature/document", "[None]", false), new GitBranch("feature/other-feature", "[None]", false), }); + Repository.Remotes.Should().BeEquivalentTo(); Repository.RemoteBranches.Should().BeEmpty(); } @@ -613,6 +623,7 @@ public async Task ShouldDetectChangesToRemotesWhenSwitchingBranches() new GitBranch("feature/document", "origin/feature/document", false), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); + Repository.Remotes.Should().BeEquivalentTo(); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -635,7 +646,7 @@ await RepositoryManager.CreateBranch("branch2", "another/master") repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.Received().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); @@ -662,6 +673,7 @@ await RepositoryManager.CreateBranch("branch2", "another/master") new GitBranch("feature/document", "origin/feature/document", false), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); + Repository.Remotes.Should().BeEquivalentTo(); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -688,7 +700,7 @@ await RepositoryManager.SwitchBranch("branch2") repositoryManagerListener.Received().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.Received().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); @@ -715,6 +727,7 @@ await RepositoryManager.SwitchBranch("branch2") new GitBranch("feature/document", "origin/feature/document", false), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); + Repository.Remotes.Should().BeEquivalentTo(); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -754,7 +767,7 @@ public async Task ShouldDetectGitPull() repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.Received().OnLocalBranchUpdated(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); @@ -782,6 +795,7 @@ public async Task ShouldDetectGitPull() new GitBranch("feature/document", "origin/feature/document", false), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); + Repository.Remotes.Should().BeEquivalentTo(); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -822,6 +836,7 @@ public async Task ShouldDetectGitFetch() Repository.LocalBranches.Should().BeEquivalentTo(new[] { new GitBranch("feature/document", "origin/feature/document", false), }); + Repository.Remotes.Should().BeEquivalentTo(); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document", "[None]", false), @@ -839,7 +854,7 @@ public async Task ShouldDetectGitFetch() repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); @@ -863,6 +878,7 @@ public async Task ShouldDetectGitFetch() Repository.LocalBranches.Should().BeEquivalentTo(new[] { new GitBranch("feature/document", "origin/feature/document", false), }); + Repository.Remotes.Should().BeEquivalentTo(); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document", "[None]", false), diff --git a/src/tests/IntegrationTests/SetUpFixture.cs b/src/tests/IntegrationTests/SetUpFixture.cs index f77cdec8d..ead5695e4 100644 --- a/src/tests/IntegrationTests/SetUpFixture.cs +++ b/src/tests/IntegrationTests/SetUpFixture.cs @@ -14,7 +14,7 @@ public void Setup() Logging.LogAdapter = new MultipleLogAdapter( new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-integration-tests.log") - //,new ConsoleLogAdapter() + ,new ConsoleLogAdapter() ); } } diff --git a/src/tests/TestUtils/Events/IRepositoryListener.cs b/src/tests/TestUtils/Events/IRepositoryListener.cs index 0b4ab2276..28094bf26 100644 --- a/src/tests/TestUtils/Events/IRepositoryListener.cs +++ b/src/tests/TestUtils/Events/IRepositoryListener.cs @@ -84,7 +84,7 @@ public static void AttachListener(this IRepositoryListener listener, repositoryEvents?.OnRemoteBranchListChanged.Set(); }; - repository.OnHeadChanged += () => + repository.OnLocalBranchChanged += () => { logger?.Debug("OnHeadChanged"); listener.OnHeadChanged(); diff --git a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs index 61ead5be3..6107f33ae 100644 --- a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs +++ b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs @@ -13,7 +13,7 @@ interface IRepositoryManagerListener void OnStatusUpdated(GitStatus status); void OnLocksUpdated(IEnumerable locks); void OnLocalBranchListUpdated(Dictionary branchList); - void OnRemoteBranchListUpdated(Dictionary> remoteBranchList); + void OnRemoteBranchListUpdated(Dictionary remotesList, Dictionary> remoteBranchList); void OnLocalBranchUpdated(string name); void OnLocalBranchAdded(string name); void OnLocalBranchRemoved(string name); @@ -109,9 +109,9 @@ public static void AttachListener(this IRepositoryManagerListener listener, managerEvents?.OnLocalBranchListUpdated.Set(); }; - repositoryManager.OnRemoteBranchListUpdated += branchList => { + repositoryManager.OnRemoteBranchListUpdated += (remotesList, branchList) => { logger?.Trace("OnRemoteBranchListUpdated"); - listener.OnRemoteBranchListUpdated(branchList); + listener.OnRemoteBranchListUpdated(remotesList, branchList); managerEvents?.OnRemoteBranchListUpdated.Set(); }; @@ -160,7 +160,7 @@ public static void AssertDidNotReceiveAnyCalls(this IRepositoryManagerListener r repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.DidNotReceive().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); diff --git a/src/tests/UnitTests/SetUpFixture.cs b/src/tests/UnitTests/SetUpFixture.cs index 1185e8146..a716ab14c 100644 --- a/src/tests/UnitTests/SetUpFixture.cs +++ b/src/tests/UnitTests/SetUpFixture.cs @@ -14,7 +14,7 @@ public void SetUp() Logging.LogAdapter = new MultipleLogAdapter( new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-unit-tests.log") - //,new ConsoleLogAdapter() + , new ConsoleLogAdapter() ); } } From 6f0d6ab0a3904a8e463d6402b4c724f8c4060c1b Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Thu, 21 Sep 2017 18:06:32 -0400 Subject: [PATCH 38/57] Making all the unit tests pass --- src/GitHub.Api/Git/IRepository.cs | 4 +- src/GitHub.Api/Git/Repository.cs | 37 ++--- src/GitHub.Api/Git/RepositoryManager.cs | 64 ++++---- .../Events/RepositoryManagerTests.cs | 146 +++++++++++------- src/tests/IntegrationTests/SetUpFixture.cs | 2 +- .../Events/IRepositoryManagerListener.cs | 16 ++ src/tests/UnitTests/Git/RepositoryTests.cs | 2 +- 7 files changed, 157 insertions(+), 114 deletions(-) diff --git a/src/GitHub.Api/Git/IRepository.cs b/src/GitHub.Api/Git/IRepository.cs index 470baab64..da9105f55 100644 --- a/src/GitHub.Api/Git/IRepository.cs +++ b/src/GitHub.Api/Git/IRepository.cs @@ -52,8 +52,8 @@ public interface IRepository : IEquatable ConfigBranch? CurrentBranch { get; set; } GitStatus CurrentStatus { get; set; } IList Remotes { get; } - IList LocalBranches { get; } - IList RemoteBranches { get; } + IEnumerable LocalBranches { get; } + IEnumerable RemoteBranches { get; } IUser User { get; set; } IList CurrentLocks { get; } string CurrentBranchName { get; } diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index b497c9669..df51b7615 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -188,15 +188,6 @@ private void OnRepositoryManager_OnRemoteBranchListUpdated(Dictionary x.Values) - .Select(x => - { - var name = x.Remote.Value.Name + "/" + x.Name; - return new GitBranch(name, "[None]", false); - }).ToArray(); - - Logger.Trace("OnRemoteBranchListChanged"); OnRemoteBranchListChanged?.Invoke(); } @@ -205,19 +196,6 @@ private void OnRepositoryManager_OnLocalBranchListUpdated(Dictionary - { - var argName = x.Name; - - var tracking = x.IsTracking - ? x.Remote.Value.Name + "/" + argName - : "[None]"; - - var active = argName == CurrentBranch?.Name; - - return new GitBranch(argName, tracking, active); - }).ToArray(); - Logger.Trace("OnLocalBranchListChanged"); OnLocalBranchListChanged?.Invoke(); } @@ -315,9 +293,20 @@ private void RepositoryManager_OnRemoteBranchRemoved(string remote, string name) public IList Remotes { get; private set; } - public IList LocalBranches { get; private set; } + public IEnumerable LocalBranches => localBranches.Values.Select(x => { + var name = x.Name; + var trackingName = x.IsTracking ? x.Remote.Value.Name + "/" + name : "[None]"; + var isActive = name == CurrentBranch?.Name; + + return new GitBranch(name, trackingName, isActive); + }); + + public IEnumerable RemoteBranches => remoteBranches.Values.SelectMany(x => x.Values).Select(x => { + var name = x.Remote.Value.Name + "/" + x.Name; + var trackingName = "[None]"; - public IList RemoteBranches { get; private set; } + return new GitBranch(name, trackingName, false); + }); public ConfigBranch? CurrentBranch { diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index ed3be8847..44d50eb4d 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -8,23 +8,20 @@ namespace GitHub.Unity { public interface IRepositoryManager : IDisposable { - event Action OnIsBusyChanged; - event Action OnStatusUpdated; - event Action> OnLocksUpdated; - event Action> OnLocalBranchListUpdated; - event Action, Dictionary>> OnRemoteBranchListUpdated; event Action OnCurrentBranchUpdated; event Action OnCurrentRemoteUpdated; - event Action OnLocalBranchUpdated; + event Action OnGitUserLoaded; + event Action OnIsBusyChanged; event Action OnLocalBranchAdded; + event Action> OnLocalBranchListUpdated; event Action OnLocalBranchRemoved; + event Action OnLocalBranchUpdated; + event Action> OnLocksUpdated; event Action OnRemoteBranchAdded; + event Action, Dictionary>> OnRemoteBranchListUpdated; event Action OnRemoteBranchRemoved; - event Action OnGitUserLoaded; + event Action OnStatusUpdated; - IGitConfig Config { get; } - IGitClient GitClient { get; } - bool IsBusy { get; } void Initialize(); void Start(); void Stop(); @@ -46,6 +43,10 @@ public interface IRepositoryManager : IDisposable ITask LockFile(string file); ITask UnlockFile(string file, bool force); int WaitForEvents(); + + IGitConfig Config { get; } + IGitClient GitClient { get; } + bool IsBusy { get; } } interface IRepositoryPathConfiguration @@ -103,36 +104,20 @@ class RepositoryManager : IRepositoryManager private readonly IRepositoryWatcher watcher; private bool isBusy; - private Action repositoryUpdateCallback; - - // internal busy flag signal - public event Action OnIsBusyChanged; - public event Action> OnLocalBranchListUpdated; - public event Action, Dictionary>> OnRemoteBranchListUpdated; - public event Action> OnLocksUpdated; - public event Action OnStatusUpdated; public event Action OnCurrentBranchUpdated; public event Action OnCurrentRemoteUpdated; - public event Action OnLocalBranchUpdated; + public event Action OnGitUserLoaded; + public event Action OnIsBusyChanged; public event Action OnLocalBranchAdded; + public event Action> OnLocalBranchListUpdated; public event Action OnLocalBranchRemoved; + public event Action OnLocalBranchUpdated; + public event Action> OnLocksUpdated; public event Action OnRemoteBranchAdded; + public event Action, Dictionary>> OnRemoteBranchListUpdated; public event Action OnRemoteBranchRemoved; - public event Action OnGitUserLoaded; - - public static RepositoryManager CreateInstance(IPlatform platform, ITaskManager taskManager, IUsageTracker usageTracker, - IGitClient gitClient, NPath repositoryRoot) - { - var repositoryPathConfiguration = new RepositoryPathConfiguration(repositoryRoot); - string filePath = repositoryPathConfiguration.DotGitConfig; - var gitConfig = new GitConfig(filePath); - - var repositoryWatcher = new RepositoryWatcher(platform, repositoryPathConfiguration, taskManager.Token); - - return new RepositoryManager(platform, taskManager, usageTracker, gitConfig, repositoryWatcher, - gitClient, repositoryPathConfiguration, taskManager.Token); - } + public event Action OnStatusUpdated; public RepositoryManager(IPlatform platform, ITaskManager taskManager, IUsageTracker usageTracker, IGitConfig gitConfig, IRepositoryWatcher repositoryWatcher, IGitClient gitClient, @@ -150,6 +135,19 @@ public RepositoryManager(IPlatform platform, ITaskManager taskManager, IUsageTra SetupWatcher(); } + public static RepositoryManager CreateInstance(IPlatform platform, ITaskManager taskManager, IUsageTracker usageTracker, + IGitClient gitClient, NPath repositoryRoot) + { + var repositoryPathConfiguration = new RepositoryPathConfiguration(repositoryRoot); + string filePath = repositoryPathConfiguration.DotGitConfig; + var gitConfig = new GitConfig(filePath); + + var repositoryWatcher = new RepositoryWatcher(platform, repositoryPathConfiguration, taskManager.Token); + + return new RepositoryManager(platform, taskManager, usageTracker, gitConfig, repositoryWatcher, + gitClient, repositoryPathConfiguration, taskManager.Token); + } + public void Initialize() { Logger.Trace("Initialize"); diff --git a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs index 27e4af96f..e9636ca56 100644 --- a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs @@ -31,7 +31,7 @@ public async Task ShouldDoNothingOnInitialize() repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents, 2); + repositoryManagerEvents.WaitForNotBusy(2); repositoryManagerListener.AssertDidNotReceiveAnyCalls(); @@ -54,7 +54,11 @@ public async Task ShouldDoNothingOnInitialize() new GitBranch("feature/document", "origin/feature/document", false), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); - Repository.Remotes.Should().BeEquivalentTo(); + Repository.Remotes.Should().BeEquivalentTo(new GitRemote + { + Name = "origin", + Url = "https://github.com/EvilStanleyGoldman/IOTestsRepo.git" + }); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -89,8 +93,8 @@ public async Task ShouldDetectFileChanges() await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); - WaitForStatusUpdated(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); + repositoryManagerEvents.WaitForStatusUpdated(); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); @@ -144,12 +148,12 @@ public async Task ShouldAddAndCommitFiles() //Intentionally wait two cycles, in case the first cycle did not pick up all events RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); - WaitForStatusUpdated(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); + repositoryManagerEvents.WaitForStatusUpdated(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); - WaitForStatusUpdated(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); + repositoryManagerEvents.WaitForStatusUpdated(); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); @@ -175,7 +179,7 @@ await RepositoryManager await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); @@ -225,8 +229,8 @@ public async Task ShouldAddAndCommitAllFiles() await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); - WaitForStatusUpdated(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); + repositoryManagerEvents.WaitForStatusUpdated(); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); @@ -252,7 +256,7 @@ await RepositoryManager await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); @@ -292,8 +296,8 @@ public async Task ShouldDetectBranchChange() await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); - WaitForStatusUpdated(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); + repositoryManagerEvents.WaitForStatusUpdated(); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); @@ -352,7 +356,7 @@ public async Task ShouldDetectBranchDelete() await RepositoryManager.DeleteBranch(deletedBranch, true).StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); @@ -385,7 +389,11 @@ public async Task ShouldDetectBranchDelete() new GitBranch("master", "origin/master", true), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); - Repository.Remotes.Should().BeEquivalentTo(); + Repository.Remotes.Should().BeEquivalentTo(new GitRemote + { + Name = "origin", + Url = "https://github.com/EvilStanleyGoldman/IOTestsRepo.git" + }); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -405,7 +413,7 @@ public async Task ShouldDetectBranchCreate() await RepositoryManager.CreateBranch(createdBranch1, "feature/document").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); @@ -440,7 +448,11 @@ public async Task ShouldDetectBranchCreate() new GitBranch("feature/document2", "[None]", false), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); - Repository.Remotes.Should().BeEquivalentTo(); + Repository.Remotes.Should().BeEquivalentTo(new GitRemote + { + Name = "origin", + Url = "https://github.com/EvilStanleyGoldman/IOTestsRepo.git" + }); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -454,7 +466,7 @@ public async Task ShouldDetectBranchCreate() await RepositoryManager.CreateBranch(createdBranch2, "feature/document").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); @@ -490,7 +502,11 @@ public async Task ShouldDetectBranchCreate() new GitBranch("feature2/document2", "[None]", false), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); - Repository.Remotes.Should().BeEquivalentTo(); + Repository.Remotes.Should().BeEquivalentTo(new GitRemote + { + Name = "origin", + Url = "https://github.com/EvilStanleyGoldman/IOTestsRepo.git" + }); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -509,7 +525,7 @@ public async Task ShouldDetectChangesToRemotes() await RepositoryManager.RemoteRemove("origin").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); repositoryManagerEvents.OnRemoteBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); repositoryManagerEvents.OnLocalBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); @@ -554,7 +570,7 @@ public async Task ShouldDetectChangesToRemotes() await RepositoryManager.RemoteAdd("origin", "https://github.com/EvilShana/IOTestsRepo.git").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); repositoryManagerEvents.OnRemoteBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); repositoryManagerEvents.OnLocalBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); @@ -590,7 +606,11 @@ public async Task ShouldDetectChangesToRemotes() new GitBranch("feature/document", "[None]", false), new GitBranch("feature/other-feature", "[None]", false), }); - Repository.Remotes.Should().BeEquivalentTo(); + Repository.Remotes.Should().BeEquivalentTo(new GitRemote + { + Name = "origin", + Url = "https://github.com/EvilShana/IOTestsRepo.git" + }); Repository.RemoteBranches.Should().BeEmpty(); } @@ -623,7 +643,15 @@ public async Task ShouldDetectChangesToRemotesWhenSwitchingBranches() new GitBranch("feature/document", "origin/feature/document", false), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); - Repository.Remotes.Should().BeEquivalentTo(); + Repository.Remotes.Should().BeEquivalentTo(new GitRemote + { + Name = "origin", + Url = "https://github.com/EvilStanleyGoldman/IOTestsRepo.git" + }, new GitRemote + { + Name = "another", + Url = "https://another.remote/Owner/Url.git" + }); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -638,7 +666,7 @@ await RepositoryManager.CreateBranch("branch2", "another/master") await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); @@ -673,7 +701,15 @@ await RepositoryManager.CreateBranch("branch2", "another/master") new GitBranch("feature/document", "origin/feature/document", false), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); - Repository.Remotes.Should().BeEquivalentTo(); + Repository.Remotes.Should().BeEquivalentTo(new GitRemote + { + Name = "origin", + Url = "https://github.com/EvilStanleyGoldman/IOTestsRepo.git" + }, new GitRemote + { + Name = "another", + Url = "https://another.remote/Owner/Url.git" + }); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -691,8 +727,8 @@ await RepositoryManager.SwitchBranch("branch2") await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); - WaitForHeadUpdated(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); + repositoryManagerEvents.WaitForHeadUpdated(); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); @@ -727,7 +763,15 @@ await RepositoryManager.SwitchBranch("branch2") new GitBranch("feature/document", "origin/feature/document", false), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); - Repository.Remotes.Should().BeEquivalentTo(); + Repository.Remotes.Should().BeEquivalentTo(new GitRemote + { + Name = "origin", + Url = "https://github.com/EvilStanleyGoldman/IOTestsRepo.git" + }, new GitRemote + { + Name = "another", + Url = "https://another.remote/Owner/Url.git" + }); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -758,8 +802,8 @@ public async Task ShouldDetectGitPull() await RepositoryManager.Pull("origin", "master").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); - WaitForStatusUpdated(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); + repositoryManagerEvents.WaitForStatusUpdated(); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.Received().OnStatusUpdated(Args.GitStatus); @@ -795,7 +839,11 @@ public async Task ShouldDetectGitPull() new GitBranch("feature/document", "origin/feature/document", false), new GitBranch("feature/other-feature", "origin/feature/other-feature", false), }); - Repository.Remotes.Should().BeEquivalentTo(); + Repository.Remotes.Should().BeEquivalentTo(new GitRemote + { + Name = "origin", + Url = "https://github.com/EvilStanleyGoldman/IOTestsRepo.git" + }); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document-2", "[None]", false), @@ -803,7 +851,7 @@ public async Task ShouldDetectGitPull() }); repositoryManagerEvents.Reset(); - WaitForNotBusy(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); } [Test] @@ -815,7 +863,7 @@ public async Task ShouldDetectGitFetch() repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents, 2); + repositoryManagerEvents.WaitForNotBusy(2); repositoryManagerListener.AssertDidNotReceiveAnyCalls(); @@ -836,7 +884,11 @@ public async Task ShouldDetectGitFetch() Repository.LocalBranches.Should().BeEquivalentTo(new[] { new GitBranch("feature/document", "origin/feature/document", false), }); - Repository.Remotes.Should().BeEquivalentTo(); + Repository.Remotes.Should().BeEquivalentTo(new GitRemote + { + Name = "origin", + Url = "https://github.com/EvilStanleyGoldman/IOTestsRepo.git" + }); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document", "[None]", false), @@ -846,7 +898,7 @@ public async Task ShouldDetectGitFetch() await RepositoryManager.Fetch("origin").StartAsAsync(); await TaskManager.Wait(); RepositoryManager.WaitForEvents(); - WaitForNotBusy(repositoryManagerEvents); + repositoryManagerEvents.WaitForNotBusy(); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); @@ -878,7 +930,11 @@ public async Task ShouldDetectGitFetch() Repository.LocalBranches.Should().BeEquivalentTo(new[] { new GitBranch("feature/document", "origin/feature/document", false), }); - Repository.Remotes.Should().BeEquivalentTo(); + Repository.Remotes.Should().BeEquivalentTo(new GitRemote + { + Name = "origin", + Url = "https://github.com/EvilStanleyGoldman/IOTestsRepo.git" + }); Repository.RemoteBranches.Should().BeEquivalentTo(new[] { new GitBranch("origin/master", "[None]", false), new GitBranch("origin/feature/document", "[None]", false), @@ -887,21 +943,5 @@ public async Task ShouldDetectGitFetch() new GitBranch("origin/feature/other-feature", "[None]", false), }); } - - private void WaitForNotBusy(RepositoryManagerEvents managerEvents, int seconds = 1) - { - managerEvents.OnIsBusy.WaitOne(TimeSpan.FromSeconds(seconds)); - managerEvents.OnIsNotBusy.WaitOne(TimeSpan.FromSeconds(seconds)); - } - - private void WaitForStatusUpdated(RepositoryManagerEvents managerEvents, int seconds = 1) - { - managerEvents.OnStatusUpdated.WaitOne(TimeSpan.FromSeconds(seconds)); - } - - private void WaitForHeadUpdated(RepositoryManagerEvents managerEvents, int seconds = 1) - { - managerEvents.OnHeadUpdated.WaitOne(TimeSpan.FromSeconds(seconds)); - } } } diff --git a/src/tests/IntegrationTests/SetUpFixture.cs b/src/tests/IntegrationTests/SetUpFixture.cs index ead5695e4..62793030c 100644 --- a/src/tests/IntegrationTests/SetUpFixture.cs +++ b/src/tests/IntegrationTests/SetUpFixture.cs @@ -14,7 +14,7 @@ public void Setup() Logging.LogAdapter = new MultipleLogAdapter( new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-integration-tests.log") - ,new ConsoleLogAdapter() + , new ConsoleLogAdapter() ); } } diff --git a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs index 6107f33ae..1f7432652 100644 --- a/src/tests/TestUtils/Events/IRepositoryManagerListener.cs +++ b/src/tests/TestUtils/Events/IRepositoryManagerListener.cs @@ -60,6 +60,22 @@ public void Reset() OnRemoteBranchRemoved.Reset(); OnGitUserLoaded.Reset(); } + + public void WaitForNotBusy(int seconds = 1) + { + OnIsBusy.WaitOne(TimeSpan.FromSeconds(seconds)); + OnIsNotBusy.WaitOne(TimeSpan.FromSeconds(seconds)); + } + + public void WaitForStatusUpdated(int seconds = 1) + { + OnStatusUpdated.WaitOne(TimeSpan.FromSeconds(seconds)); + } + + public void WaitForHeadUpdated(int seconds = 1) + { + OnHeadUpdated.WaitOne(TimeSpan.FromSeconds(seconds)); + } } static class RepositoryManagerListenerExtensions diff --git a/src/tests/UnitTests/Git/RepositoryTests.cs b/src/tests/UnitTests/Git/RepositoryTests.cs index 36ccc134b..368d4a86b 100644 --- a/src/tests/UnitTests/Git/RepositoryTests.cs +++ b/src/tests/UnitTests/Git/RepositoryTests.cs @@ -95,7 +95,7 @@ public void Repository() repositoryEvents.OnLocalBranchListChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnLocalBranchListChanged not raised"); - repositoryManager.OnRemoteBranchListUpdated += Raise.Event>>>(remoteBranchDictionary); + repositoryManager.OnRemoteBranchListUpdated += Raise.Event, Dictionary>>>(remoteDictionary, remoteBranchDictionary); repositoryEvents.OnRemoteBranchListChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnRemoteBranchListChanged not raised"); From d3f6af904f969918b3e2e17fe18fc914069406d3 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Thu, 21 Sep 2017 18:29:11 -0400 Subject: [PATCH 39/57] Making Repository return GitBranch and GitRemote instead of ConfigBranch and ConfigRemote --- src/GitHub.Api/Git/IRepository.cs | 6 +- src/GitHub.Api/Git/Repository.cs | 89 ++++++++----- .../Events/RepositoryManagerTests.cs | 126 +++++++----------- 3 files changed, 102 insertions(+), 119 deletions(-) diff --git a/src/GitHub.Api/Git/IRepository.cs b/src/GitHub.Api/Git/IRepository.cs index da9105f55..e3ebdf0ca 100644 --- a/src/GitHub.Api/Git/IRepository.cs +++ b/src/GitHub.Api/Git/IRepository.cs @@ -45,12 +45,12 @@ public interface IRepository : IEquatable /// /// Gets the current remote of the repository. /// - ConfigRemote? CurrentRemote { get; set; } + GitRemote? CurrentRemote { get; } /// /// Gets the current branch of the repository. /// - ConfigBranch? CurrentBranch { get; set; } - GitStatus CurrentStatus { get; set; } + GitBranch? CurrentBranch { get; } + GitStatus CurrentStatus { get; } IList Remotes { get; } IEnumerable LocalBranches { get; } IEnumerable RemoteBranches { get; } diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index df51b7615..2a5ba3e3e 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -49,8 +49,8 @@ public void Initialize(IRepositoryManager repositoryManager) this.repositoryManager = repositoryManager; - repositoryManager.OnCurrentBranchUpdated += branch => CurrentBranch = branch; - repositoryManager.OnCurrentRemoteUpdated += remote => CurrentRemote = remote; + repositoryManager.OnCurrentBranchUpdated += OnRepositoryManager_OnCurrentBranchUpdated; + repositoryManager.OnCurrentRemoteUpdated += OnRepositoryManager_OnCurrentRemoteUpdated; repositoryManager.OnStatusUpdated += status => CurrentStatus = status; repositoryManager.OnLocksUpdated += locks => CurrentLocks = locks; repositoryManager.OnLocalBranchListUpdated += OnRepositoryManager_OnLocalBranchListUpdated; @@ -168,6 +168,27 @@ public bool Equals(IRepository other) object.Equals(LocalPath, other.LocalPath); } + private void OnRepositoryManager_OnCurrentRemoteUpdated(ConfigRemote? remote) + { + if (!Nullable.Equals(currentRemote, remote)) + { + currentRemote = remote; + Logger.Trace("OnCurrentRemoteChanged: {0}", currentRemote.HasValue ? currentRemote.Value.ToString() : "[NULL]"); + OnCurrentRemoteChanged?.Invoke(currentRemote.HasValue ? currentRemote.Value.Name : null); + UpdateRepositoryInfo(); + } + } + + private void OnRepositoryManager_OnCurrentBranchUpdated(ConfigBranch? branch) + { + if (!Nullable.Equals(currentBranch, branch)) + { + currentBranch = branch; + Logger.Trace("OnCurrentBranchChanged: {0}", currentBranch.HasValue ? currentBranch.ToString() : "[NULL]"); + OnCurrentBranchChanged?.Invoke(currentBranch.HasValue ? currentBranch.Value.Name : null); + } + } + private void OnRepositoryManager_OnLocalBranchUpdated(string name) { if (name == currentBranch?.Name) @@ -181,10 +202,7 @@ private void OnRepositoryManager_OnRemoteBranchListUpdated(Dictionary new GitRemote { - Name = pair.Value.Name, - Url = pair.Value.Url - }).ToArray(); + Remotes = remotes.Select(pair => GetGitRemote(pair.Value)).ToArray(); remoteBranches = branches; @@ -291,58 +309,59 @@ private void RepositoryManager_OnRemoteBranchRemoved(string remote, string name) } } - public IList Remotes { get; private set; } - - public IEnumerable LocalBranches => localBranches.Values.Select(x => { + private GitBranch GetLocalGitBranch(ConfigBranch x) + { var name = x.Name; var trackingName = x.IsTracking ? x.Remote.Value.Name + "/" + name : "[None]"; var isActive = name == CurrentBranch?.Name; return new GitBranch(name, trackingName, isActive); - }); + } - public IEnumerable RemoteBranches => remoteBranches.Values.SelectMany(x => x.Values).Select(x => { + private GitBranch GetRemoteGitBranch(ConfigBranch x) + { var name = x.Remote.Value.Name + "/" + x.Name; var trackingName = "[None]"; return new GitBranch(name, trackingName, false); - }); + } - public ConfigBranch? CurrentBranch + private GitRemote GetGitRemote(ConfigRemote configRemote) { - get { return currentBranch; } - set + return new GitRemote { Name = configRemote.Name, Url = configRemote.Url }; + } + + public IList Remotes { get; private set; } + + public IEnumerable LocalBranches => localBranches.Values.Select(GetLocalGitBranch); + + public IEnumerable RemoteBranches => remoteBranches.Values.SelectMany(x => x.Values).Select(GetRemoteGitBranch); + + public GitBranch? CurrentBranch + { + get { - if (!Nullable.Equals(currentBranch, value)) + if (currentBranch != null) { - currentBranch = value; - Logger.Trace("OnCurrentBranchChanged: {0}", currentBranch.HasValue ? currentBranch.ToString() : "[NULL]"); - OnCurrentBranchChanged?.Invoke(currentBranch.HasValue ? currentBranch.Value.Name : null); + return GetLocalGitBranch(currentBranch.Value); } + + return null; } } - /// - /// Gets the current branch of the repository. - /// - public string CurrentBranchName => currentBranch?.Name; - /// - /// Gets the current remote of the repository. - /// - public ConfigRemote? CurrentRemote + public GitRemote? CurrentRemote { - get { return currentRemote; } - set + get { - if (!Nullable.Equals(currentRemote, value)) + if (currentRemote != null) { - currentRemote = value; - Logger.Trace("OnCurrentRemoteChanged: {0}", currentRemote.HasValue ? currentRemote.Value.ToString() : "[NULL]"); - OnCurrentRemoteChanged?.Invoke(currentRemote.HasValue ? currentRemote.Value.Name : null); - UpdateRepositoryInfo(); + return GetGitRemote(currentRemote.Value); } + + return null; } } @@ -370,7 +389,7 @@ public ConfigRemote? CurrentRemote public GitStatus CurrentStatus { get { return currentStatus; } - set + private set { currentStatus = value; Logger.Trace("OnStatusChanged: {0}", value.ToString()); diff --git a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs index e9636ca56..e872955db 100644 --- a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs @@ -43,9 +43,6 @@ public async Task ShouldDoNothingOnInitialize() Repository.CurrentBranchName.Should().Be("master"); Repository.CurrentBranch.HasValue.Should().BeTrue(); Repository.CurrentBranch.Value.Name.Should().Be("master"); - Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); - Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); - Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("origin"); Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); @@ -322,9 +319,6 @@ public async Task ShouldDetectBranchChange() Repository.CurrentBranchName.Should().Be("feature/document"); Repository.CurrentBranch.HasValue.Should().BeTrue(); Repository.CurrentBranch.Value.Name.Should().Be("feature/document"); - Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); - Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); - Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("origin"); Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); @@ -379,9 +373,6 @@ public async Task ShouldDetectBranchDelete() Repository.CurrentBranchName.Should().Be("master"); Repository.CurrentBranch.HasValue.Should().BeTrue(); Repository.CurrentBranch.Value.Name.Should().Be("master"); - Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); - Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); - Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("origin"); Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); @@ -436,9 +427,6 @@ public async Task ShouldDetectBranchCreate() Repository.CurrentBranchName.Should().Be("master"); Repository.CurrentBranch.HasValue.Should().BeTrue(); Repository.CurrentBranch.Value.Name.Should().Be("master"); - Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); - Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); - Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("origin"); Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); @@ -489,9 +477,6 @@ public async Task ShouldDetectBranchCreate() Repository.CurrentBranchName.Should().Be("master"); Repository.CurrentBranch.HasValue.Should().BeTrue(); Repository.CurrentBranch.Value.Name.Should().Be("master"); - Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); - Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); - Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("origin"); Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); @@ -550,9 +535,6 @@ public async Task ShouldDetectChangesToRemotes() Repository.CurrentBranchName.Should().Be("master"); Repository.CurrentBranch.HasValue.Should().BeTrue(); Repository.CurrentBranch.Value.Name.Should().Be("master"); - Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); - Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); - Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("origin"); Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); @@ -567,51 +549,51 @@ public async Task ShouldDetectChangesToRemotes() repositoryManagerListener.ClearReceivedCalls(); repositoryManagerEvents.Reset(); - await RepositoryManager.RemoteAdd("origin", "https://github.com/EvilShana/IOTestsRepo.git").StartAsAsync(); - await TaskManager.Wait(); - RepositoryManager.WaitForEvents(); - repositoryManagerEvents.WaitForNotBusy(); - repositoryManagerEvents.OnRemoteBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); - repositoryManagerEvents.OnLocalBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); - - repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); - repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); - repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); - repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); - repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); - repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); - repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); - repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); - repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); - repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); - - Repository.Name.Should().Be("IOTestsRepo"); - Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); - Repository.Owner.Should().Be("EvilStanleyGoldman"); - Repository.LocalPath.Should().Be(TestRepoMasterCleanSynchronized); - Repository.IsGitHub.Should().BeTrue(); - Repository.CurrentBranchName.Should().Be("master"); - Repository.CurrentBranch.HasValue.Should().BeTrue(); - Repository.CurrentBranch.Value.Name.Should().Be("master"); - Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); - Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); - Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); - Repository.CurrentRemote.HasValue.Should().BeTrue(); - Repository.CurrentRemote.Value.Name.Should().Be("origin"); - Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); - Repository.LocalBranches.Should().BeEquivalentTo(new[] { - new GitBranch("master", "[None]", true), - new GitBranch("feature/document", "[None]", false), - new GitBranch("feature/other-feature", "[None]", false), - }); - Repository.Remotes.Should().BeEquivalentTo(new GitRemote - { - Name = "origin", - Url = "https://github.com/EvilShana/IOTestsRepo.git" - }); - Repository.RemoteBranches.Should().BeEmpty(); +// await RepositoryManager.RemoteAdd("origin", "https://github.com/EvilShana/IOTestsRepo.git").StartAsAsync(); +// await TaskManager.Wait(); +// RepositoryManager.WaitForEvents(); +// repositoryManagerEvents.WaitForNotBusy(); +// repositoryManagerEvents.OnRemoteBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); +// repositoryManagerEvents.OnLocalBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); +// +// repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); +// repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); +// repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); +// repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); +// repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); +// repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); +// repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); +// repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); +// repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); +// repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); +// repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); +// repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); +// +// Repository.Name.Should().Be("IOTestsRepo"); +// Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); +// Repository.Owner.Should().Be("EvilStanleyGoldman"); +// Repository.LocalPath.Should().Be(TestRepoMasterCleanSynchronized); +// Repository.IsGitHub.Should().BeTrue(); +// Repository.CurrentBranchName.Should().Be("master"); +// Repository.CurrentBranch.HasValue.Should().BeTrue(); +// Repository.CurrentBranch.Value.Name.Should().Be("master"); +// Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); +// Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); +// Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); +// Repository.CurrentRemote.HasValue.Should().BeTrue(); +// Repository.CurrentRemote.Value.Name.Should().Be("origin"); +// Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); +// Repository.LocalBranches.Should().BeEquivalentTo(new[] { +// new GitBranch("master", "[None]", true), +// new GitBranch("feature/document", "[None]", false), +// new GitBranch("feature/other-feature", "[None]", false), +// }); +// Repository.Remotes.Should().BeEquivalentTo(new GitRemote +// { +// Name = "origin", +// Url = "https://github.com/EvilShana/IOTestsRepo.git" +// }); +// Repository.RemoteBranches.Should().BeEmpty(); } [Test] @@ -632,9 +614,6 @@ public async Task ShouldDetectChangesToRemotesWhenSwitchingBranches() Repository.CurrentBranchName.Should().Be("master"); Repository.CurrentBranch.HasValue.Should().BeTrue(); Repository.CurrentBranch.Value.Name.Should().Be("master"); - Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); - Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); - Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("origin"); Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); @@ -689,9 +668,6 @@ await RepositoryManager.CreateBranch("branch2", "another/master") Repository.CurrentBranchName.Should().Be("master"); Repository.CurrentBranch.HasValue.Should().BeTrue(); Repository.CurrentBranch.Value.Name.Should().Be("master"); - Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); - Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); - Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("origin"); Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); @@ -751,9 +727,6 @@ await RepositoryManager.SwitchBranch("branch2") Repository.CurrentBranchName.Should().Be("branch2"); Repository.CurrentBranch.HasValue.Should().BeTrue(); Repository.CurrentBranch.Value.Name.Should().Be("branch2"); - Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); - Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("another"); - Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://another.remote/Owner/Url.git"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("another"); Repository.CurrentRemote.Value.Url.Should().Be("https://another.remote/Owner/Url.git"); @@ -828,9 +801,6 @@ public async Task ShouldDetectGitPull() Repository.CurrentBranchName.Should().Be("master"); Repository.CurrentBranch.HasValue.Should().BeTrue(); Repository.CurrentBranch.Value.Name.Should().Be("master"); - Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); - Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); - Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("origin"); Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); @@ -875,9 +845,6 @@ public async Task ShouldDetectGitFetch() Repository.CurrentBranchName.Should().Be("master"); Repository.CurrentBranch.HasValue.Should().BeTrue(); Repository.CurrentBranch.Value.Name.Should().Be("master"); - Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); - Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); - Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("origin"); Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); @@ -921,9 +888,6 @@ public async Task ShouldDetectGitFetch() Repository.CurrentBranchName.Should().Be("master"); Repository.CurrentBranch.HasValue.Should().BeTrue(); Repository.CurrentBranch.Value.Name.Should().Be("master"); - Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); - Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); - Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("origin"); Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); From a4ceed13b36d841d96b28021484414c410d3992e Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Thu, 21 Sep 2017 18:33:41 -0400 Subject: [PATCH 40/57] Stackoverflow bufix --- src/GitHub.Api/Git/Repository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index 2a5ba3e3e..f187fb6d3 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -313,7 +313,7 @@ private GitBranch GetLocalGitBranch(ConfigBranch x) { var name = x.Name; var trackingName = x.IsTracking ? x.Remote.Value.Name + "/" + name : "[None]"; - var isActive = name == CurrentBranch?.Name; + var isActive = name == currentBranch?.Name; return new GitBranch(name, trackingName, isActive); } From c81e885f2653fc7b74917d2781476f3f0bc27e95 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Thu, 21 Sep 2017 18:51:16 -0400 Subject: [PATCH 41/57] Fixing the update after removing a remote when it is active --- src/GitHub.Api/Git/RepositoryManager.cs | 2 +- .../Events/RepositoryManagerTests.cs | 147 +++++++++++------- 2 files changed, 88 insertions(+), 61 deletions(-) diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index 44d50eb4d..c70d111fa 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -159,7 +159,6 @@ public void Start() Logger.Trace("Start"); UpdateConfigData(); - UpdateHead(); LoadGitUser(); watcher.Start(); } @@ -486,6 +485,7 @@ private void UpdateConfigData(bool resetConfig = false) LoadBranchesFromConfig(); LoadRemotesFromConfig(); + UpdateHead(); } private void LoadBranchesFromConfig() diff --git a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs index e872955db..672b092d3 100644 --- a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs @@ -506,19 +506,53 @@ public async Task ShouldDetectChangesToRemotes() var repositoryManagerListener = Substitute.For(); repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); - + + RepositoryManager.WaitForEvents(); + repositoryManagerEvents.WaitForNotBusy(2); + + repositoryManagerListener.AssertDidNotReceiveAnyCalls(); + + Repository.Name.Should().Be("IOTestsRepo"); + Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.Owner.Should().Be("EvilStanleyGoldman"); + Repository.LocalPath.Should().Be(TestRepoMasterCleanSynchronized); + Repository.IsGitHub.Should().BeTrue(); + Repository.CurrentBranchName.Should().Be("master"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("master"); + Repository.CurrentRemote.HasValue.Should().BeTrue(); + Repository.CurrentRemote.Value.Name.Should().Be("origin"); + Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.LocalBranches.Should().BeEquivalentTo(new[] { + new GitBranch("master", "origin/master", true), + new GitBranch("feature/document", "origin/feature/document", false), + new GitBranch("feature/other-feature", "origin/feature/other-feature", false), + }); + Repository.Remotes.Should().BeEquivalentTo(new GitRemote + { + Name = "origin", + Url = "https://github.com/EvilStanleyGoldman/IOTestsRepo.git" + }); + Repository.RemoteBranches.Should().BeEquivalentTo(new[] { + new GitBranch("origin/master", "[None]", false), + new GitBranch("origin/feature/document-2", "[None]", false), + new GitBranch("origin/feature/other-feature", "[None]", false), + }); + await RepositoryManager.RemoteRemove("origin").StartAsAsync(); await TaskManager.Wait(); + RepositoryManager.WaitForEvents(); repositoryManagerEvents.WaitForNotBusy(); + repositoryManagerEvents.OnRemoteBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); repositoryManagerEvents.OnLocalBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); + repositoryManagerListener.Received().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.Received().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); @@ -527,9 +561,44 @@ public async Task ShouldDetectChangesToRemotes() repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); repositoryManagerListener.Received().OnRemoteBranchRemoved(Args.String, Args.String); + Repository.Name.Should().Be("IOTestsRepo_master_clean_sync"); + Repository.CloneUrl.Should().BeNull(); + Repository.Owner.Should().BeNull(); + Repository.LocalPath.Should().Be(TestRepoMasterCleanSynchronized); + Repository.IsGitHub.Should().BeFalse(); + Repository.CurrentBranchName.Should().Be("master"); + Repository.CurrentBranch.HasValue.Should().BeTrue(); + Repository.CurrentBranch.Value.Name.Should().Be("master"); + Repository.CurrentRemote.HasValue.Should().BeFalse(); + Repository.Remotes.Should().BeEquivalentTo(); + Repository.RemoteBranches.Should().BeEmpty(); + + repositoryManagerListener.ClearReceivedCalls(); + repositoryManagerEvents.Reset(); + + await RepositoryManager.RemoteAdd("origin", "https://github.com/EvilShana/IOTestsRepo.git").StartAsAsync(); + await TaskManager.Wait(); + RepositoryManager.WaitForEvents(); + repositoryManagerEvents.WaitForNotBusy(); + repositoryManagerEvents.OnRemoteBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); + repositoryManagerEvents.OnLocalBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); + + repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); + repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); + repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); + repositoryManagerListener.Received().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.Received().OnCurrentRemoteUpdated(Arg.Any()); + repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); + repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); + repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); + repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); + repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); + Repository.Name.Should().Be("IOTestsRepo"); - Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); - Repository.Owner.Should().Be("EvilStanleyGoldman"); + Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilShana/IOTestsRepo.git"); + Repository.Owner.Should().Be("EvilShana"); Repository.LocalPath.Should().Be(TestRepoMasterCleanSynchronized); Repository.IsGitHub.Should().BeTrue(); Repository.CurrentBranchName.Should().Be("master"); @@ -537,75 +606,33 @@ public async Task ShouldDetectChangesToRemotes() Repository.CurrentBranch.Value.Name.Should().Be("master"); Repository.CurrentRemote.HasValue.Should().BeTrue(); Repository.CurrentRemote.Value.Name.Should().Be("origin"); - Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); + Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilShana/IOTestsRepo.git"); Repository.LocalBranches.Should().BeEquivalentTo(new[] { new GitBranch("master", "[None]", true), new GitBranch("feature/document", "[None]", false), new GitBranch("feature/other-feature", "[None]", false), }); - Repository.Remotes.Should().BeEquivalentTo(); + Repository.Remotes.Should().BeEquivalentTo(new GitRemote + { + Name = "origin", + Url = "https://github.com/EvilShana/IOTestsRepo.git" + }); Repository.RemoteBranches.Should().BeEmpty(); - - repositoryManagerListener.ClearReceivedCalls(); - repositoryManagerEvents.Reset(); - -// await RepositoryManager.RemoteAdd("origin", "https://github.com/EvilShana/IOTestsRepo.git").StartAsAsync(); -// await TaskManager.Wait(); -// RepositoryManager.WaitForEvents(); -// repositoryManagerEvents.WaitForNotBusy(); -// repositoryManagerEvents.OnRemoteBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); -// repositoryManagerEvents.OnLocalBranchListUpdated.WaitOne(TimeSpan.FromSeconds(1)); -// -// repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); -// repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); -// repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); -// repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); -// repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); -// repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); -// repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); -// repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); -// repositoryManagerListener.DidNotReceive().OnLocalBranchAdded(Args.String); -// repositoryManagerListener.DidNotReceive().OnLocalBranchRemoved(Args.String); -// repositoryManagerListener.DidNotReceive().OnRemoteBranchAdded(Args.String, Args.String); -// repositoryManagerListener.DidNotReceive().OnRemoteBranchRemoved(Args.String, Args.String); -// -// Repository.Name.Should().Be("IOTestsRepo"); -// Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); -// Repository.Owner.Should().Be("EvilStanleyGoldman"); -// Repository.LocalPath.Should().Be(TestRepoMasterCleanSynchronized); -// Repository.IsGitHub.Should().BeTrue(); -// Repository.CurrentBranchName.Should().Be("master"); -// Repository.CurrentBranch.HasValue.Should().BeTrue(); -// Repository.CurrentBranch.Value.Name.Should().Be("master"); -// Repository.CurrentBranch.Value.Remote.HasValue.Should().BeTrue(); -// Repository.CurrentBranch.Value.Remote.Value.Name.Should().Be("origin"); -// Repository.CurrentBranch.Value.Remote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); -// Repository.CurrentRemote.HasValue.Should().BeTrue(); -// Repository.CurrentRemote.Value.Name.Should().Be("origin"); -// Repository.CurrentRemote.Value.Url.Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); -// Repository.LocalBranches.Should().BeEquivalentTo(new[] { -// new GitBranch("master", "[None]", true), -// new GitBranch("feature/document", "[None]", false), -// new GitBranch("feature/other-feature", "[None]", false), -// }); -// Repository.Remotes.Should().BeEquivalentTo(new GitRemote -// { -// Name = "origin", -// Url = "https://github.com/EvilShana/IOTestsRepo.git" -// }); -// Repository.RemoteBranches.Should().BeEmpty(); } [Test] public async Task ShouldDetectChangesToRemotesWhenSwitchingBranches() { - var expectedCloneUrl = "https://github.com/EvilStanleyGoldman/IOTestsRepo.git"; - await Initialize(TestRepoMasterTwoRemotes); var repositoryManagerListener = Substitute.For(); repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents); + RepositoryManager.WaitForEvents(); + repositoryManagerEvents.WaitForNotBusy(2); + + repositoryManagerListener.AssertDidNotReceiveAnyCalls(); + Repository.Name.Should().Be("IOTestsRepo"); Repository.CloneUrl.ToString().Should().Be("https://github.com/EvilStanleyGoldman/IOTestsRepo.git"); Repository.Owner.Should().Be("EvilStanleyGoldman"); @@ -650,8 +677,8 @@ await RepositoryManager.CreateBranch("branch2", "another/master") repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); + repositoryManagerListener.Received().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.Received().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); From de434cd746ccf55e8b0a75ea6f7dceaa86363388 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Thu, 21 Sep 2017 18:52:41 -0400 Subject: [PATCH 42/57] Removing unintentional change --- GitHub.Unity.sln.DotSettings | 1 - 1 file changed, 1 deletion(-) diff --git a/GitHub.Unity.sln.DotSettings b/GitHub.Unity.sln.DotSettings index d4374a413..ded507d07 100644 --- a/GitHub.Unity.sln.DotSettings +++ b/GitHub.Unity.sln.DotSettings @@ -342,7 +342,6 @@ True True True - True False x64 \ No newline at end of file From 1e83fe380014763d993ddc2bc2a63e5fa2447238 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 22 Sep 2017 07:06:37 -0400 Subject: [PATCH 43/57] Fixing integration test --- src/tests/IntegrationTests/Events/RepositoryManagerTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs index 672b092d3..3e943d875 100644 --- a/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs +++ b/src/tests/IntegrationTests/Events/RepositoryManagerTests.cs @@ -355,8 +355,8 @@ public async Task ShouldDetectBranchDelete() repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool); repositoryManagerListener.DidNotReceive().OnStatusUpdated(Args.GitStatus); repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock); - repositoryManagerListener.DidNotReceive().OnCurrentBranchUpdated(Arg.Any()); - repositoryManagerListener.DidNotReceive().OnCurrentRemoteUpdated(Arg.Any()); + repositoryManagerListener.Received().OnCurrentBranchUpdated(Arg.Any()); + repositoryManagerListener.Received().OnCurrentRemoteUpdated(Arg.Any()); repositoryManagerListener.Received().OnLocalBranchListUpdated(Arg.Any>()); repositoryManagerListener.Received().OnRemoteBranchListUpdated(Arg.Any>(), Arg.Any>>()); repositoryManagerListener.DidNotReceive().OnLocalBranchUpdated(Args.String); From 6e778123e899d7fa62a7173137468d32f70fca68 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 22 Sep 2017 07:07:59 -0400 Subject: [PATCH 44/57] Commenting out ConsoleLogAdapter in SetUpFixture --- src/tests/IntegrationTests/SetUpFixture.cs | 2 +- src/tests/UnitTests/SetUpFixture.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/IntegrationTests/SetUpFixture.cs b/src/tests/IntegrationTests/SetUpFixture.cs index 62793030c..21c14f375 100644 --- a/src/tests/IntegrationTests/SetUpFixture.cs +++ b/src/tests/IntegrationTests/SetUpFixture.cs @@ -14,7 +14,7 @@ public void Setup() Logging.LogAdapter = new MultipleLogAdapter( new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-integration-tests.log") - , new ConsoleLogAdapter() + //, new ConsoleLogAdapter() ); } } diff --git a/src/tests/UnitTests/SetUpFixture.cs b/src/tests/UnitTests/SetUpFixture.cs index a716ab14c..8b683ff0e 100644 --- a/src/tests/UnitTests/SetUpFixture.cs +++ b/src/tests/UnitTests/SetUpFixture.cs @@ -14,7 +14,7 @@ public void SetUp() Logging.LogAdapter = new MultipleLogAdapter( new FileLogAdapter($"..\\{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}-unit-tests.log") - , new ConsoleLogAdapter() + //, new ConsoleLogAdapter() ); } } From 2238a807cc7bc20a730d5c08aa5ceefcc4dacb03 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Fri, 22 Sep 2017 14:03:18 -0400 Subject: [PATCH 45/57] Fixing branch selection when not named in config --- src/GitHub.Api/Git/RepositoryManager.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index c70d111fa..e3892806a 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -346,6 +346,7 @@ private void SetupWatcher() private void UpdateHead() { var head = repositoryPaths.DotGitHead.ReadAllLines().FirstOrDefault(); + Logger.Trace("UpdateHead: {0}", head ?? "[NULL]"); UpdateCurrentBranchAndRemote(head); } @@ -428,6 +429,11 @@ private void UpdateCurrentBranchAndRemote(string head) { var branchName = head.Substring(head.IndexOf("refs/heads/") + "refs/heads/".Length); branch = config.GetBranch(branchName); + + if (!branch.HasValue) + { + branch = new ConfigBranch { Name = branchName }; + } } var defaultRemote = "origin"; @@ -452,7 +458,10 @@ private void UpdateCurrentBranchAndRemote(string head) } } + Logger.Trace("OnCurrentBranchUpdated: {0}", branch.HasValue ? branch.Value.ToString() : "[NULL]"); OnCurrentBranchUpdated?.Invoke(branch); + + Logger.Trace("OnCurrentRemoteUpdated: {0}", remote.HasValue ? remote.Value.ToString() : "[NULL]"); OnCurrentRemoteUpdated?.Invoke(remote); } @@ -476,13 +485,13 @@ private void Watcher_OnLocalBranchChanged(string name) private void UpdateConfigData(bool resetConfig = false) { + Logger.Trace("UpdateConfigData reset:{0}", resetConfig); + if (resetConfig) { config.Reset(); } - Logger.Trace("RefreshConfigData"); - LoadBranchesFromConfig(); LoadRemotesFromConfig(); UpdateHead(); @@ -494,6 +503,8 @@ private void LoadBranchesFromConfig() var branches = new Dictionary(); LoadBranchesFromConfig(branches, repositoryPaths.BranchesPath, config.GetBranches().Where(x => x.IsTracking), ""); + + Logger.Trace("OnLocalBranchListUpdated {0} branches", branches.Count); OnLocalBranchListUpdated?.Invoke(branches); } @@ -542,6 +553,7 @@ private void LoadRemotesFromConfig() } } + Logger.Trace("OnRemoteBranchListUpdated {0} remotes", remotes.Count); OnRemoteBranchListUpdated?.Invoke(remotes, remoteBranches); } From 955cb707b41b7c77c55a9c7c95ca4365a973c49a Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 10 Oct 2017 16:07:46 -0400 Subject: [PATCH 46/57] Updating branches after enabled --- .../Editor/GitHub.Unity/UI/BranchesView.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs index 9d12b5ab5..ab4ae2408 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs @@ -44,6 +44,7 @@ class BranchesView : Subview [NonSerialized] private BranchTreeNode newNodeSelection; [NonSerialized] private BranchesMode targetMode; [NonSerialized] private bool favoritesHasChanged; + [NonSerialized] private bool branchesHasChanged; [SerializeField] private BranchTreeNode activeBranchNode; [SerializeField] private BranchTreeNode localRoot; @@ -65,6 +66,7 @@ public override void OnEnable() base.OnEnable(); AttachHandlers(Repository); favoritesHasChanged = true; + branchesHasChanged = true; } public override void OnDisable() @@ -86,6 +88,12 @@ private void MaybeUpdateData() favoritesList = Manager.LocalSettings.Get(FavoritesSetting, new List()); favoritesHasChanged = false; } + + if (branchesHasChanged) + { + RunRefreshEmbeddedOnMainThread(); + branchesHasChanged = false; + } } public override void OnRepositoryChanged(IRepository oldRepository) @@ -114,22 +122,15 @@ private void DetachHandlers(IRepository repository) repository.OnCurrentRemoteChanged -= HandleRepositoryBranchChangeEvent; } - private void RunRefreshEmbeddedOnMainThread() - { - new ActionTask(TaskManager.Token, _ => RefreshEmbedded()) - .ScheduleUI(TaskManager); - } - private void HandleRepositoryBranchChangeEvent(string obj) { RunRefreshEmbeddedOnMainThread(); } - public override void Refresh() + private void RunRefreshEmbeddedOnMainThread() { - base.Refresh(); - - RefreshEmbedded(); + new ActionTask(TaskManager.Token, _ => RefreshEmbedded()) + .ScheduleUI(TaskManager); } public void RefreshEmbedded() @@ -297,9 +298,9 @@ private void OnLocalBranchesUpdate(IEnumerable list) newLocalBranches = new List(list); } - private void OnRemoteBranchesUpdate(IEnumerable list) + private void OnRemoteBranchesUpdate(IEnumerable newRemoteBranches) { - BuildTree(newLocalBranches, list); + BuildTree(newLocalBranches, newRemoteBranches); newLocalBranches.Clear(); } From c09e0818bf3750a5f07969b29e5694b81d4e2af1 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 10 Oct 2017 16:33:21 -0400 Subject: [PATCH 47/57] Renaming method --- .../Assets/Editor/GitHub.Unity/UI/BranchesView.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs index ab4ae2408..f53b89230 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs @@ -91,7 +91,7 @@ private void MaybeUpdateData() if (branchesHasChanged) { - RunRefreshEmbeddedOnMainThread(); + RunUpdateBranchesOnMainThread(); branchesHasChanged = false; } } @@ -108,7 +108,7 @@ private void AttachHandlers(IRepository repository) if (repository == null) return; - repository.OnLocalBranchListChanged += RunRefreshEmbeddedOnMainThread; + repository.OnLocalBranchListChanged += RunUpdateBranchesOnMainThread; repository.OnCurrentBranchChanged += HandleRepositoryBranchChangeEvent; repository.OnCurrentRemoteChanged += HandleRepositoryBranchChangeEvent; } @@ -117,23 +117,23 @@ private void DetachHandlers(IRepository repository) { if (repository == null) return; - repository.OnLocalBranchListChanged -= RunRefreshEmbeddedOnMainThread; + repository.OnLocalBranchListChanged -= RunUpdateBranchesOnMainThread; repository.OnCurrentBranchChanged -= HandleRepositoryBranchChangeEvent; repository.OnCurrentRemoteChanged -= HandleRepositoryBranchChangeEvent; } private void HandleRepositoryBranchChangeEvent(string obj) { - RunRefreshEmbeddedOnMainThread(); + RunUpdateBranchesOnMainThread(); } - private void RunRefreshEmbeddedOnMainThread() + private void RunUpdateBranchesOnMainThread() { - new ActionTask(TaskManager.Token, _ => RefreshEmbedded()) + new ActionTask(TaskManager.Token, _ => UpdateBranches()) .ScheduleUI(TaskManager); } - public void RefreshEmbedded() + public void UpdateBranches() { if (Repository == null) return; From cead15a7d9b8f06ff96622955f1fb558e650a3ac Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Tue, 10 Oct 2017 18:22:03 -0400 Subject: [PATCH 48/57] Fixing the reactions to events in the UI --- .../Editor/GitHub.Unity/UI/BranchesView.cs | 21 ++-- .../Editor/GitHub.Unity/UI/HistoryView.cs | 109 +++++++++--------- 2 files changed, 66 insertions(+), 64 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs index f53b89230..5c3966deb 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs @@ -44,7 +44,6 @@ class BranchesView : Subview [NonSerialized] private BranchTreeNode newNodeSelection; [NonSerialized] private BranchesMode targetMode; [NonSerialized] private bool favoritesHasChanged; - [NonSerialized] private bool branchesHasChanged; [SerializeField] private BranchTreeNode activeBranchNode; [SerializeField] private BranchTreeNode localRoot; @@ -66,7 +65,7 @@ public override void OnEnable() base.OnEnable(); AttachHandlers(Repository); favoritesHasChanged = true; - branchesHasChanged = true; + Refresh(); } public override void OnDisable() @@ -88,12 +87,6 @@ private void MaybeUpdateData() favoritesList = Manager.LocalSettings.Get(FavoritesSetting, new List()); favoritesHasChanged = false; } - - if (branchesHasChanged) - { - RunUpdateBranchesOnMainThread(); - branchesHasChanged = false; - } } public override void OnRepositoryChanged(IRepository oldRepository) @@ -127,6 +120,12 @@ private void HandleRepositoryBranchChangeEvent(string obj) RunUpdateBranchesOnMainThread(); } + public override void Refresh() + { + base.Refresh(); + UpdateBranches(); + } + private void RunUpdateBranchesOnMainThread() { new ActionTask(TaskManager.Token, _ => UpdateBranches()) @@ -537,7 +536,7 @@ private void OnButtonBarGUI() .FinallyInUI((success, e) => { if (success) { - Refresh(); + Redraw(); } else { @@ -658,7 +657,7 @@ private void OnTreeNodeGUI(BranchTreeNode node) { if (success) { - Refresh(); + Redraw(); } else { @@ -694,7 +693,7 @@ private void OnTreeNodeGUI(BranchTreeNode node) { if (success) { - Refresh(); + Redraw(); } else { diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs index c830c39c1..85eab46f4 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs @@ -43,7 +43,7 @@ class HistoryView : Subview [NonSerialized] private float scrollOffset; [NonSerialized] private DateTimeOffset scrollTime = DateTimeOffset.Now; [NonSerialized] private int selectionIndex; - [NonSerialized] private bool updated = true; + [NonSerialized] private bool logHasChanged; [NonSerialized] private bool useScrollTime; [NonSerialized] private bool isBusy; @@ -74,6 +74,7 @@ public override void OnEnable() { base.OnEnable(); AttachHandlers(Repository); + UpdateLog(); } public override void OnDisable() @@ -94,13 +95,6 @@ public override void OnRepositoryChanged(IRepository oldRepository) DetachHandlers(oldRepository); AttachHandlers(Repository); - Refresh(); - } - - public override void Refresh() - { - base.Refresh(); - RefreshLog(); } public override void OnSelectionChange() @@ -108,7 +102,6 @@ public override void OnSelectionChange() if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(Selection.activeObject))) { historyTarget = Selection.activeObject; - Refresh(); } } @@ -123,8 +116,8 @@ private void AttachHandlers(IRepository repository) return; repository.OnLocalBranchChanged += Refresh; repository.OnStatusChanged += UpdateStatusOnMainThread; - repository.OnCurrentBranchChanged += s => Refresh(); - repository.OnCurrentRemoteChanged += s => Refresh(); + repository.OnCurrentBranchChanged += Repository_OnCurrentBranchChanged(); + repository.OnCurrentRemoteChanged += Repository_OnCurrentRemoteChanged(); } private void DetachHandlers(IRepository repository) @@ -133,8 +126,18 @@ private void DetachHandlers(IRepository repository) return; repository.OnLocalBranchChanged -= Refresh; repository.OnStatusChanged -= UpdateStatusOnMainThread; - repository.OnCurrentBranchChanged -= s => Refresh(); - repository.OnCurrentRemoteChanged -= s => Refresh(); + repository.OnCurrentBranchChanged -= Repository_OnCurrentBranchChanged(); + repository.OnCurrentRemoteChanged -= Repository_OnCurrentRemoteChanged(); + } + + private Action Repository_OnCurrentRemoteChanged() + { + return s => Refresh(); + } + + private Action Repository_OnCurrentBranchChanged() + { + return s => Refresh(); } private void UpdateStatusOnMainThread(GitStatus status) @@ -149,68 +152,68 @@ private void UpdateStatus(GitStatus status) statusBehind = status.Behind; } - private void RefreshLog() + private void UpdateLog() { if (Repository != null) { Repository.Log().ThenInUI((success, log) => { - if (success) OnLogUpdate(log); + if (success) + { + Logger.Trace("OnLogUpdate"); + GitLogCache.Instance.Log = log; + logHasChanged = true; + Redraw(); + } }).Start(); } } - private void OnLogUpdate(List entries) - { - Logger.Trace("OnLogUpdate"); - GitLogCache.Instance.Log = entries; - updated = true; - Redraw(); - } - private void MaybeUpdateData() { isPublished = Repository != null && Repository.CurrentRemote.HasValue; currentRemote = isPublished ? Repository.CurrentRemote.Value.Name : "placeholder"; - if (!updated) - return; - updated = false; + if (logHasChanged) + { + logHasChanged = false; - history = GitLogCache.Instance.Log; + history = GitLogCache.Instance.Log; - if (history.Any()) - { - // Make sure that scroll as much as possible focuses the same time period in the new entry list - if (useScrollTime) + if (history.Any()) { - var closestIndex = -1; - double closestDifference = Mathf.Infinity; - for (var index = 0; index < history.Count; ++index) + // Make sure that scroll as much as possible focuses the same time period in the new entry list + if (useScrollTime) { - var diff = Math.Abs((history[index].Time - scrollTime).TotalSeconds); - if (diff < closestDifference) + var closestIndex = -1; + double closestDifference = Mathf.Infinity; + for (var index = 0; index < history.Count; ++index) { - closestDifference = diff; - closestIndex = index; + var diff = Math.Abs((history[index].Time - scrollTime).TotalSeconds); + if (diff < closestDifference) + { + closestDifference = diff; + closestIndex = index; + } } + + ScrollTo(closestIndex, scrollOffset); } - ScrollTo(closestIndex, scrollOffset); + CullHistory(); } - CullHistory(); - } - - // Restore selection index or clear it - newSelectionIndex = -1; - if (!string.IsNullOrEmpty(selectionID)) - { - selectionIndex = - Enumerable.Range(1, history.Count + 1).FirstOrDefault(index => history[index - 1].CommitID.Equals(selectionID)) - 1; - - if (selectionIndex < 0) + // Restore selection index or clear it + newSelectionIndex = -1; + if (!string.IsNullOrEmpty(selectionID)) { - selectionID = string.Empty; + selectionIndex = Enumerable.Range(1, history.Count + 1) + .FirstOrDefault( + index => history[index - 1].CommitID.Equals(selectionID)) - 1; + + if (selectionIndex < 0) + { + selectionID = string.Empty; + } } } } @@ -305,7 +308,7 @@ public void OnEmbeddedGUI() // Only update time scroll var lastScroll = scroll; scroll = GUILayout.BeginScrollView(scroll); - if (lastScroll != scroll && !updated) + if (lastScroll != scroll && !logHasChanged) { scrollTime = history[historyStartIndex].Time; scrollOffset = scroll.y - historyStartIndex * EntryHeight; @@ -411,7 +414,7 @@ public void OnEmbeddedGUI() if (Event.current.type == EventType.Repaint) { CullHistory(); - updated = false; + logHasChanged = false; if (newSelectionIndex >= 0 || newSelectionIndex == -2) { From 185573c0e05661470cd69e41707d296b131b13b5 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Wed, 11 Oct 2017 08:00:40 -0400 Subject: [PATCH 49/57] Simplying branch updating --- .../Assets/Editor/GitHub.Unity/UI/BranchesView.cs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs index 5c3966deb..8c00a6f63 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs @@ -40,7 +40,6 @@ class BranchesView : Subview [NonSerialized] private List favorites = new List(); [NonSerialized] private int listID = -1; - [NonSerialized] private List newLocalBranches; [NonSerialized] private BranchTreeNode newNodeSelection; [NonSerialized] private BranchesMode targetMode; [NonSerialized] private bool favoritesHasChanged; @@ -137,8 +136,7 @@ public void UpdateBranches() if (Repository == null) return; - OnLocalBranchesUpdate(Repository.LocalBranches); - OnRemoteBranchesUpdate(Repository.RemoteBranches); + BuildTree(Repository.LocalBranches, Repository.RemoteBranches); } public override void OnGUI() @@ -292,17 +290,6 @@ private bool IsFavorite(string branchName) return !String.IsNullOrEmpty(branchName) && favoritesList.Contains(branchName); } - private void OnLocalBranchesUpdate(IEnumerable list) - { - newLocalBranches = new List(list); - } - - private void OnRemoteBranchesUpdate(IEnumerable newRemoteBranches) - { - BuildTree(newLocalBranches, newRemoteBranches); - newLocalBranches.Clear(); - } - private void BuildTree(IEnumerable local, IEnumerable remote) { //Clear the selected node From b6959c7fd710b58a7c2ea8c0bdea423c2daa0c08 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Wed, 11 Oct 2017 09:51:36 -0400 Subject: [PATCH 50/57] Putting UpdateLog back in Refresh Method; Removing from OnUpdated --- .../Assets/Editor/GitHub.Unity/UI/HistoryView.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs index 85eab46f4..f4b78d114 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs @@ -74,7 +74,6 @@ public override void OnEnable() { base.OnEnable(); AttachHandlers(Repository); - UpdateLog(); } public override void OnDisable() @@ -110,6 +109,12 @@ public override void OnGUI() OnEmbeddedGUI(); } + public override void Refresh() + { + base.Refresh(); + UpdateLog(); + } + private void AttachHandlers(IRepository repository) { if (repository == null) From b3639d8cdf3336a1f122896f293196c4b7302039 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Wed, 11 Oct 2017 11:12:02 -0400 Subject: [PATCH 51/57] Renaming methods --- src/GitHub.Api/Git/Repository.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index f187fb6d3..bfeb7f7cb 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -49,13 +49,13 @@ public void Initialize(IRepositoryManager repositoryManager) this.repositoryManager = repositoryManager; - repositoryManager.OnCurrentBranchUpdated += OnRepositoryManager_OnCurrentBranchUpdated; - repositoryManager.OnCurrentRemoteUpdated += OnRepositoryManager_OnCurrentRemoteUpdated; + repositoryManager.OnCurrentBranchUpdated += RepositoryManager_OnCurrentBranchUpdated; + repositoryManager.OnCurrentRemoteUpdated += RepositoryManager_OnCurrentRemoteUpdated; repositoryManager.OnStatusUpdated += status => CurrentStatus = status; repositoryManager.OnLocksUpdated += locks => CurrentLocks = locks; - repositoryManager.OnLocalBranchListUpdated += OnRepositoryManager_OnLocalBranchListUpdated; - repositoryManager.OnRemoteBranchListUpdated += OnRepositoryManager_OnRemoteBranchListUpdated; - repositoryManager.OnLocalBranchUpdated += OnRepositoryManager_OnLocalBranchUpdated; + repositoryManager.OnLocalBranchListUpdated += RepositoryManager_OnLocalBranchListUpdated; + repositoryManager.OnRemoteBranchListUpdated += RepositoryManager_OnRemoteBranchListUpdated; + repositoryManager.OnLocalBranchUpdated += RepositoryManager_OnLocalBranchUpdated; repositoryManager.OnLocalBranchAdded += RepositoryManager_OnLocalBranchAdded; repositoryManager.OnLocalBranchRemoved += RepositoryManager_OnLocalBranchRemoved; repositoryManager.OnRemoteBranchAdded += RepositoryManager_OnRemoteBranchAdded; @@ -168,7 +168,7 @@ public bool Equals(IRepository other) object.Equals(LocalPath, other.LocalPath); } - private void OnRepositoryManager_OnCurrentRemoteUpdated(ConfigRemote? remote) + private void RepositoryManager_OnCurrentRemoteUpdated(ConfigRemote? remote) { if (!Nullable.Equals(currentRemote, remote)) { @@ -179,7 +179,7 @@ private void OnRepositoryManager_OnCurrentRemoteUpdated(ConfigRemote? remote) } } - private void OnRepositoryManager_OnCurrentBranchUpdated(ConfigBranch? branch) + private void RepositoryManager_OnCurrentBranchUpdated(ConfigBranch? branch) { if (!Nullable.Equals(currentBranch, branch)) { @@ -189,7 +189,7 @@ private void OnRepositoryManager_OnCurrentBranchUpdated(ConfigBranch? branch) } } - private void OnRepositoryManager_OnLocalBranchUpdated(string name) + private void RepositoryManager_OnLocalBranchUpdated(string name) { if (name == currentBranch?.Name) { @@ -198,7 +198,7 @@ private void OnRepositoryManager_OnLocalBranchUpdated(string name) } } - private void OnRepositoryManager_OnRemoteBranchListUpdated(Dictionary updatedRemotes, Dictionary> branches) + private void RepositoryManager_OnRemoteBranchListUpdated(Dictionary updatedRemotes, Dictionary> branches) { remotes = updatedRemotes; @@ -210,7 +210,7 @@ private void OnRepositoryManager_OnRemoteBranchListUpdated(Dictionary branches) + private void RepositoryManager_OnLocalBranchListUpdated(Dictionary branches) { localBranches = branches; From b06a73748c062f32ca83beecdd0ac5b476aa6bd5 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Wed, 11 Oct 2017 11:40:48 -0400 Subject: [PATCH 52/57] Moving UpdateLog functionality to Window --- src/GitHub.Api/Git/Repository.cs | 12 ++++++ .../Editor/GitHub.Unity/UI/HistoryView.cs | 39 +------------------ .../Assets/Editor/GitHub.Unity/UI/Window.cs | 33 ++++++++++++++++ 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index bfeb7f7cb..cfce703b7 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -173,8 +173,10 @@ private void RepositoryManager_OnCurrentRemoteUpdated(ConfigRemote? remote) if (!Nullable.Equals(currentRemote, remote)) { currentRemote = remote; + Logger.Trace("OnCurrentRemoteChanged: {0}", currentRemote.HasValue ? currentRemote.Value.ToString() : "[NULL]"); OnCurrentRemoteChanged?.Invoke(currentRemote.HasValue ? currentRemote.Value.Name : null); + UpdateRepositoryInfo(); } } @@ -184,6 +186,7 @@ private void RepositoryManager_OnCurrentBranchUpdated(ConfigBranch? branch) if (!Nullable.Equals(currentBranch, branch)) { currentBranch = branch; + Logger.Trace("OnCurrentBranchChanged: {0}", currentBranch.HasValue ? currentBranch.ToString() : "[NULL]"); OnCurrentBranchChanged?.Invoke(currentBranch.HasValue ? currentBranch.Value.Name : null); } @@ -193,6 +196,7 @@ private void RepositoryManager_OnLocalBranchUpdated(string name) { if (name == currentBranch?.Name) { + Logger.Trace("OnLocalBranchChanged: {0}", name); OnLocalBranchChanged?.Invoke(); Refresh(); } @@ -241,6 +245,8 @@ private void RepositoryManager_OnLocalBranchRemoved(string name) if (localBranches.ContainsKey(name)) { localBranches.Remove(name); + + Logger.Trace("OnLocalBranchListChanged"); OnLocalBranchListChanged?.Invoke(); } else @@ -259,6 +265,8 @@ private void RepositoryManager_OnLocalBranchAdded(string name) branch = new ConfigBranch { Name = name }; } localBranches.Add(name, branch.Value); + + Logger.Trace("OnLocalBranchListChanged"); OnLocalBranchListChanged?.Invoke(); } else @@ -275,6 +283,8 @@ private void RepositoryManager_OnRemoteBranchAdded(string remote, string name) if (!branchList.ContainsKey(name)) { branchList.Add(name, new ConfigBranch { Name = name, Remote = remotes[remote] }); + + Logger.Trace("OnRemoteBranchListChanged"); OnRemoteBranchListChanged?.Invoke(); } else @@ -296,6 +306,8 @@ private void RepositoryManager_OnRemoteBranchRemoved(string remote, string name) if (localBranches.ContainsKey(name)) { localBranches.Remove(name); + + Logger.Trace("OnRemoteBranchListChanged"); OnRemoteBranchListChanged?.Invoke(); } else diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs index f4b78d114..d52939b19 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs @@ -74,6 +74,7 @@ public override void OnEnable() { base.OnEnable(); AttachHandlers(Repository); + logHasChanged = true; } public override void OnDisable() @@ -109,40 +110,18 @@ public override void OnGUI() OnEmbeddedGUI(); } - public override void Refresh() - { - base.Refresh(); - UpdateLog(); - } - private void AttachHandlers(IRepository repository) { if (repository == null) return; - repository.OnLocalBranchChanged += Refresh; repository.OnStatusChanged += UpdateStatusOnMainThread; - repository.OnCurrentBranchChanged += Repository_OnCurrentBranchChanged(); - repository.OnCurrentRemoteChanged += Repository_OnCurrentRemoteChanged(); } private void DetachHandlers(IRepository repository) { if (repository == null) return; - repository.OnLocalBranchChanged -= Refresh; repository.OnStatusChanged -= UpdateStatusOnMainThread; - repository.OnCurrentBranchChanged -= Repository_OnCurrentBranchChanged(); - repository.OnCurrentRemoteChanged -= Repository_OnCurrentRemoteChanged(); - } - - private Action Repository_OnCurrentRemoteChanged() - { - return s => Refresh(); - } - - private Action Repository_OnCurrentBranchChanged() - { - return s => Refresh(); } private void UpdateStatusOnMainThread(GitStatus status) @@ -157,22 +136,6 @@ private void UpdateStatus(GitStatus status) statusBehind = status.Behind; } - private void UpdateLog() - { - if (Repository != null) - { - Repository.Log().ThenInUI((success, log) => { - if (success) - { - Logger.Trace("OnLogUpdate"); - GitLogCache.Instance.Log = log; - logHasChanged = true; - Redraw(); - } - }).Start(); - } - } - private void MaybeUpdateData() { isPublished = Repository != null && Repository.CurrentRemote.HasValue; diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs index cf9da47f6..32508fb8a 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs @@ -144,6 +144,7 @@ public override void OnRepositoryChanged(IRepository oldRepository) if (ActiveView != null) ActiveView.OnRepositoryChanged(oldRepository); + UpdateLog(); } public override void OnSelectionChange() @@ -197,6 +198,16 @@ private void RefreshOnMainThread() new ActionTask(TaskManager.Token, Refresh) { Affinity = TaskAffinity.UI }.Start(); } + private void Repository_OnCurrentRemoteChanged(string s) + { + UpdateLog(); + } + + private void Repository_OnCurrentBranchChanged(string s) + { + UpdateLog(); + } + private bool MaybeUpdateData(out string repoRemote) { repoRemote = null; @@ -243,6 +254,8 @@ private void AttachHandlers(IRepository repository) if (repository == null) return; repository.OnRepositoryInfoChanged += RefreshOnMainThread; + repository.OnCurrentBranchChanged += Repository_OnCurrentBranchChanged; + repository.OnCurrentRemoteChanged += Repository_OnCurrentRemoteChanged; } private void DetachHandlers(IRepository repository) @@ -251,6 +264,7 @@ private void DetachHandlers(IRepository repository) return; repository.OnRepositoryInfoChanged -= RefreshOnMainThread; } + private void DoHeaderGUI() { GUILayout.BeginHorizontal(Styles.HeaderBoxStyle); @@ -393,6 +407,25 @@ private static SubTab TabButton(SubTab tab, string title, SubTab activeTab) return GUILayout.Toggle(activeTab == tab, title, EditorStyles.toolbarButton) ? tab : activeTab; } + private void UpdateLog() + { + Logger.Trace("Updating Log"); + + if (Repository != null) + { + Repository + .Log() + .ThenInUI((success, log) => { + if (success) + { + Logger.Trace("Updated Log"); + GitLogCache.Instance.Log = log; + Redraw(); + } + }).Start(); + } + } + private Subview ToView(SubTab tab) { switch (tab) From 1a65195cba930002ec97e7476fe54dc2352cc8e5 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Wed, 11 Oct 2017 12:45:16 -0400 Subject: [PATCH 53/57] Refreshing the log cache properly --- src/GitHub.Api/Git/IRepository.cs | 2 +- src/GitHub.Api/Git/Repository.cs | 6 ++-- .../Editor/GitHub.Unity/UI/HistoryView.cs | 26 ++++++++++++++++- .../Assets/Editor/GitHub.Unity/UI/Window.cs | 28 ++++++++----------- .../TestUtils/Events/IRepositoryListener.cs | 2 +- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/GitHub.Api/Git/IRepository.cs b/src/GitHub.Api/Git/IRepository.cs index e3ebdf0ca..5818a9f52 100644 --- a/src/GitHub.Api/Git/IRepository.cs +++ b/src/GitHub.Api/Git/IRepository.cs @@ -62,7 +62,7 @@ public interface IRepository : IEquatable event Action OnCurrentBranchChanged; event Action OnCurrentRemoteChanged; event Action OnLocalBranchListChanged; - event Action OnLocalBranchChanged; + event Action OnCurrentBranchUpdated; event Action> OnLocksChanged; event Action OnRepositoryInfoChanged; event Action OnRemoteBranchListChanged; diff --git a/src/GitHub.Api/Git/Repository.cs b/src/GitHub.Api/Git/Repository.cs index cfce703b7..68d53af17 100644 --- a/src/GitHub.Api/Git/Repository.cs +++ b/src/GitHub.Api/Git/Repository.cs @@ -20,7 +20,7 @@ class Repository : IEquatable, IRepository private IRepositoryManager repositoryManager; public event Action OnCurrentBranchChanged; public event Action OnCurrentRemoteChanged; - public event Action OnLocalBranchChanged; + public event Action OnCurrentBranchUpdated; public event Action OnLocalBranchListChanged; public event Action> OnLocksChanged; public event Action OnRemoteBranchListChanged; @@ -196,8 +196,8 @@ private void RepositoryManager_OnLocalBranchUpdated(string name) { if (name == currentBranch?.Name) { - Logger.Trace("OnLocalBranchChanged: {0}", name); - OnLocalBranchChanged?.Invoke(); + Logger.Trace("OnCurrentBranchUpdated: {0}", name); + OnCurrentBranchUpdated?.Invoke(); Refresh(); } } diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs index d52939b19..f5b5f2fc9 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs @@ -74,7 +74,7 @@ public override void OnEnable() { base.OnEnable(); AttachHandlers(Repository); - logHasChanged = true; + CheckLogCache(); } public override void OnDisable() @@ -110,6 +110,30 @@ public override void OnGUI() OnEmbeddedGUI(); } + public void CheckLogCache() + { + string firstItemCommitID = null; + if (history.Any()) + { + firstItemCommitID = history.First().CommitID; + } + + var cachedList = GitLogCache.Instance.Log; + + string firstCachedItemCommitID = null; + if (cachedList.Any()) + { + firstCachedItemCommitID = cachedList.First().CommitID; + } + + if (firstItemCommitID != firstCachedItemCommitID) + { + Logger.Trace("CommitID {0} != Cached CommitId {1}", firstItemCommitID ?? "[NULL]", firstCachedItemCommitID ?? "[NULL]"); + logHasChanged = true; + Redraw(); + } + } + private void AttachHandlers(IRepository repository) { if (repository == null) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs index 32508fb8a..a9bbaca1b 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs @@ -198,16 +198,6 @@ private void RefreshOnMainThread() new ActionTask(TaskManager.Token, Refresh) { Affinity = TaskAffinity.UI }.Start(); } - private void Repository_OnCurrentRemoteChanged(string s) - { - UpdateLog(); - } - - private void Repository_OnCurrentBranchChanged(string s) - { - UpdateLog(); - } - private bool MaybeUpdateData(out string repoRemote) { repoRemote = null; @@ -254,15 +244,15 @@ private void AttachHandlers(IRepository repository) if (repository == null) return; repository.OnRepositoryInfoChanged += RefreshOnMainThread; - repository.OnCurrentBranchChanged += Repository_OnCurrentBranchChanged; - repository.OnCurrentRemoteChanged += Repository_OnCurrentRemoteChanged; + repository.OnCurrentBranchUpdated += UpdateLog; } - + private void DetachHandlers(IRepository repository) { if (repository == null) return; repository.OnRepositoryInfoChanged -= RefreshOnMainThread; + repository.OnCurrentBranchUpdated -= UpdateLog; } private void DoHeaderGUI() @@ -409,18 +399,22 @@ private static SubTab TabButton(SubTab tab, string title, SubTab activeTab) private void UpdateLog() { - Logger.Trace("Updating Log"); - if (Repository != null) { + Logger.Trace("Updating Log"); + Repository .Log() - .ThenInUI((success, log) => { + .FinallyInUI((success, exception, log) => { if (success) { Logger.Trace("Updated Log"); GitLogCache.Instance.Log = log; - Redraw(); + + if (activeTab == SubTab.History) + { + HistoryView.CheckLogCache(); + } } }).Start(); } diff --git a/src/tests/TestUtils/Events/IRepositoryListener.cs b/src/tests/TestUtils/Events/IRepositoryListener.cs index 28094bf26..5a56ed4c1 100644 --- a/src/tests/TestUtils/Events/IRepositoryListener.cs +++ b/src/tests/TestUtils/Events/IRepositoryListener.cs @@ -84,7 +84,7 @@ public static void AttachListener(this IRepositoryListener listener, repositoryEvents?.OnRemoteBranchListChanged.Set(); }; - repository.OnLocalBranchChanged += () => + repository.OnCurrentBranchUpdated += () => { logger?.Debug("OnHeadChanged"); listener.OnHeadChanged(); From 12eac941d27d8a1d7ed8a6e4daee9069a74d35aa Mon Sep 17 00:00:00 2001 From: Andreia Gaita Date: Mon, 16 Oct 2017 18:05:13 +0200 Subject: [PATCH 54/57] Split event processing and process firing --- src/GitHub.Api/Events/RepositoryWatcher.cs | 180 +++++++++++++++------ 1 file changed, 128 insertions(+), 52 deletions(-) diff --git a/src/GitHub.Api/Events/RepositoryWatcher.cs b/src/GitHub.Api/Events/RepositoryWatcher.cs index 788fdff93..6f3de0ac7 100644 --- a/src/GitHub.Api/Events/RepositoryWatcher.cs +++ b/src/GitHub.Api/Events/RepositoryWatcher.cs @@ -160,14 +160,30 @@ public int CheckAndProcessEvents() return processedEventCount; } - private int ProcessEvents(Event[] fileEvents) + enum EventType + { + None, + ConfigChanged, + HeadChanged, + RepositoryChanged, + IndexChanged, + RemoteBranchDeleted, + RemoteBranchCreated, + RemoteBranchChanged, + LocalBranchDeleted, + LocalBranchCreated, + LocalBranchChanged + } + + class EventData { - var eventsProcessed = 0; - var configChanged = false; - var headChanged = false; - var repositoryChanged = false; - var indexChanged = false; + public string Origin; + public string Branch; + } + private int ProcessEvents(Event[] fileEvents) + { + Dictionary> events = new Dictionary>(); foreach (var fileEvent in fileEvents) { if (!running) @@ -195,29 +211,17 @@ private int ProcessEvents(Event[] fileEvents) // handling events in .git/* if (fileA.IsChildOf(paths.DotGitPath)) { - if (!configChanged && fileA.Equals(paths.DotGitConfig)) + if (!events.ContainsKey(EventType.ConfigChanged) && fileA.Equals(paths.DotGitConfig)) { - configChanged = true; - - Logger.Trace("ConfigChanged"); - ConfigChanged?.Invoke(); - eventsProcessed++; + events.Add(EventType.ConfigChanged, null); } - else if (!headChanged && fileA.Equals(paths.DotGitHead)) + else if (!events.ContainsKey(EventType.HeadChanged) && fileA.Equals(paths.DotGitHead)) { - headChanged = true; - - Logger.Trace("HeadChanged"); - HeadChanged?.Invoke(); - eventsProcessed++; + events.Add(EventType.HeadChanged, null); } - else if (!indexChanged && fileA.Equals(paths.DotGitIndex)) + else if (!events.ContainsKey(EventType.IndexChanged) && fileA.Equals(paths.DotGitIndex)) { - indexChanged = true; - - Logger.Trace("IndexChanged"); - IndexChanged?.Invoke(); - eventsProcessed++; + events.Add(EventType.IndexChanged, null); } else if (fileA.IsChildOf(paths.RemotesPath)) { @@ -231,7 +235,7 @@ private int ProcessEvents(Event[] fileEvents) var origin = relativePathElements[0]; - if (fileEvent.Type == EventType.DELETED) + if (fileEvent.Type == sfw.net.EventType.DELETED) { if (fileA.ExtensionWithDot == ".lock") { @@ -239,12 +243,9 @@ private int ProcessEvents(Event[] fileEvents) } var branch = string.Join(@"/", relativePathElements.Skip(1).ToArray()); - - Logger.Trace("RemoteBranchDeleted: {0}/{1}", origin, branch); - RemoteBranchDeleted?.Invoke(origin, branch); - eventsProcessed++; + AddOrUpdateEventData(events, EventType.RemoteBranchDeleted, new EventData { Origin = origin, Branch = branch }); } - else if (fileEvent.Type == EventType.RENAMED) + else if (fileEvent.Type == sfw.net.EventType.RENAMED) { if (fileA.ExtensionWithDot != ".lock") { @@ -260,17 +261,14 @@ private int ProcessEvents(Event[] fileEvents) .Union(new[] { fileA.FileNameWithoutExtension }).ToArray(); var branch = string.Join(@"/", branchPathElement); - - Logger.Trace("RemoteBranchCreated: {0}/{1}", origin, branch); - RemoteBranchCreated?.Invoke(origin, branch); - eventsProcessed++; + AddOrUpdateEventData(events, EventType.RemoteBranchCreated, new EventData { Origin = origin, Branch = branch }); } } } } else if (fileA.IsChildOf(paths.BranchesPath)) { - if (fileEvent.Type == EventType.MODIFIED) + if (fileEvent.Type == sfw.net.EventType.MODIFIED) { if (fileA.DirectoryExists()) { @@ -292,11 +290,10 @@ private int ProcessEvents(Event[] fileEvents) var branch = string.Join(@"/", relativePathElements.ToArray()); - Logger.Trace("LocalBranchChanged: {0}", branch); - LocalBranchChanged?.Invoke(branch); - eventsProcessed++; + AddOrUpdateEventData(events, EventType.LocalBranchChanged, new EventData { Branch = branch }); + } - else if (fileEvent.Type == EventType.DELETED) + else if (fileEvent.Type == sfw.net.EventType.DELETED) { if (fileA.ExtensionWithDot == ".lock") { @@ -312,12 +309,9 @@ private int ProcessEvents(Event[] fileEvents) } var branch = string.Join(@"/", relativePathElements.ToArray()); - - Logger.Trace("LocalBranchDeleted: {0}", branch); - LocalBranchDeleted?.Invoke(branch); - eventsProcessed++; + AddOrUpdateEventData(events, EventType.LocalBranchDeleted, new EventData { Branch = branch }); } - else if (fileEvent.Type == EventType.RENAMED) + else if (fileEvent.Type == sfw.net.EventType.RENAMED) { if (fileA.ExtensionWithDot != ".lock") { @@ -337,10 +331,7 @@ private int ProcessEvents(Event[] fileEvents) } var branch = string.Join(@"/", relativePathElements.ToArray()); - - Logger.Trace("LocalBranchCreated: {0}", branch); - LocalBranchCreated?.Invoke(branch); - eventsProcessed++; + AddOrUpdateEventData(events, EventType.LocalBranchCreated, new EventData { Branch = branch }); } } } @@ -348,19 +339,104 @@ private int ProcessEvents(Event[] fileEvents) } else { - if (repositoryChanged || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath))) + if (events.ContainsKey(EventType.RepositoryChanged) || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath))) { continue; } + events.Add(EventType.RepositoryChanged, null); + } + } + + return FireEvents(events); + } - repositoryChanged = true; + private void AddOrUpdateEventData(Dictionary> events, EventType type, EventData data) + { + if (!events.ContainsKey(type)) + events.Add(type, new List()); + events[type].Add(data); + } - Logger.Trace("RepositoryChanged"); - RepositoryChanged?.Invoke(); + private int FireEvents(Dictionary> events) + { + int eventsProcessed = 0; + if (events.ContainsKey(EventType.ConfigChanged)) + { + Logger.Trace("ConfigChanged"); + ConfigChanged?.Invoke(); + eventsProcessed++; + } + + if (events.ContainsKey(EventType.HeadChanged)) + { + Logger.Trace("HeadChanged"); + HeadChanged?.Invoke(); + eventsProcessed++; + } + + if (events.ContainsKey(EventType.IndexChanged)) + { + Logger.Trace("IndexChanged"); + IndexChanged?.Invoke(); + eventsProcessed++; + } + + if (events.ContainsKey(EventType.RepositoryChanged)) + { + Logger.Trace("RepositoryChanged"); + RepositoryChanged?.Invoke(); + eventsProcessed++; + } + + if (events.ContainsKey(EventType.LocalBranchCreated)) + { + foreach (var evt in events[EventType.LocalBranchCreated]) + { + Logger.Trace($"LocalBranchCreated: {evt.Branch}"); + LocalBranchCreated?.Invoke(evt.Branch); eventsProcessed++; } } + if (events.ContainsKey(EventType.LocalBranchChanged)) + { + foreach (var evt in events[EventType.LocalBranchChanged]) + { + Logger.Trace($"LocalBranchChanged: {evt.Branch}"); + LocalBranchChanged?.Invoke(evt.Branch); + eventsProcessed++; + } + } + + if (events.ContainsKey(EventType.LocalBranchDeleted)) + { + foreach (var evt in events[EventType.LocalBranchDeleted]) + { + Logger.Trace($"LocalBranchDeleted: {evt.Branch}"); + LocalBranchDeleted?.Invoke(evt.Branch); + eventsProcessed++; + } + } + + if (events.ContainsKey(EventType.RemoteBranchCreated)) + { + foreach (var evt in events[EventType.RemoteBranchCreated]) + { + Logger.Trace($"RemoteBranchCreated: {evt.Origin}/{evt.Branch}"); + RemoteBranchCreated?.Invoke(evt.Origin, evt.Branch); + eventsProcessed++; + } + } + + if (events.ContainsKey(EventType.RemoteBranchDeleted)) + { + foreach (var evt in events[EventType.RemoteBranchDeleted]) + { + Logger.Trace($"RemoteBranchDeleted: {evt.Origin}/{evt.Branch}"); + RemoteBranchDeleted?.Invoke(evt.Origin, evt.Branch); + eventsProcessed++; + } + } return eventsProcessed; } From a2e6a521ea4a007e5d762a20995b045c17494310 Mon Sep 17 00:00:00 2001 From: Andreia Gaita Date: Mon, 16 Oct 2017 18:11:57 +0200 Subject: [PATCH 55/57] Put things in their proper place --- src/GitHub.Api/Events/RepositoryWatcher.cs | 42 +++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/GitHub.Api/Events/RepositoryWatcher.cs b/src/GitHub.Api/Events/RepositoryWatcher.cs index 6f3de0ac7..025b93eb8 100644 --- a/src/GitHub.Api/Events/RepositoryWatcher.cs +++ b/src/GitHub.Api/Events/RepositoryWatcher.cs @@ -160,27 +160,6 @@ public int CheckAndProcessEvents() return processedEventCount; } - enum EventType - { - None, - ConfigChanged, - HeadChanged, - RepositoryChanged, - IndexChanged, - RemoteBranchDeleted, - RemoteBranchCreated, - RemoteBranchChanged, - LocalBranchDeleted, - LocalBranchCreated, - LocalBranchChanged - } - - class EventData - { - public string Origin; - public string Branch; - } - private int ProcessEvents(Event[] fileEvents) { Dictionary> events = new Dictionary>(); @@ -464,5 +443,26 @@ public void Dispose() } protected static ILogging Logger { get; } = Logging.GetLogger(); + + private enum EventType + { + None, + ConfigChanged, + HeadChanged, + RepositoryChanged, + IndexChanged, + RemoteBranchDeleted, + RemoteBranchCreated, + RemoteBranchChanged, + LocalBranchDeleted, + LocalBranchCreated, + LocalBranchChanged + } + + private class EventData + { + public string Origin; + public string Branch; + } } } From 9b776d17319a3005392ff2ae63b54eb23e72992f Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 16 Oct 2017 13:20:28 -0400 Subject: [PATCH 56/57] Using TryGet to fire events --- src/GitHub.Api/Events/RepositoryWatcher.cs | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/GitHub.Api/Events/RepositoryWatcher.cs b/src/GitHub.Api/Events/RepositoryWatcher.cs index 025b93eb8..bd2576815 100644 --- a/src/GitHub.Api/Events/RepositoryWatcher.cs +++ b/src/GitHub.Api/Events/RepositoryWatcher.cs @@ -367,9 +367,10 @@ private int FireEvents(Dictionary> events) eventsProcessed++; } - if (events.ContainsKey(EventType.LocalBranchCreated)) + List localBranchesCreated; + if (events.TryGetValue(EventType.LocalBranchCreated, out localBranchesCreated)) { - foreach (var evt in events[EventType.LocalBranchCreated]) + foreach (var evt in localBranchesCreated) { Logger.Trace($"LocalBranchCreated: {evt.Branch}"); LocalBranchCreated?.Invoke(evt.Branch); @@ -377,9 +378,10 @@ private int FireEvents(Dictionary> events) } } - if (events.ContainsKey(EventType.LocalBranchChanged)) + List localBranchesChanged; + if (events.TryGetValue(EventType.LocalBranchChanged, out localBranchesChanged)) { - foreach (var evt in events[EventType.LocalBranchChanged]) + foreach (var evt in localBranchesChanged) { Logger.Trace($"LocalBranchChanged: {evt.Branch}"); LocalBranchChanged?.Invoke(evt.Branch); @@ -387,9 +389,10 @@ private int FireEvents(Dictionary> events) } } - if (events.ContainsKey(EventType.LocalBranchDeleted)) + List localBranchesDeleted; + if (events.TryGetValue(EventType.LocalBranchDeleted, out localBranchesDeleted)) { - foreach (var evt in events[EventType.LocalBranchDeleted]) + foreach (var evt in localBranchesDeleted) { Logger.Trace($"LocalBranchDeleted: {evt.Branch}"); LocalBranchDeleted?.Invoke(evt.Branch); @@ -397,9 +400,10 @@ private int FireEvents(Dictionary> events) } } - if (events.ContainsKey(EventType.RemoteBranchCreated)) + List remoteBranchesCreated; + if (events.TryGetValue(EventType.RemoteBranchCreated, out remoteBranchesCreated)) { - foreach (var evt in events[EventType.RemoteBranchCreated]) + foreach (var evt in remoteBranchesCreated) { Logger.Trace($"RemoteBranchCreated: {evt.Origin}/{evt.Branch}"); RemoteBranchCreated?.Invoke(evt.Origin, evt.Branch); @@ -407,9 +411,10 @@ private int FireEvents(Dictionary> events) } } - if (events.ContainsKey(EventType.RemoteBranchDeleted)) + List remoteBranchesDeleted; + if (events.TryGetValue(EventType.RemoteBranchDeleted, out remoteBranchesDeleted)) { - foreach (var evt in events[EventType.RemoteBranchDeleted]) + foreach (var evt in remoteBranchesDeleted) { Logger.Trace($"RemoteBranchDeleted: {evt.Origin}/{evt.Branch}"); RemoteBranchDeleted?.Invoke(evt.Origin, evt.Branch); From 6966e576a309a9cea99f12aa4a7cc19cbf2d49d5 Mon Sep 17 00:00:00 2001 From: Andreia Gaita Date: Tue, 17 Oct 2017 19:20:46 +0200 Subject: [PATCH 57/57] Remove unused event --- src/GitHub.Api/Events/RepositoryWatcher.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/GitHub.Api/Events/RepositoryWatcher.cs b/src/GitHub.Api/Events/RepositoryWatcher.cs index bd2576815..b72d6bd3c 100644 --- a/src/GitHub.Api/Events/RepositoryWatcher.cs +++ b/src/GitHub.Api/Events/RepositoryWatcher.cs @@ -458,7 +458,6 @@ private enum EventType IndexChanged, RemoteBranchDeleted, RemoteBranchCreated, - RemoteBranchChanged, LocalBranchDeleted, LocalBranchCreated, LocalBranchChanged