diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml
index 76beb4f9..0586ee99 100644
--- a/src/Resources/Locales/en_US.axaml
+++ b/src/Resources/Locales/en_US.axaml
@@ -8,6 +8,9 @@
• Source code can be found at
Opensource & Free Git GUI Client
Add Worktree
+ What to Checkout:
+ Existing Branch
+ Create New Branch
Location:
Path for this worktree. Relative path is supported.
Branch Name:
diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml
index 12158d43..3b6bfb9d 100644
--- a/src/Resources/Locales/zh_CN.axaml
+++ b/src/Resources/Locales/zh_CN.axaml
@@ -11,9 +11,12 @@
• 项目源代码地址
开源免费的Git客户端
新增工作树
+ 检出分支方式 :
+ 已有分支
+ 创建新分支
工作树路径 :
填写该工作树的路径。支持相对路径。
- 自定义分支名 :
+ 分支名 :
选填。默认使用目标文件夹名称。
跟踪分支
设置上游跟踪分支
diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml
index 8b55fcfc..5563a21a 100644
--- a/src/Resources/Locales/zh_TW.axaml
+++ b/src/Resources/Locales/zh_TW.axaml
@@ -11,9 +11,12 @@
• 專案原始碼地址
開源免費的Git客戶端
新增工作樹
+ 檢出分支方式 :
+ 已有分支
+ 創建新分支
工作樹路徑 :
填寫該工作樹的路徑。支援相對路徑。
- 自定义分支名 :
+ 分支名 :
選填。 預設使用目標資料夾名稱。
跟蹤分支
設置上游跟蹤分支
diff --git a/src/ViewModels/AddWorktree.cs b/src/ViewModels/AddWorktree.cs
index b9425dca..c034fb75 100644
--- a/src/ViewModels/AddWorktree.cs
+++ b/src/ViewModels/AddWorktree.cs
@@ -1,29 +1,51 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
-using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
- public partial class AddWorktree : Popup
+ public class AddWorktree : Popup
{
- [GeneratedRegex(@"^[\w\-/\.]+$")]
- private static partial Regex REG_NAME();
-
[Required(ErrorMessage = "Worktree path is required!")]
[CustomValidation(typeof(AddWorktree), nameof(ValidateWorktreePath))]
public string Path
{
get => _path;
- set => SetProperty(ref _path, value, true);
+ set => SetProperty(ref _path, value);
}
- [CustomValidation(typeof(AddWorktree), nameof(ValidateBranchName))]
- public string CustomName
+ public bool UseExistingBranch
{
- get => _customName;
- set => SetProperty(ref _customName, value, true);
+ get => _useExistingBranch;
+ set
+ {
+ if (SetProperty(ref _useExistingBranch, value, true))
+ {
+ if (value)
+ SelectedBranch = LocalBranches.Count > 0 ? LocalBranches[0] : string.Empty;
+ else
+ SelectedBranch = string.Empty;
+ }
+ }
+ }
+
+ public List LocalBranches
+ {
+ get;
+ private set;
+ }
+
+ public List RemoteBranches
+ {
+ get;
+ private set;
+ }
+
+ public string SelectedBranch
+ {
+ get => _selectedBranch;
+ set => SetProperty(ref _selectedBranch, value);
}
public bool SetTrackingBranch
@@ -32,12 +54,6 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _setTrackingBranch, value);
}
- public List TrackingBranches
- {
- get;
- private set;
- }
-
public string SelectedTrackingBranch
{
get;
@@ -48,15 +64,23 @@ namespace SourceGit.ViewModels
{
_repo = repo;
- TrackingBranches = new List();
+ LocalBranches = new List();
+ RemoteBranches = new List();
foreach (var branch in repo.Branches)
{
- if (!branch.IsLocal)
- TrackingBranches.Add($"{branch.Remote}/{branch.Name}");
+ if (branch.IsLocal)
+ LocalBranches.Add(branch.Name);
+ else
+ RemoteBranches.Add($"{branch.Remote}/{branch.Name}");
}
- if (TrackingBranches.Count > 0)
- SelectedTrackingBranch = TrackingBranches[0];
+ if (LocalBranches.Count > 0)
+ SelectedBranch = LocalBranches[0];
+ else
+ SelectedBranch = string.Empty;
+
+ if (RemoteBranches.Count > 0)
+ SelectedTrackingBranch = RemoteBranches[0];
else
SelectedTrackingBranch = string.Empty;
@@ -81,25 +105,6 @@ namespace SourceGit.ViewModels
if (folders.Length > 0)
return new ValidationResult("Given path is not empty!!!");
}
-
- return ValidationResult.Success;
- }
-
- public static ValidationResult ValidateBranchName(string name, ValidationContext ctx)
- {
- if (string.IsNullOrEmpty(name))
- return ValidationResult.Success;
-
- var creator = ctx.ObjectInstance as AddWorktree;
- if (creator == null)
- return new ValidationResult("Missing runtime context to create branch!");
-
- foreach (var b in creator._repo.Branches)
- {
- var test = b.IsLocal ? b.Name : $"{b.Remote}/{b.Name}";
- if (test == name)
- return new ValidationResult("A branch with same name already exists!");
- }
return ValidationResult.Success;
}
@@ -113,7 +118,7 @@ namespace SourceGit.ViewModels
return Task.Run(() =>
{
- var succ = new Commands.Worktree(_repo.FullPath).Add(_path, _customName, tracking, SetProgressDescription);
+ var succ = new Commands.Worktree(_repo.FullPath).Add(_path, _selectedBranch, tracking, SetProgressDescription);
CallUIThread(() => _repo.SetWatcherEnabled(true));
return succ;
});
@@ -121,7 +126,8 @@ namespace SourceGit.ViewModels
private Repository _repo = null;
private string _path = string.Empty;
- private string _customName = string.Empty;
+ private bool _useExistingBranch = true;
+ private string _selectedBranch = string.Empty;
private bool _setTrackingBranch = false;
}
}
diff --git a/src/Views/AddWorktree.axaml b/src/Views/AddWorktree.axaml
index a393c055..4d75d136 100644
--- a/src/Views/AddWorktree.axaml
+++ b/src/Views/AddWorktree.axaml
@@ -13,7 +13,7 @@
-
+
-
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
-
-
+ Text="{Binding SelectedBranch, Mode=TwoWay}"
+ Watermark="{DynamicResource Text.AddWorktree.Name.Placeholder}"
+ IsEnabled="{Binding !UseExistingBranch, Mode=OneWay}"
+ IsVisible="{Binding !UseExistingBranch, Mode=OneWay}"/>
@@ -67,6 +94,10 @@
+
+