mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
enhance: makes Create New Branch
option as the default selected mode for adding new worktree
This commit is contained in:
parent
db8e534a0a
commit
3e54ab0227
3 changed files with 30 additions and 29 deletions
|
@ -62,7 +62,7 @@ namespace SourceGit.Commands
|
||||||
return worktrees;
|
return worktrees;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Add(string fullpath, string name, string tracking, Action<string> outputHandler)
|
public bool Add(string fullpath, string name, bool createNew, string tracking, Action<string> outputHandler)
|
||||||
{
|
{
|
||||||
Args = "worktree add ";
|
Args = "worktree add ";
|
||||||
|
|
||||||
|
@ -70,7 +70,12 @@ namespace SourceGit.Commands
|
||||||
Args += "--track ";
|
Args += "--track ";
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(name))
|
if (!string.IsNullOrEmpty(name))
|
||||||
Args += $"-B {name} ";
|
{
|
||||||
|
if (createNew)
|
||||||
|
Args += $"-b {name} ";
|
||||||
|
else
|
||||||
|
Args += $"-B {name} ";
|
||||||
|
}
|
||||||
|
|
||||||
Args += $"\"{fullpath}\" ";
|
Args += $"\"{fullpath}\" ";
|
||||||
|
|
||||||
|
|
|
@ -15,17 +15,17 @@ namespace SourceGit.ViewModels
|
||||||
set => SetProperty(ref _path, value);
|
set => SetProperty(ref _path, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool UseExistingBranch
|
public bool CreateNewBranch
|
||||||
{
|
{
|
||||||
get => _useExistingBranch;
|
get => _createNewBranch;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _useExistingBranch, value, true))
|
if (SetProperty(ref _createNewBranch, value, true))
|
||||||
{
|
{
|
||||||
if (value)
|
if (value)
|
||||||
SelectedBranch = LocalBranches.Count > 0 ? LocalBranches[0] : string.Empty;
|
|
||||||
else
|
|
||||||
SelectedBranch = string.Empty;
|
SelectedBranch = string.Empty;
|
||||||
|
else
|
||||||
|
SelectedBranch = LocalBranches.Count > 0 ? LocalBranches[0] : string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,11 +74,6 @@ namespace SourceGit.ViewModels
|
||||||
RemoteBranches.Add($"{branch.Remote}/{branch.Name}");
|
RemoteBranches.Add($"{branch.Remote}/{branch.Name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LocalBranches.Count > 0)
|
|
||||||
SelectedBranch = LocalBranches[0];
|
|
||||||
else
|
|
||||||
SelectedBranch = string.Empty;
|
|
||||||
|
|
||||||
if (RemoteBranches.Count > 0)
|
if (RemoteBranches.Count > 0)
|
||||||
SelectedTrackingBranch = RemoteBranches[0];
|
SelectedTrackingBranch = RemoteBranches[0];
|
||||||
else
|
else
|
||||||
|
@ -114,11 +109,12 @@ namespace SourceGit.ViewModels
|
||||||
_repo.SetWatcherEnabled(false);
|
_repo.SetWatcherEnabled(false);
|
||||||
ProgressDescription = "Adding worktree ...";
|
ProgressDescription = "Adding worktree ...";
|
||||||
|
|
||||||
|
var branchName = _selectedBranch;
|
||||||
var tracking = _setTrackingBranch ? SelectedTrackingBranch : string.Empty;
|
var tracking = _setTrackingBranch ? SelectedTrackingBranch : string.Empty;
|
||||||
|
|
||||||
return Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
var succ = new Commands.Worktree(_repo.FullPath).Add(_path, _selectedBranch, tracking, SetProgressDescription);
|
var succ = new Commands.Worktree(_repo.FullPath).Add(_path, branchName, _createNewBranch, tracking, SetProgressDescription);
|
||||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||||
return succ;
|
return succ;
|
||||||
});
|
});
|
||||||
|
@ -126,7 +122,7 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
private Repository _repo = null;
|
private Repository _repo = null;
|
||||||
private string _path = string.Empty;
|
private string _path = string.Empty;
|
||||||
private bool _useExistingBranch = true;
|
private bool _createNewBranch = true;
|
||||||
private string _selectedBranch = string.Empty;
|
private string _selectedBranch = string.Empty;
|
||||||
private bool _setTrackingBranch = false;
|
private bool _setTrackingBranch = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,25 +36,32 @@
|
||||||
Margin="0,0,8,0"
|
Margin="0,0,8,0"
|
||||||
Text="{DynamicResource Text.AddWorktree.WhatToCheckout}"/>
|
Text="{DynamicResource Text.AddWorktree.WhatToCheckout}"/>
|
||||||
<StackPanel Grid.Row="1" Grid.Column="1" Height="32" Orientation="Horizontal">
|
<StackPanel Grid.Row="1" Grid.Column="1" Height="32" Orientation="Horizontal">
|
||||||
<RadioButton Content="{DynamicResource Text.AddWorktree.WhatToCheckout.Existing}"
|
|
||||||
GroupName="LocalChanges"
|
|
||||||
IsChecked="{Binding UseExistingBranch, Mode=TwoWay}" />
|
|
||||||
<RadioButton Content="{DynamicResource Text.AddWorktree.WhatToCheckout.CreateNew}"
|
<RadioButton Content="{DynamicResource Text.AddWorktree.WhatToCheckout.CreateNew}"
|
||||||
GroupName="LocalChanges"
|
GroupName="WhatToCheckout"
|
||||||
Margin="8,0,0,0" />
|
IsChecked="{Binding CreateNewBranch, Mode=TwoWay}"/>
|
||||||
|
<RadioButton Content="{DynamicResource Text.AddWorktree.WhatToCheckout.Existing}"
|
||||||
|
GroupName="WhatToCheckout"
|
||||||
|
Margin="8,0,0,0"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<TextBlock Grid.Row="2" Grid.Column="0"
|
<TextBlock Grid.Row="2" Grid.Column="0"
|
||||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||||
Margin="0,0,8,0"
|
Margin="0,0,8,0"
|
||||||
Text="{DynamicResource Text.AddWorktree.Name}"/>
|
Text="{DynamicResource Text.AddWorktree.Name}"/>
|
||||||
|
<TextBox Grid.Row="2" Grid.Column="1"
|
||||||
|
Height="28"
|
||||||
|
CornerRadius="3"
|
||||||
|
Text="{Binding SelectedBranch, Mode=TwoWay}"
|
||||||
|
Watermark="{DynamicResource Text.AddWorktree.Name.Placeholder}"
|
||||||
|
IsEnabled="{Binding CreateNewBranch, Mode=OneWay}"
|
||||||
|
IsVisible="{Binding CreateNewBranch, Mode=OneWay}"/>
|
||||||
<ComboBox Grid.Row="2" Grid.Column="1"
|
<ComboBox Grid.Row="2" Grid.Column="1"
|
||||||
Height="28" Padding="8,0"
|
Height="28" Padding="8,0"
|
||||||
VerticalAlignment="Center" HorizontalAlignment="Stretch"
|
VerticalAlignment="Center" HorizontalAlignment="Stretch"
|
||||||
ItemsSource="{Binding LocalBranches}"
|
ItemsSource="{Binding LocalBranches}"
|
||||||
SelectedItem="{Binding SelectedBranch, Mode=TwoWay}"
|
SelectedItem="{Binding SelectedBranch, Mode=TwoWay}"
|
||||||
IsEnabled="{Binding UseExistingBranch, Mode=OneWay}"
|
IsEnabled="{Binding !CreateNewBranch, Mode=OneWay}"
|
||||||
IsVisible="{Binding UseExistingBranch, Mode=OneWay}">
|
IsVisible="{Binding !CreateNewBranch, Mode=OneWay}">
|
||||||
<ComboBox.ItemTemplate>
|
<ComboBox.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center">
|
<StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Center">
|
||||||
|
@ -63,14 +70,7 @@
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ComboBox.ItemTemplate>
|
</ComboBox.ItemTemplate>
|
||||||
</ComboBox>
|
</ComboBox>
|
||||||
<TextBox Grid.Row="2" Grid.Column="1"
|
|
||||||
Height="28"
|
|
||||||
CornerRadius="3"
|
|
||||||
Text="{Binding SelectedBranch, Mode=TwoWay}"
|
|
||||||
Watermark="{DynamicResource Text.AddWorktree.Name.Placeholder}"
|
|
||||||
IsEnabled="{Binding !UseExistingBranch, Mode=OneWay}"
|
|
||||||
IsVisible="{Binding !UseExistingBranch, Mode=OneWay}"/>
|
|
||||||
|
|
||||||
<Border Grid.Row="3" Grid.Column="0"
|
<Border Grid.Row="3" Grid.Column="0"
|
||||||
Height="32"
|
Height="32"
|
||||||
|
|
Loading…
Reference in a new issue