Skip to content

Commit 908faf3

Browse files
committed
code_review: PR #2394
- Auto-selecting remote branch when `Tracking remote branch` is enabled should also work for `Create New Branch` mode - Use `BranchOrTagNameTextBox` instead of `TextBox` for new branch name input control Signed-off-by: leo <longshuang@msn.cn>
1 parent 2fbe2b6 commit 908faf3

2 files changed

Lines changed: 38 additions & 13 deletions

File tree

‎src/ViewModels/AddWorktree.cs‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public override async Task<bool> Sure()
115115
using var lockWatcher = _repo.LockWatcher();
116116
ProgressDescription = "Adding worktree ...";
117117

118-
var branchName = _createNewBranch ? _newBranchName : (_selectedBranch?.FriendlyName ?? string.Empty);
118+
var branchName = GetBranchName(false);
119119
var tracking = (_setTrackingBranch && _selectedTrackingBranch != null) ? _selectedTrackingBranch.FriendlyName : string.Empty;
120120
var log = _repo.CreateLog("Add Worktree");
121121

@@ -134,12 +134,37 @@ private void AutoSelectTrackingBranch()
134134
if (!_setTrackingBranch || RemoteBranches.Count == 0)
135135
return;
136136

137-
var name = string.IsNullOrEmpty(_selectedBranch?.FriendlyName) ? System.IO.Path.GetFileName(_path.TrimEnd('/', '\\')) : _selectedBranch.FriendlyName;
138-
var remoteBranch = RemoteBranches.Find(b => b.Name.EndsWith(name, StringComparison.Ordinal));
139-
if (remoteBranch == null)
140-
remoteBranch = RemoteBranches[0];
137+
var name = GetBranchName(true);
138+
if (!string.IsNullOrEmpty(name))
139+
{
140+
var remoteBranch = RemoteBranches.Find(b => b.Name.EndsWith(name, StringComparison.Ordinal));
141+
if (remoteBranch != null)
142+
{
143+
SelectedTrackingBranch = remoteBranch;
144+
return;
145+
}
146+
}
147+
148+
SelectedTrackingBranch = RemoteBranches[0];
149+
}
150+
151+
private string GetBranchName(bool fallback)
152+
{
153+
do
154+
{
155+
if (!_createNewBranch)
156+
{
157+
if (_selectedBranch != null)
158+
return _selectedBranch.Name;
159+
160+
break;
161+
}
162+
163+
if (!string.IsNullOrEmpty(_newBranchName))
164+
return _newBranchName;
165+
} while (false);
141166

142-
SelectedTrackingBranch = remoteBranch;
167+
return fallback ? System.IO.Path.GetFileName(_path.TrimEnd('/', '\\')) : string.Empty;
143168
}
144169

145170
private Repository _repo = null;

‎src/Views/AddWorktree.axaml‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@
5454
HorizontalAlignment="Right" VerticalAlignment="Center"
5555
Margin="0,0,8,0"
5656
Text="{DynamicResource Text.AddWorktree.Name}"/>
57-
<TextBox Grid.Row="2" Grid.Column="1"
58-
Height="28"
59-
CornerRadius="3"
60-
Text="{Binding NewBranchName, Mode=TwoWay}"
61-
Watermark="{DynamicResource Text.AddWorktree.Name.Placeholder}"
62-
IsEnabled="{Binding CreateNewBranch, Mode=OneWay}"
63-
IsVisible="{Binding CreateNewBranch, Mode=OneWay}"/>
57+
<v:BranchOrTagNameTextBox Grid.Row="2" Grid.Column="1"
58+
Height="28"
59+
VerticalAlignment="Center"
60+
CornerRadius="3"
61+
Text="{Binding NewBranchName, Mode=TwoWay}"
62+
Watermark="{DynamicResource Text.AddWorktree.Name.Placeholder}"
63+
IsVisible="{Binding CreateNewBranch, Mode=OneWay}"/>
6464
<v:BranchSelector Grid.Row="2" Grid.Column="1"
6565
Height="28"
6666
VerticalAlignment="Center" HorizontalAlignment="Stretch"

0 commit comments

Comments
 (0)