Skip to content

Commit b0c0034

Browse files
committed
Making local detached branch HEAD as the first item below folders
1 parent 4750ad0 commit b0c0034

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/Commands/QueryBranches.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ protected override void OnReadline(string line)
5151
var refName = parts[0];
5252
if (refName.EndsWith("/HEAD", StringComparison.Ordinal))
5353
return;
54-
54+
55+
if (refName.StartsWith("(HEAD detached at"))
56+
{
57+
branch.isHead = true;
58+
}
59+
5560
if (refName.StartsWith(PREFIX_LOCAL, StringComparison.Ordinal))
5661
{
5762
branch.Name = refName.Substring(PREFIX_LOCAL.Length);

src/Models/Branch.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public class Branch
1010
public string Upstream { get; set; }
1111
public string UpstreamTrackStatus { get; set; }
1212
public string Remote { get; set; }
13+
public bool isHead { get; set; }
1314
}
1415
}

src/ViewModels/BranchTreeNode.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace SourceGit.ViewModels
77
{
88
public enum BranchTreeNodeType
99
{
10+
DetachedHead,
1011
Remote,
1112
Folder,
1213
Branch,
@@ -45,6 +46,11 @@ public bool IsBranch
4546
{
4647
get => Type == BranchTreeNodeType.Branch;
4748
}
49+
50+
public bool IsDetachedHead
51+
{
52+
get => Type == BranchTreeNodeType.DetachedHead;
53+
}
4854

4955
public bool IsCurrent
5056
{
@@ -170,11 +176,11 @@ private void MakeBranchNode(Models.Branch branch, List<BranchTreeNode> roots, Di
170176
start = sepIdx + 1;
171177
sepIdx = branch.Name.IndexOf('/', start);
172178
}
173-
179+
174180
lastFolder.Children.Add(new BranchTreeNode()
175181
{
176182
Name = Path.GetFileName(branch.Name),
177-
Type = BranchTreeNodeType.Branch,
183+
Type = branch.isHead ? BranchTreeNodeType.DetachedHead : BranchTreeNodeType.Branch,
178184
Backend = branch,
179185
IsExpanded = false,
180186
IsFiltered = isFiltered,
@@ -185,14 +191,16 @@ private void SortNodes(List<BranchTreeNode> nodes)
185191
{
186192
nodes.Sort((l, r) =>
187193
{
188-
if (l.Type == r.Type)
194+
if (l.Type == BranchTreeNodeType.DetachedHead)
189195
{
190-
return l.Name.CompareTo(r.Name);
196+
return -1;
191197
}
192-
else
198+
if (l.Type == r.Type)
193199
{
194-
return (int)l.Type - (int)r.Type;
200+
return l.Name.CompareTo(r.Name);
195201
}
202+
203+
return (int)l.Type - (int)r.Type;
196204
});
197205

198206
foreach (var node in nodes)

0 commit comments

Comments
 (0)