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

@ -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);

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,
@ -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)