private async Task <Nodes> LoadNodesAsync(CancellationToken token)
            {
                await TaskScheduler.Default;

                token.ThrowIfCancellationRequested();
                var nodes       = new Nodes(this);
                var pathToNodes = new Dictionary <string, BaseBranchNode>();

                var branches = Module.GetRefs(tags: true, branches: true, noLocks: true)
                               .Where(branch => branch.IsRemote && !branch.IsTag)
                               .OrderBy(branch => branch.Name)
                               .Select(branch => branch.Name);

                token.ThrowIfCancellationRequested();

                var enabledRemoteRepoNodes = new List <RemoteRepoNode>();
                var remoteByName           = Module.GetRemotes().ToDictionary(r => r.Name);

                var gitRemoteManager = new GitRemoteManager(() => Module);

                // Create nodes for enabled remotes with branches
                foreach (var branchPath in branches)
                {
                    token.ThrowIfCancellationRequested();
                    var remoteName = branchPath.SubstringUntil('/');
                    if (remoteByName.TryGetValue(remoteName, out var remote))
                    {
                        var remoteBranchNode = new RemoteBranchNode(this, branchPath);
                        var parent           = remoteBranchNode.CreateRootNode(
                            pathToNodes,
                            (tree, parentPath) => CreateRemoteBranchPathNode(tree, parentPath, remote));

                        if (parent != null)
                        {
                            enabledRemoteRepoNodes.Add((RemoteRepoNode)parent);
                        }
                    }
                }

                // Create nodes for enabled remotes without branches
                var enabledRemotesNoBranches = gitRemoteManager.GetEnabledRemoteNamesWithoutBranches();

                foreach (var remoteName in enabledRemotesNoBranches)
                {
                    if (remoteByName.TryGetValue(remoteName, out var remote))
                    {
                        var node = new RemoteRepoNode(this, remoteName, gitRemoteManager, remote, true);
                        enabledRemoteRepoNodes.Add(node);
                    }
                }

                // Add enabled remote nodes in order
                enabledRemoteRepoNodes
                .OrderBy(node => node.FullPath)
                .ForEach(node => nodes.AddNode(node));

                // Add disabled remotes, if any
                var disabledRemotes = gitRemoteManager.GetDisabledRemotes();

                if (disabledRemotes.Count > 0)
                {
                    var disabledRemoteRepoNodes = new List <RemoteRepoNode>();
                    foreach (var remote in disabledRemotes.OrderBy(remote => remote.Name))
                    {
                        var node = new RemoteRepoNode(this, remote.Name, gitRemoteManager, remote, false);
                        disabledRemoteRepoNodes.Add(node);
                    }

                    var disabledFolderNode = new RemoteRepoFolderNode(this, _inactiveRemoteNodeLabel.Text);
                    disabledRemoteRepoNodes
                    .OrderBy(node => node.FullPath)
                    .ForEach(node => disabledFolderNode.Nodes.AddNode(node));

                    nodes.AddNode(disabledFolderNode);
                }

                return(nodes);

                BaseBranchNode CreateRemoteBranchPathNode(Tree tree, string parentPath, Remote remote)
                {
                    if (parentPath == remote.Name)
                    {
                        return(new RemoteRepoNode(tree, parentPath, gitRemoteManager, remote, true));
                    }

                    return(new BasePathNode(tree, parentPath));
                }
            }
            private async Task <Nodes> FillBranchTreeAsync(IReadOnlyList <IGitRef> branches, CancellationToken token)
            {
                var nodes       = new Nodes(this);
                var pathToNodes = new Dictionary <string, BaseBranchNode>();

                var enabledRemoteRepoNodes = new List <RemoteRepoNode>();
                var remoteByName           = (await Module.GetRemotesAsync().ConfigureAwaitRunInline()).ToDictionary(r => r.Name);

                var remotesManager = new ConfigFileRemoteSettingsManager(() => Module);

                // Create nodes for enabled remotes with branches
                foreach (IGitRef branch in branches)
                {
                    token.ThrowIfCancellationRequested();

                    Validates.NotNull(branch.ObjectId);

                    bool isVisible  = !IsFiltering.Value || _refsSource.Contains(branch.ObjectId);
                    var  remoteName = branch.Name.SubstringUntil('/');
                    if (remoteByName.TryGetValue(remoteName, out Remote remote))
                    {
                        var remoteBranchNode = new RemoteBranchNode(this, branch.ObjectId, branch.Name, isVisible);

                        var parent = remoteBranchNode.CreateRootNode(
                            pathToNodes,
                            (tree, parentPath) => CreateRemoteBranchPathNode(tree, parentPath, remote));

                        if (parent is not null)
                        {
                            enabledRemoteRepoNodes.Add((RemoteRepoNode)parent);
                        }
                    }
                }

                // Create nodes for enabled remotes without branches
                var enabledRemotesNoBranches = remotesManager.GetEnabledRemoteNamesWithoutBranches();

                foreach (var remoteName in enabledRemotesNoBranches)
                {
                    if (remoteByName.TryGetValue(remoteName, out var remote))
                    {
                        var node = new RemoteRepoNode(this, remoteName, remotesManager, remote, true);
                        enabledRemoteRepoNodes.Add(node);
                    }
                }

                // Add enabled remote nodes in order
                enabledRemoteRepoNodes
                .OrderBy(node => node.FullPath)
                .ForEach(node => nodes.AddNode(node));

                // Add disabled remotes, if any
                var disabledRemotes = remotesManager.GetDisabledRemotes();

                if (disabledRemotes.Count > 0)
                {
                    var disabledRemoteRepoNodes = new List <RemoteRepoNode>();
                    foreach (var remote in disabledRemotes.OrderBy(remote => remote.Name))
                    {
                        var node = new RemoteRepoNode(this, remote.Name, remotesManager, remote, false);
                        disabledRemoteRepoNodes.Add(node);
                    }

                    var disabledFolderNode = new RemoteRepoFolderNode(this, Strings.Inactive);
                    disabledRemoteRepoNodes
                    .OrderBy(node => node.FullPath)
                    .ForEach(node => disabledFolderNode.Nodes.AddNode(node));

                    nodes.AddNode(disabledFolderNode);
                }

                return(nodes);

                BaseBranchNode CreateRemoteBranchPathNode(Tree tree, string parentPath, Remote remote)
                {
                    if (parentPath == remote.Name)
                    {
                        return(new RemoteRepoNode(tree, parentPath, remotesManager, remote, true));
                    }

                    return(new BasePathNode(tree, parentPath));
                }
            }