diff --git a/src/Commands/QueryBranches.cs b/src/Commands/QueryBranches.cs index 39794090..910e5fd2 100644 --- a/src/Commands/QueryBranches.cs +++ b/src/Commands/QueryBranches.cs @@ -27,7 +27,7 @@ namespace SourceGit.Commands return branches; var lines = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries); - var remoteBranches = new HashSet(); + var remoteHeads = new Dictionary(); foreach (var line in lines) { var b = ParseLine(line); @@ -35,7 +35,7 @@ namespace SourceGit.Commands { branches.Add(b); if (!b.IsLocal) - remoteBranches.Add(b.FullName); + remoteHeads.Add(b.FullName, b.Head); else localBranchesCount++; } @@ -44,7 +44,22 @@ namespace SourceGit.Commands foreach (var b in branches) { if (b.IsLocal && !string.IsNullOrEmpty(b.Upstream)) - b.IsUpstreamGone = !remoteBranches.Contains(b.Upstream); + { + if (remoteHeads.TryGetValue(b.Upstream, out var upstreamHead)) + { + b.IsUpstreamGone = false; + + if (b.TrackStatus == null) + b.TrackStatus = new QueryTrackStatus(WorkingDirectory, b.Head, upstreamHead).Result(); + } + else + { + b.IsUpstreamGone = true; + + if (b.TrackStatus == null) + b.TrackStatus = new Models.BranchTrackStatus(); + } + } } return branches; @@ -93,9 +108,10 @@ namespace SourceGit.Commands branch.Upstream = parts[4]; branch.IsUpstreamGone = false; - if (branch.IsLocal && !string.IsNullOrEmpty(parts[5]) && !parts[5].Equals("=", StringComparison.Ordinal)) - branch.TrackStatus = new QueryTrackStatus(WorkingDirectory, branch.Name, branch.Upstream).Result(); - else + if (!branch.IsLocal || + string.IsNullOrEmpty(branch.Upstream) || + string.IsNullOrEmpty(parts[5]) || + parts[5].Equals("=", StringComparison.Ordinal)) branch.TrackStatus = new Models.BranchTrackStatus(); return branch;