Skip to content

Commit 588879e

Browse files
authored
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.
1 parent c6aedf1 commit 588879e

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

src/Commands/Worktree.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34

45
namespace SourceGit.Commands
56
{
@@ -26,6 +27,7 @@ public Worktree(string repo)
2627
if (line.StartsWith("worktree ", StringComparison.Ordinal))
2728
{
2829
last = new Models.Worktree() { FullPath = line.Substring(9).Trim() };
30+
last.RelativePath = Path.GetRelativePath(WorkingDirectory, last.FullPath);
2931
worktrees.Add(last);
3032
}
3133
else if (line.StartsWith("bare", StringComparison.Ordinal))

src/Models/Worktree.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class Worktree : ObservableObject
66
{
77
public string Branch { get; set; } = string.Empty;
88
public string FullPath { get; set; } = string.Empty;
9+
public string RelativePath { get; set; } = string.Empty;
910
public string Head { get; set; } = string.Empty;
1011
public bool IsBare { get; set; } = false;
1112
public bool IsDetached { get; set; } = false;
@@ -21,15 +22,15 @@ public string Name
2122
get
2223
{
2324
if (IsDetached)
24-
return $"(deteched HEAD at {Head.Substring(10)})";
25+
return $"deteched HEAD at {Head.Substring(10)}";
2526

2627
if (Branch.StartsWith("refs/heads/", System.StringComparison.Ordinal))
27-
return $"({Branch.Substring(11)})";
28+
return Branch.Substring(11);
2829

2930
if (Branch.StartsWith("refs/remotes/", System.StringComparison.Ordinal))
30-
return $"({Branch.Substring(13)})";
31+
return Branch.Substring(13);
3132

32-
return $"({Branch})";
33+
return Branch;
3334
}
3435
}
3536

src/Views/RemoveWorktree.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
<Grid Grid.Row="0" Grid.Column="1" ColumnDefinitions="Auto,*">
1919
<Path Grid.Column="0" Width="12" Height="12" Data="{StaticResource Icons.Worktree}"/>
2020
<TextBlock Grid.Column="1" Classes="primary" Margin="8,0,0,0" TextTrimming="CharacterEllipsis">
21-
<Run Text="{Binding Target.FullPath}"/>
22-
<Run Text="{Binding Target.Name}" Foreground="{DynamicResource Brush.FG2}"/>
21+
<Run Text="{Binding Target.Name}"/>
22+
(<Run Text="{Binding Target.RelativePath}" Foreground="{DynamicResource Brush.FG2}"/>)
2323
</TextBlock>
2424
</Grid>
2525

src/Views/Repository.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@
372372
<Grid ColumnDefinitions="Auto,*,22">
373373
<Path Grid.Column="0" Width="10" Height="10" Margin="8,0,0,0" Data="{StaticResource Icons.Worktree}"/>
374374
<TextBlock Grid.Column="1" Classes="primary" Margin="8,0,0,0" TextTrimming="CharacterEllipsis">
375-
<Run Text="{Binding FullPath}"/>
376-
<Run Text="{Binding Name}" Foreground="{DynamicResource Brush.FG2}"/>
375+
<Run Text="{Binding Name}"/>
376+
(<Run Text="{Binding RelativePath}" Foreground="{DynamicResource Brush.FG2}"/>)
377377
</TextBlock>
378378
<Path Grid.Column="2" Width="10" Height="10" Margin="4,0,0,0" Data="{StaticResource Icons.Lock}" Fill="{DynamicResource Brush.FG2}" IsVisible="{Binding IsLocked}"/>
379379
</Grid>

0 commit comments

Comments
 (0)