Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LeftPanel was initiated twice at startup #9734

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion GitCommands/Git/GitModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static bool HasGitModulesFile(string path)
}

/// <inherit/>
public string WorkingDir { get; }
public string WorkingDir { get; init; }

/// <summary>
/// GitVersion for the default GitExecutable.
Expand Down Expand Up @@ -359,6 +359,13 @@ public string GitCommonDirectory
{
get
{
if (string.IsNullOrEmpty(WorkingDir))
{
// No directory for this module, so the common directory must be empty too
// (should not be retrieved from the GE start directory)
return "";
}

// Get a cache of the common dir
// Lock needed as the command is called rapidly when creating the module
if (_gitCommonDirectory is not null)
Expand Down
19 changes: 0 additions & 19 deletions GitCommands/Remotes/ConfigFileRemoteSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ public interface IConfigFileRemoteSettingsManager
/// Retrieves enabled remote names.
/// </summary>
IReadOnlyList<string> GetEnabledRemoteNames();

/// <summary>
/// Retrieves enabled remote names of remotes without branches (i.e. that require a fetch).
/// </summary>
IReadOnlyList<string> GetEnabledRemoteNamesWithoutBranches();
}

public class ConfigFileRemoteSettingsManager : IConfigFileRemoteSettingsManager
Expand Down Expand Up @@ -198,20 +193,6 @@ public IReadOnlyList<string> GetEnabledRemoteNames()
return GetModule().GetRemoteNames();
}

/// <summary>
/// Retrieves enabled remote names of remotes without branches (i.e. that require a fetch).
/// </summary>
public IReadOnlyList<string> GetEnabledRemoteNamesWithoutBranches()
{
HashSet<string> remotesWithBranches = GetModule().GetRefs(RefsFilter.Remotes)
.Select(branch => branch.Name.SubstringUntil('/'))
.ToHashSet();

HashSet<string> allRemotes = GetEnabledRemoteNames().ToHashSet();

return allRemotes.Except(remotesWithBranches).ToList();
}

/// <summary>
/// Loads the list of remotes configured in .git/config file.
/// </summary>
Expand Down
3 changes: 1 addition & 2 deletions GitUI/BranchTreePanel/RepoObjectsTree.BranchTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ public BranchTree(TreeNode treeNode, IGitUICommandsSource uiCommands, IAheadBehi

protected override bool SupportsFiltering => true;

protected override Task OnAttachedAsync()
protected override void OnAttached()
{
IsFiltering.Value = false;
return ReloadNodesAsync(LoadNodesAsync);
}

protected override Task PostRepositoryChangedAsync()
Expand Down
11 changes: 0 additions & 11 deletions GitUI/BranchTreePanel/RepoObjectsTree.Nodes.Submodules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,6 @@ public SubmoduleTree(TreeNode treeNode, IGitUICommandsSource uiCommands)
SubmoduleStatusProvider.Default.StatusUpdated += Provider_StatusUpdated;
}

protected override Task OnAttachedAsync()
{
var e = _currentSubmoduleInfo;
if (e is not null)
{
OnStatusUpdated(e);
}

return Task.CompletedTask;
}

protected override Task<Nodes> LoadNodesAsync(CancellationToken token)
{
return Task.FromResult(new Nodes(null));
Expand Down
3 changes: 1 addition & 2 deletions GitUI/BranchTreePanel/RepoObjectsTree.Nodes.Tags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ public TagTree(TreeNode treeNode, IGitUICommandsSource uiCommands, ICheckRefs re

protected override bool SupportsFiltering => true;

protected override Task OnAttachedAsync()
protected override void OnAttached()
{
IsFiltering.Value = false;
return ReloadNodesAsync(LoadNodesAsync);
}

protected override Task PostRepositoryChangedAsync()
Expand Down
7 changes: 3 additions & 4 deletions GitUI/BranchTreePanel/RepoObjectsTree.Nodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,14 @@ protected virtual Task PostRepositoryChangedAsync()
protected bool IsAttached { get; private set; }
protected virtual bool SupportsFiltering { get; } = false;

public Task AttachedAsync()
public void Attached()
{
IsAttached = true;
return OnAttachedAsync();
mstv marked this conversation as resolved.
Show resolved Hide resolved
OnAttached();
}

protected virtual Task OnAttachedAsync()
protected virtual void OnAttached()
{
return Task.CompletedTask;
}

public void Detached()
Expand Down
18 changes: 14 additions & 4 deletions GitUI/BranchTreePanel/RepoObjectsTree.RemoteBranchTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ public RemoteBranchTree(TreeNode treeNode, IGitUICommandsSource uiCommands, IChe

protected override bool SupportsFiltering => true;

protected override Task OnAttachedAsync()
protected override void OnAttached()
{
IsFiltering.Value = false;
return ReloadNodesAsync(LoadNodesAsync);
}

protected override Task PostRepositoryChangedAsync()
Expand Down Expand Up @@ -73,7 +72,7 @@ private async Task<Nodes> FillBranchTreeAsync(IReadOnlyList<IGitRef> branches, C
Dictionary<string, BaseBranchNode> pathToNodes = new();

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

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

Expand Down Expand Up @@ -102,7 +101,7 @@ private async Task<Nodes> FillBranchTreeAsync(IReadOnlyList<IGitRef> branches, C
}

// Create nodes for enabled remotes without branches
var enabledRemotesNoBranches = remotesManager.GetEnabledRemoteNamesWithoutBranches();
var enabledRemotesNoBranches = GetEnabledRemoteNamesWithoutBranches(branches, remoteByName);
foreach (var remoteName in enabledRemotesNoBranches)
{
if (remoteByName.TryGetValue(remoteName, out var remote))
Expand Down Expand Up @@ -147,6 +146,17 @@ BaseBranchNode CreateRemoteBranchPathNode(Tree tree, string parentPath, Remote r

return new BasePathNode(tree, parentPath);
}

IReadOnlyList<string> GetEnabledRemoteNamesWithoutBranches(IReadOnlyList<IGitRef> branches, Dictionary<string, Remote> remoteByName)
{
HashSet<string> remotesWithBranches = branches
.Select(branch => branch.Name.SubstringUntil('/'))
.ToHashSet();

HashSet<string> allRemotes = remoteByName.Select(kv => kv.Value.Name).ToHashSet();

return allRemotes.Except(remotesWithBranches).ToList();
}
}

protected override void PostFillTreeViewNode(bool firstTime)
Expand Down
16 changes: 9 additions & 7 deletions GitUI/BranchTreePanel/RepoObjectsTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,20 @@ public void SelectionChanged(IReadOnlyList<GitRevision> selectedRevisions)
{
// If we arrived here through the chain of events after selecting a node in the tree,
// and the selected revision is the one we have selected - do nothing.
if (selectedRevisions.Count == 1 && selectedRevisions[0].ObjectId == GetSelectedNodeObjectId(treeMain.SelectedNode))
if ((selectedRevisions.Count == 0 && treeMain.SelectedNode is null)
|| (selectedRevisions.Count == 1 && selectedRevisions[0].ObjectId == GetSelectedNodeObjectId(treeMain.SelectedNode)))
{
return;
}

var cancellationToken = _selectionCancellationTokenSequence.Next();

GitRevision selectedRevision = selectedRevisions.FirstOrDefault();
string selectedGuid = selectedRevision?.IsArtificial ?? true ? "HEAD" : selectedRevision.Guid;
string? selectedGuid = selectedRevision is null
? null
: selectedRevision.IsArtificial
? "HEAD"
: selectedRevision.Guid;
ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
cancellationToken.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -394,11 +399,8 @@ private void AddTree(Tree tree)
treeMain.Font = AppSettings.Font;
_rootNodes.Add(tree);

ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
await tree.AttachedAsync();
}).FileAndForget();
}
tree.Attached();
}

private void RemoveTree(Tree tree)
{
Expand Down
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/BuildReportTabPageExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void FillBuildReport(GitRevision? revision)

try
{
var buildResultPageEnabled = IsBuildResultPageEnabled();
var buildResultPageEnabled = revision is not null && IsBuildResultPageEnabled();
var buildInfoIsAvailable = !string.IsNullOrEmpty(revision?.BuildStatus?.Url);

if (buildResultPageEnabled && buildInfoIsAvailable)
Expand Down
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/FormBrowse.InitMenusAndToolbars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void InitToolStripStyles(Color toolForeColor, Color toolBackColor)

void InitFilters()
{
ToolStripFilters.UpdateBranchFilterItems();
// ToolStripFilters.UpdateBranchFilterItems() is init in UICommands_PostRepositoryChanged

if (!string.IsNullOrWhiteSpace(revFilter))
{
Expand Down
10 changes: 2 additions & 8 deletions UnitTests/GitCommands.Tests/GitModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,8 @@ public void CommitCmdTests(bool amend, bool signOff, string author, bool useExpl
[Test]
public void ParseGitBlame()
{
GitBlame result;

using (_executable.StageOutput("rev-parse --git-common-dir", ".git"))
{
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData/README.blame");

result = _gitModule.ParseGitBlame(File.ReadAllText(path), Encoding.UTF8);
}
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData/README.blame");
GitBlame result = _gitModule.ParseGitBlame(File.ReadAllText(path), Encoding.UTF8);

Assert.AreEqual(80, result.Lines.Count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,30 +388,6 @@ public void GetEnabledRemoteNames_returns_enabled_remotes_only()
Assert.AreEqual(enabledRemoteName, enabledRemoteNames[0]);
}

[Test]
public void GetEnabledRemotesNameWithoutBranches_returns_enabled_remotes_without_branches_only()
{
string enabledRemoteNameWithBranches = "enabledRemote1";
string enabledRemoteNameNoBranches = "enabledRemote2";
string disabledRemoteName = "disabledRemote";

_module.GetRemoteNames().Returns(x => new[] { enabledRemoteNameWithBranches, enabledRemoteNameNoBranches });

var refs = new[]
{
CreateSubstituteRef("02e10a13e06e7562f7c3c516abb2a0e1a0c0dd90", $"refs/remotes/{enabledRemoteNameWithBranches}/develop", $"{enabledRemoteNameWithBranches}"),
};

_module.GetRefs(RefsFilter.NoFilter).ReturnsForAnyArgs(refs);

List<IConfigSection> sections = new() { new ConfigSection($"{ConfigFileRemoteSettingsManager.DisabledSectionPrefix}{ConfigFileRemoteSettingsManager.SectionRemote}.{disabledRemoteName}", true) };
_configFile.GetConfigSections().Returns(x => sections);

var enabledRemotesNoBranches = _remotesManager.GetEnabledRemoteNamesWithoutBranches();
Assert.AreEqual(1, enabledRemotesNoBranches.Count);
Assert.AreEqual(enabledRemoteNameNoBranches, enabledRemotesNoBranches[0]);
}

[Test]
public void EnabledRemoteExists_returns_true_for_enabled_remotes_only()
{
Expand Down