From fa2c7c0e18e9af032a4c79e99575864ded313b91 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 27 Jun 2024 19:19:21 +0800 Subject: [PATCH] enhance: simpfy the way to lock a worktree --- src/Commands/Worktree.cs | 7 ++--- src/Resources/Locales/en_US.axaml | 5 +--- src/Resources/Locales/zh_CN.axaml | 5 +--- src/Resources/Locales/zh_TW.axaml | 5 +--- src/ViewModels/AddWorktree.cs | 19 ++++++++----- src/ViewModels/LockWorktree.cs | 44 ------------------------------- src/ViewModels/Repository.cs | 7 +++-- src/Views/AddWorktree.axaml | 5 ++-- src/Views/LockWorktree.axaml | 41 ---------------------------- src/Views/LockWorktree.axaml.cs | 12 --------- 10 files changed, 25 insertions(+), 125 deletions(-) delete mode 100644 src/ViewModels/LockWorktree.cs delete mode 100644 src/Views/LockWorktree.axaml delete mode 100644 src/Views/LockWorktree.axaml.cs diff --git a/src/Commands/Worktree.cs b/src/Commands/Worktree.cs index 74b41358..800cb309 100644 --- a/src/Commands/Worktree.cs +++ b/src/Commands/Worktree.cs @@ -88,12 +88,9 @@ namespace SourceGit.Commands return Exec(); } - public bool Lock(string fullpath, string reason) + public bool Lock(string fullpath) { - if (string.IsNullOrEmpty(reason)) - Args = $"worktree lock \"{fullpath}\""; - else - Args = $"worktree lock --reason \"{reason}\" \"{fullpath}\""; + Args = $"worktree lock \"{fullpath}\""; return Exec(); } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 8158d38a..2e8b5448 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -9,6 +9,7 @@ Opensource & Free Git GUI Client Add Worktree Location: + Path for this worktree. Relative path is supported. Branch Name: Optional. Default is the destination folder name. Track Branch: @@ -311,10 +312,6 @@ ERROR NOTICE Open Main Menu - Lock Worktree - Reason: - Optional, specify a reason for the lock. - Target: Merge Branch Into: Merge Option: diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 81f42741..4121eaae 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -12,6 +12,7 @@ 开源免费的Git客户端 新增工作树 工作树路径 : + 填写该工作树的路径。支持相对路径。 自定义分支名 : 选填。默认使用目标文件夹名称。 跟踪分支 @@ -314,10 +315,6 @@ 出错了 系统提示 主菜单 - 锁定工作树 - 原因 : - 选填,为此锁定操作描述原因。 - 目标工作树 : 合并分支 目标分支 : 合并方式 : diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 25299cda..33d2a48b 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -12,6 +12,7 @@ 開源免費的Git客戶端 新增工作樹 工作樹路徑 : + 填寫該工作樹的路徑。支援相對路徑。 自定义分支名 : 選填。 預設使用目標資料夾名稱。 跟蹤分支 @@ -314,10 +315,6 @@ 出錯了 系統提示 主選單 - 鎖定工作樹 - 原因 : - 選填,為此鎖定操作描述原因。 - 目標工作樹 : 合併分支 目標分支 : 合併方式 : diff --git a/src/ViewModels/AddWorktree.cs b/src/ViewModels/AddWorktree.cs index afa42ebf..b9425dca 100644 --- a/src/ViewModels/AddWorktree.cs +++ b/src/ViewModels/AddWorktree.cs @@ -13,10 +13,10 @@ namespace SourceGit.ViewModels [Required(ErrorMessage = "Worktree path is required!")] [CustomValidation(typeof(AddWorktree), nameof(ValidateWorktreePath))] - public string FullPath + public string Path { - get => _fullPath; - set => SetProperty(ref _fullPath, value, true); + get => _path; + set => SetProperty(ref _path, value, true); } [CustomValidation(typeof(AddWorktree), nameof(ValidateBranchName))] @@ -63,9 +63,14 @@ namespace SourceGit.ViewModels View = new Views.AddWorktree() { DataContext = this }; } - public static ValidationResult ValidateWorktreePath(string folder, ValidationContext _) + public static ValidationResult ValidateWorktreePath(string path, ValidationContext ctx) { - var info = new DirectoryInfo(folder); + var creator = ctx.ObjectInstance as AddWorktree; + if (creator == null) + return new ValidationResult("Missing runtime context to create branch!"); + + var fullPath = System.IO.Path.IsPathRooted(path) ? path : System.IO.Path.Combine(creator._repo.FullPath, path); + var info = new DirectoryInfo(fullPath); if (info.Exists) { var files = info.GetFiles(); @@ -108,14 +113,14 @@ namespace SourceGit.ViewModels return Task.Run(() => { - var succ = new Commands.Worktree(_repo.FullPath).Add(_fullPath, _customName, tracking, SetProgressDescription); + var succ = new Commands.Worktree(_repo.FullPath).Add(_path, _customName, tracking, SetProgressDescription); CallUIThread(() => _repo.SetWatcherEnabled(true)); return succ; }); } private Repository _repo = null; - private string _fullPath = string.Empty; + private string _path = string.Empty; private string _customName = string.Empty; private bool _setTrackingBranch = false; } diff --git a/src/ViewModels/LockWorktree.cs b/src/ViewModels/LockWorktree.cs deleted file mode 100644 index e8a181c6..00000000 --- a/src/ViewModels/LockWorktree.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Threading.Tasks; - -namespace SourceGit.ViewModels -{ - public class LockWorktree : Popup - { - public Models.Worktree Target - { - get; - private set; - } = null; - - public string Reason - { - get; - set; - } = string.Empty; - - public LockWorktree(Repository repo, Models.Worktree target) - { - _repo = repo; - Target = target; - View = new Views.LockWorktree() { DataContext = this }; - } - - public override Task Sure() - { - _repo.SetWatcherEnabled(false); - ProgressDescription = "Locking worktrees ..."; - - return Task.Run(() => - { - var succ = new Commands.Worktree(_repo.FullPath).Lock(Target.FullPath, Reason); - if (succ) - Target.IsLocked = true; - - CallUIThread(() => _repo.SetWatcherEnabled(true)); - return true; - }); - } - - private Repository _repo = null; - } -} diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 2e980575..99bff966 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -1731,8 +1731,11 @@ namespace SourceGit.ViewModels loc.Icon = App.CreateMenuIcon("Icons.Lock"); loc.Click += (o, ev) => { - if (PopupHost.CanCreatePopup()) - PopupHost.ShowPopup(new LockWorktree(this, worktree)); + SetWatcherEnabled(false); + var succ = new Commands.Worktree(_fullpath).Lock(worktree.FullPath); + if (succ) + worktree.IsLocked = true; + SetWatcherEnabled(true); ev.Handled = true; }; menu.Items.Add(loc); diff --git a/src/Views/AddWorktree.axaml b/src/Views/AddWorktree.axaml index 11bc2186..a393c055 100644 --- a/src/Views/AddWorktree.axaml +++ b/src/Views/AddWorktree.axaml @@ -13,7 +13,7 @@ - + + Text="{Binding Path, Mode=TwoWay}" + Watermark="{DynamicResource Text.AddWorktree.Location.Placeholder}">