Making local detached branch HEAD as the first item below folders

This commit is contained in:
Filipe Ramalho 2024-05-25 15:09:40 -03:00
parent 4750ad0d07
commit b0c00340a8
3 changed files with 21 additions and 7 deletions

View file

@ -52,6 +52,11 @@ namespace SourceGit.Commands
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);

View file

@ -10,5 +10,6 @@
public string Upstream { get; set; }
public string UpstreamTrackStatus { get; set; }
public string Remote { get; set; }
public bool isHead { get; set; }
}
}

View file

@ -7,6 +7,7 @@ namespace SourceGit.ViewModels
{
public enum BranchTreeNodeType
{
DetachedHead,
Remote,
Folder,
Branch,
@ -46,6 +47,11 @@ namespace SourceGit.ViewModels
get => Type == BranchTreeNodeType.Branch;
}
public bool IsDetachedHead
{
get => Type == BranchTreeNodeType.DetachedHead;
}
public bool IsCurrent
{
get => IsBranch && (Backend as Models.Branch).IsCurrent;
@ -174,7 +180,7 @@ namespace SourceGit.ViewModels
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)