From 588879eb7f8689506179e02fea6402d6b5a8ed3b Mon Sep 17 00:00:00 2001 From: "Dmitrij D. Czarkoff" Date: Thu, 13 Feb 2025 02:41:08 +0000 Subject: [PATCH] feat: change worktree presentation (#978) Present the worktree name first, then relative path to the main repo. This is more aligned with Git's own UI, and works better with UI size constrains. --- src/Commands/Worktree.cs | 2 ++ src/Models/Worktree.cs | 9 +++++---- src/Views/RemoveWorktree.axaml | 4 ++-- src/Views/Repository.axaml | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Commands/Worktree.cs b/src/Commands/Worktree.cs index 27c0e28e..b73b8573 100644 --- a/src/Commands/Worktree.cs +++ b/src/Commands/Worktree.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; namespace SourceGit.Commands { @@ -26,6 +27,7 @@ namespace SourceGit.Commands if (line.StartsWith("worktree ", StringComparison.Ordinal)) { last = new Models.Worktree() { FullPath = line.Substring(9).Trim() }; + last.RelativePath = Path.GetRelativePath(WorkingDirectory, last.FullPath); worktrees.Add(last); } else if (line.StartsWith("bare", StringComparison.Ordinal)) diff --git a/src/Models/Worktree.cs b/src/Models/Worktree.cs index f9ba14e4..bc40e320 100644 --- a/src/Models/Worktree.cs +++ b/src/Models/Worktree.cs @@ -6,6 +6,7 @@ namespace SourceGit.Models { public string Branch { get; set; } = string.Empty; public string FullPath { get; set; } = string.Empty; + public string RelativePath { get; set; } = string.Empty; public string Head { get; set; } = string.Empty; public bool IsBare { get; set; } = false; public bool IsDetached { get; set; } = false; @@ -21,15 +22,15 @@ namespace SourceGit.Models get { if (IsDetached) - return $"(deteched HEAD at {Head.Substring(10)})"; + return $"deteched HEAD at {Head.Substring(10)}"; if (Branch.StartsWith("refs/heads/", System.StringComparison.Ordinal)) - return $"({Branch.Substring(11)})"; + return Branch.Substring(11); if (Branch.StartsWith("refs/remotes/", System.StringComparison.Ordinal)) - return $"({Branch.Substring(13)})"; + return Branch.Substring(13); - return $"({Branch})"; + return Branch; } } diff --git a/src/Views/RemoveWorktree.axaml b/src/Views/RemoveWorktree.axaml index 6d7ea914..364881d2 100644 --- a/src/Views/RemoveWorktree.axaml +++ b/src/Views/RemoveWorktree.axaml @@ -18,8 +18,8 @@ - - + + () diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index 74f628c6..4180a054 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -372,8 +372,8 @@ - - + + ()