diff --git a/GitUI/CommandsDialogs/WorktreeDialog/FormCreateWorktree.Designer.cs b/GitUI/CommandsDialogs/WorktreeDialog/FormCreateWorktree.Designer.cs index 2d31325c9b8..5c1f1e64e4d 100644 --- a/GitUI/CommandsDialogs/WorktreeDialog/FormCreateWorktree.Designer.cs +++ b/GitUI/CommandsDialogs/WorktreeDialog/FormCreateWorktree.Designer.cs @@ -72,6 +72,7 @@ private void InitializeComponent() // radioButtonCheckoutExistingBranch // this.radioButtonCheckoutExistingBranch.AutoSize = true; + this.radioButtonCheckoutExistingBranch.Checked = true; this.radioButtonCheckoutExistingBranch.Location = new System.Drawing.Point(3, 3); this.radioButtonCheckoutExistingBranch.Name = "radioButtonCheckoutExistingBranch"; this.radioButtonCheckoutExistingBranch.Size = new System.Drawing.Size(165, 17); diff --git a/GitUI/CommandsDialogs/WorktreeDialog/FormCreateWorktree.cs b/GitUI/CommandsDialogs/WorktreeDialog/FormCreateWorktree.cs index 2dc011266e3..44b24b74095 100644 --- a/GitUI/CommandsDialogs/WorktreeDialog/FormCreateWorktree.cs +++ b/GitUI/CommandsDialogs/WorktreeDialog/FormCreateWorktree.cs @@ -9,7 +9,7 @@ public sealed partial class FormCreateWorktree : GitModuleForm private readonly AsyncLoader _branchesLoader = new(); private readonly char[] _invalidCharsInPath = Path.GetInvalidFileNameChars(); - private string? _initialDirectoryPath; + private readonly string? _initialDirectoryPath; public string WorktreeDirectory => newWorktreeDirectory.Text; public bool OpenWorktree => openWorktreeCheckBox.Checked; @@ -22,22 +22,19 @@ private FormCreateWorktree() InitializeComponent(); } - public FormCreateWorktree(GitUICommands commands) + public FormCreateWorktree(GitUICommands commands, string? path) : base(commands) { InitializeComponent(); InitializeComplete(); + _initialDirectoryPath = path; } private void FormCreateWorktree_Load(object sender, EventArgs e) { - _initialDirectoryPath = GetWorktreeDirectory(); LoadBranchesAsync(); - string GetWorktreeDirectory() - { - return UICommands.GitModule.WorkingDir.TrimEnd('\\', '/'); - } + UpdateWorktreePathAndValidateWorktreeOptions(); void LoadBranchesAsync() { @@ -160,6 +157,9 @@ private void ValidateWorktreeOptions(object sender, EventArgs e) } private void UpdateWorktreePathAndValidateWorktreeOptions(object sender, EventArgs e) + => UpdateWorktreePathAndValidateWorktreeOptions(); + + private void UpdateWorktreePathAndValidateWorktreeOptions() { UpdateWorktreePath(); @@ -170,15 +170,12 @@ private void UpdateWorktreePathAndValidateWorktreeOptions(object sender, EventAr void UpdateWorktreePath() { var branchNameNormalized = NormalizeBranchName(radioButtonCheckoutExistingBranch.Checked - ? ((IGitRef)comboBoxBranches.SelectedItem).Name + ? ((IGitRef)comboBoxBranches.SelectedItem)?.Name ?? string.Empty : textBoxNewBranchName.Text); newWorktreeDirectory.Text = $"{_initialDirectoryPath}_{branchNameNormalized}"; } - string NormalizeBranchName(string branchName) - { - return string.Join("_", branchName.Split(_invalidCharsInPath, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.'); - } + string NormalizeBranchName(string branchName) => string.Join("_", branchName.Split(_invalidCharsInPath, StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.'); } } } diff --git a/GitUI/CommandsDialogs/WorktreeDialog/FormManageWorktree.cs b/GitUI/CommandsDialogs/WorktreeDialog/FormManageWorktree.cs index efc8b35b9f2..1f010060036 100644 --- a/GitUI/CommandsDialogs/WorktreeDialog/FormManageWorktree.cs +++ b/GitUI/CommandsDialogs/WorktreeDialog/FormManageWorktree.cs @@ -246,7 +246,7 @@ private bool IsCurrentlyOpenedWorktree(WorkTree workTree) private void buttonCreateNewWorktree_Click(object sender, EventArgs e) { - using FormCreateWorktree formCreateWorktree = new(UICommands); + using FormCreateWorktree formCreateWorktree = new(UICommands, _worktrees[0].Path); DialogResult dialogResult = formCreateWorktree.ShowDialog(this); if (dialogResult != DialogResult.OK) {