Skip to content

Commit fa2c7c0

Browse files
committed
enhance: simpfy the way to lock a worktree
1 parent 8a8aabe commit fa2c7c0

File tree

10 files changed

+25
-125
lines changed

10 files changed

+25
-125
lines changed

src/Commands/Worktree.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,9 @@ public bool Prune(Action<string> outputHandler)
8888
return Exec();
8989
}
9090

91-
public bool Lock(string fullpath, string reason)
91+
public bool Lock(string fullpath)
9292
{
93-
if (string.IsNullOrEmpty(reason))
94-
Args = $"worktree lock \"{fullpath}\"";
95-
else
96-
Args = $"worktree lock --reason \"{reason}\" \"{fullpath}\"";
93+
Args = $"worktree lock \"{fullpath}\"";
9794
return Exec();
9895
}
9996

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<x:String x:Key="Text.About.SubTitle" xml:space="preserve">Opensource &amp; Free Git GUI Client</x:String>
1010
<x:String x:Key="Text.AddWorktree" xml:space="preserve">Add Worktree</x:String>
1111
<x:String x:Key="Text.AddWorktree.Location" xml:space="preserve">Location:</x:String>
12+
<x:String x:Key="Text.AddWorktree.Location.Placeholder" xml:space="preserve">Path for this worktree. Relative path is supported.</x:String>
1213
<x:String x:Key="Text.AddWorktree.Name" xml:space="preserve">Branch Name:</x:String>
1314
<x:String x:Key="Text.AddWorktree.Name.Placeholder" xml:space="preserve">Optional. Default is the destination folder name.</x:String>
1415
<x:String x:Key="Text.AddWorktree.Tracking" xml:space="preserve">Track Branch:</x:String>
@@ -311,10 +312,6 @@
311312
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">ERROR</x:String>
312313
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">NOTICE</x:String>
313314
<x:String x:Key="Text.Launcher.Menu" xml:space="preserve">Open Main Menu</x:String>
314-
<x:String x:Key="Text.LockWorktree" xml:space="preserve">Lock Worktree</x:String>
315-
<x:String x:Key="Text.LockWorktree.Reason" xml:space="preserve">Reason:</x:String>
316-
<x:String x:Key="Text.LockWorktree.Reason.Placeholder" xml:space="preserve">Optional, specify a reason for the lock.</x:String>
317-
<x:String x:Key="Text.LockWorktree.Target" xml:space="preserve">Target:</x:String>
318315
<x:String x:Key="Text.Merge" xml:space="preserve">Merge Branch</x:String>
319316
<x:String x:Key="Text.Merge.Into" xml:space="preserve">Into:</x:String>
320317
<x:String x:Key="Text.Merge.Mode" xml:space="preserve">Merge Option:</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<x:String x:Key="Text.About.SubTitle" xml:space="preserve">开源免费的Git客户端</x:String>
1313
<x:String x:Key="Text.AddWorktree" xml:space="preserve">新增工作树</x:String>
1414
<x:String x:Key="Text.AddWorktree.Location" xml:space="preserve">工作树路径 :</x:String>
15+
<x:String x:Key="Text.AddWorktree.Location.Placeholder" xml:space="preserve">填写该工作树的路径。支持相对路径。</x:String>
1516
<x:String x:Key="Text.AddWorktree.Name" xml:space="preserve">自定义分支名 :</x:String>
1617
<x:String x:Key="Text.AddWorktree.Name.Placeholder" xml:space="preserve">选填。默认使用目标文件夹名称。</x:String>
1718
<x:String x:Key="Text.AddWorktree.Tracking" xml:space="preserve">跟踪分支</x:String>
@@ -314,10 +315,6 @@
314315
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">出错了</x:String>
315316
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">系统提示</x:String>
316317
<x:String x:Key="Text.Launcher.Menu" xml:space="preserve">主菜单</x:String>
317-
<x:String x:Key="Text.LockWorktree" xml:space="preserve">锁定工作树</x:String>
318-
<x:String x:Key="Text.LockWorktree.Reason" xml:space="preserve">原因 :</x:String>
319-
<x:String x:Key="Text.LockWorktree.Reason.Placeholder" xml:space="preserve">选填,为此锁定操作描述原因。</x:String>
320-
<x:String x:Key="Text.LockWorktree.Target" xml:space="preserve">目标工作树 :</x:String>
321318
<x:String x:Key="Text.Merge" xml:space="preserve">合并分支</x:String>
322319
<x:String x:Key="Text.Merge.Into" xml:space="preserve">目标分支 :</x:String>
323320
<x:String x:Key="Text.Merge.Mode" xml:space="preserve">合并方式 :</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<x:String x:Key="Text.About.SubTitle" xml:space="preserve">開源免費的Git客戶端</x:String>
1313
<x:String x:Key="Text.AddWorktree" xml:space="preserve">新增工作樹</x:String>
1414
<x:String x:Key="Text.AddWorktree.Location" xml:space="preserve">工作樹路徑 :</x:String>
15+
<x:String x:Key="Text.AddWorktree.Location.Placeholder" xml:space="preserve">填寫該工作樹的路徑。支援相對路徑。</x:String>
1516
<x:String x:Key="Text.AddWorktree.Name" xml:space="preserve">自定义分支名 :</x:String>
1617
<x:String x:Key="Text.AddWorktree.Name.Placeholder" xml:space="preserve">選填。 預設使用目標資料夾名稱。</x:String>
1718
<x:String x:Key="Text.AddWorktree.Tracking" xml:space="preserve">跟蹤分支</x:String>
@@ -314,10 +315,6 @@
314315
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">出錯了</x:String>
315316
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">系統提示</x:String>
316317
<x:String x:Key="Text.Launcher.Menu" xml:space="preserve">主選單</x:String>
317-
<x:String x:Key="Text.LockWorktree" xml:space="preserve">鎖定工作樹</x:String>
318-
<x:String x:Key="Text.LockWorktree.Reason" xml:space="preserve">原因 :</x:String>
319-
<x:String x:Key="Text.LockWorktree.Reason.Placeholder" xml:space="preserve">選填,為此鎖定操作描述原因。</x:String>
320-
<x:String x:Key="Text.LockWorktree.Target" xml:space="preserve">目標工作樹 :</x:String>
321318
<x:String x:Key="Text.Merge" xml:space="preserve">合併分支</x:String>
322319
<x:String x:Key="Text.Merge.Into" xml:space="preserve">目標分支 :</x:String>
323320
<x:String x:Key="Text.Merge.Mode" xml:space="preserve">合併方式 :</x:String>

src/ViewModels/AddWorktree.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public partial class AddWorktree : Popup
1313

1414
[Required(ErrorMessage = "Worktree path is required!")]
1515
[CustomValidation(typeof(AddWorktree), nameof(ValidateWorktreePath))]
16-
public string FullPath
16+
public string Path
1717
{
18-
get => _fullPath;
19-
set => SetProperty(ref _fullPath, value, true);
18+
get => _path;
19+
set => SetProperty(ref _path, value, true);
2020
}
2121

2222
[CustomValidation(typeof(AddWorktree), nameof(ValidateBranchName))]
@@ -63,9 +63,14 @@ public AddWorktree(Repository repo)
6363
View = new Views.AddWorktree() { DataContext = this };
6464
}
6565

66-
public static ValidationResult ValidateWorktreePath(string folder, ValidationContext _)
66+
public static ValidationResult ValidateWorktreePath(string path, ValidationContext ctx)
6767
{
68-
var info = new DirectoryInfo(folder);
68+
var creator = ctx.ObjectInstance as AddWorktree;
69+
if (creator == null)
70+
return new ValidationResult("Missing runtime context to create branch!");
71+
72+
var fullPath = System.IO.Path.IsPathRooted(path) ? path : System.IO.Path.Combine(creator._repo.FullPath, path);
73+
var info = new DirectoryInfo(fullPath);
6974
if (info.Exists)
7075
{
7176
var files = info.GetFiles();
@@ -108,14 +113,14 @@ public override Task<bool> Sure()
108113

109114
return Task.Run(() =>
110115
{
111-
var succ = new Commands.Worktree(_repo.FullPath).Add(_fullPath, _customName, tracking, SetProgressDescription);
116+
var succ = new Commands.Worktree(_repo.FullPath).Add(_path, _customName, tracking, SetProgressDescription);
112117
CallUIThread(() => _repo.SetWatcherEnabled(true));
113118
return succ;
114119
});
115120
}
116121

117122
private Repository _repo = null;
118-
private string _fullPath = string.Empty;
123+
private string _path = string.Empty;
119124
private string _customName = string.Empty;
120125
private bool _setTrackingBranch = false;
121126
}

src/ViewModels/LockWorktree.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/ViewModels/Repository.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,8 +1731,11 @@ public ContextMenu CreateContextMenuForWorktree(Models.Worktree worktree)
17311731
loc.Icon = App.CreateMenuIcon("Icons.Lock");
17321732
loc.Click += (o, ev) =>
17331733
{
1734-
if (PopupHost.CanCreatePopup())
1735-
PopupHost.ShowPopup(new LockWorktree(this, worktree));
1734+
SetWatcherEnabled(false);
1735+
var succ = new Commands.Worktree(_fullpath).Lock(worktree.FullPath);
1736+
if (succ)
1737+
worktree.IsLocked = true;
1738+
SetWatcherEnabled(true);
17361739
ev.Handled = true;
17371740
};
17381741
menu.Items.Add(loc);

src/Views/AddWorktree.axaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<TextBlock FontSize="18"
1414
Classes="bold"
1515
Text="{DynamicResource Text.AddWorktree}"/>
16-
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,Auto" ColumnDefinitions="150,*">
16+
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,Auto" ColumnDefinitions="120,*">
1717
<TextBlock Grid.Row="0" Grid.Column="0"
1818
HorizontalAlignment="Right" VerticalAlignment="Center"
1919
Margin="0,0,8,0"
@@ -22,7 +22,8 @@
2222
x:Name="TxtLocation"
2323
Height="28"
2424
CornerRadius="3"
25-
Text="{Binding FullPath, Mode=TwoWay}">
25+
Text="{Binding Path, Mode=TwoWay}"
26+
Watermark="{DynamicResource Text.AddWorktree.Location.Placeholder}">
2627
<TextBox.InnerRightContent>
2728
<Button Classes="icon_button" Width="28" Height="28" Margin="4,0,0,0" Click="SelectLocation">
2829
<Path Data="{StaticResource Icons.Folder.Open}" Fill="{DynamicResource Brush.FG1}"/>

src/Views/LockWorktree.axaml

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/Views/LockWorktree.axaml.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)