mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-21 21:30:37 +08:00
enhance: auto select tracking branch after Tracking remote branch option is toggled while creating worktree (#1983)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
@@ -51,7 +52,11 @@ namespace SourceGit.ViewModels
|
||||
public bool SetTrackingBranch
|
||||
{
|
||||
get => _setTrackingBranch;
|
||||
set => SetProperty(ref _setTrackingBranch, value);
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _setTrackingBranch, value))
|
||||
AutoSelectTrackingBranch();
|
||||
}
|
||||
}
|
||||
|
||||
public string SelectedTrackingBranch
|
||||
@@ -73,11 +78,6 @@ namespace SourceGit.ViewModels
|
||||
else
|
||||
RemoteBranches.Add(branch.FriendlyName);
|
||||
}
|
||||
|
||||
if (RemoteBranches.Count > 0)
|
||||
SelectedTrackingBranch = RemoteBranches[0];
|
||||
else
|
||||
SelectedTrackingBranch = string.Empty;
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateWorktreePath(string path, ValidationContext ctx)
|
||||
@@ -123,6 +123,23 @@ namespace SourceGit.ViewModels
|
||||
return succ;
|
||||
}
|
||||
|
||||
private void AutoSelectTrackingBranch()
|
||||
{
|
||||
if (!_setTrackingBranch || RemoteBranches.Count == 0)
|
||||
return;
|
||||
|
||||
var name = string.IsNullOrEmpty(_selectedBranch) ? System.IO.Path.GetFileName(_path.TrimEnd('/', '\\')) : _selectedBranch;
|
||||
var remoteBranch = RemoteBranches.Find(b => b.Substring(b.IndexOf('/') + 1).Equals(name, StringComparison.Ordinal));
|
||||
if (string.IsNullOrEmpty(remoteBranch))
|
||||
remoteBranch = RemoteBranches[0];
|
||||
|
||||
if (!remoteBranch.Equals(SelectedTrackingBranch, StringComparison.Ordinal))
|
||||
{
|
||||
SelectedTrackingBranch = remoteBranch;
|
||||
OnPropertyChanged(nameof(SelectedTrackingBranch));
|
||||
}
|
||||
}
|
||||
|
||||
private Repository _repo = null;
|
||||
private string _path = string.Empty;
|
||||
private bool _createNewBranch = true;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="using:SourceGit.ViewModels"
|
||||
xmlns:c="using:SourceGit.Converters"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="SourceGit.Views.AddWorktree"
|
||||
x:DataType="vm:AddWorktree">
|
||||
@@ -17,7 +18,7 @@
|
||||
Text="{DynamicResource Text.AddWorktree}"/>
|
||||
</StackPanel>
|
||||
|
||||
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,Auto,32" ColumnDefinitions="150,*">
|
||||
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,Auto,Auto" ColumnDefinitions="150,*">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
@@ -101,8 +102,10 @@
|
||||
</ComboBox>
|
||||
|
||||
<CheckBox Grid.Row="4" Grid.Column="1"
|
||||
Height="32"
|
||||
Content="{DynamicResource Text.AddWorktree.Tracking.Toggle}"
|
||||
IsChecked="{Binding SetTrackingBranch, Mode=TwoWay}"/>
|
||||
IsChecked="{Binding SetTrackingBranch, Mode=TwoWay}"
|
||||
IsVisible="{Binding RemoteBranches, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
Reference in New Issue
Block a user