diff --git a/src/Commands/QueryBranches.cs b/src/Commands/QueryBranches.cs index cc726fd9..04241933 100644 --- a/src/Commands/QueryBranches.cs +++ b/src/Commands/QueryBranches.cs @@ -51,7 +51,12 @@ namespace SourceGit.Commands var refName = parts[0]; if (refName.EndsWith("/HEAD", StringComparison.Ordinal)) return; - + + if (refName.StartsWith("(HEAD detached at")) + { + branch.isHead = true; + } + if (refName.StartsWith(PREFIX_LOCAL, StringComparison.Ordinal)) { branch.Name = refName.Substring(PREFIX_LOCAL.Length); diff --git a/src/Models/Branch.cs b/src/Models/Branch.cs index c23718d4..0b346712 100644 --- a/src/Models/Branch.cs +++ b/src/Models/Branch.cs @@ -10,5 +10,6 @@ public string Upstream { get; set; } public string UpstreamTrackStatus { get; set; } public string Remote { get; set; } + public bool isHead { get; set; } } } diff --git a/src/ViewModels/BranchTreeNode.cs b/src/ViewModels/BranchTreeNode.cs index b6b88b5d..8dc3cf94 100644 --- a/src/ViewModels/BranchTreeNode.cs +++ b/src/ViewModels/BranchTreeNode.cs @@ -7,6 +7,7 @@ namespace SourceGit.ViewModels { public enum BranchTreeNodeType { + DetachedHead, Remote, Folder, Branch, @@ -45,6 +46,11 @@ namespace SourceGit.ViewModels { get => Type == BranchTreeNodeType.Branch; } + + public bool IsDetachedHead + { + get => Type == BranchTreeNodeType.DetachedHead; + } public bool IsCurrent { @@ -170,11 +176,11 @@ namespace SourceGit.ViewModels start = sepIdx + 1; sepIdx = branch.Name.IndexOf('/', start); } - + lastFolder.Children.Add(new BranchTreeNode() { Name = Path.GetFileName(branch.Name), - Type = BranchTreeNodeType.Branch, + Type = branch.isHead ? BranchTreeNodeType.DetachedHead : BranchTreeNodeType.Branch, Backend = branch, IsExpanded = false, IsFiltered = isFiltered, @@ -185,14 +191,16 @@ namespace SourceGit.ViewModels { nodes.Sort((l, r) => { + if (l.Type == BranchTreeNodeType.DetachedHead) + { + return -1; + } if (l.Type == r.Type) { return l.Name.CompareTo(r.Name); } - else - { - return (int)l.Type - (int)r.Type; - } + + return (int)l.Type - (int)r.Type; }); foreach (var node in nodes)