mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 04:34:59 +00:00
enhance: auto convert spaces with dashes while renaming a branch (#1088)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
7331167be2
commit
e430e847ff
3 changed files with 27 additions and 16 deletions
|
@ -32,9 +32,10 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
if (ctx.ObjectInstance is RenameBranch rename)
|
if (ctx.ObjectInstance is RenameBranch rename)
|
||||||
{
|
{
|
||||||
|
var fixedName = rename.FixName(name);
|
||||||
foreach (var b in rename._repo.Branches)
|
foreach (var b in rename._repo.Branches)
|
||||||
{
|
{
|
||||||
if (b.IsLocal && b != rename.Target && b.Name == name)
|
if (b.IsLocal && b != rename.Target && b.Name == fixedName)
|
||||||
{
|
{
|
||||||
return new ValidationResult("A branch with same name already exists!!!");
|
return new ValidationResult("A branch with same name already exists!!!");
|
||||||
}
|
}
|
||||||
|
@ -46,7 +47,8 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
public override Task<bool> Sure()
|
public override Task<bool> Sure()
|
||||||
{
|
{
|
||||||
if (_name == Target.Name)
|
var fixedName = FixName(_name);
|
||||||
|
if (fixedName == Target.Name)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
_repo.SetWatcherEnabled(false);
|
_repo.SetWatcherEnabled(false);
|
||||||
|
@ -55,7 +57,7 @@ namespace SourceGit.ViewModels
|
||||||
return Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
var oldName = Target.FullName;
|
var oldName = Target.FullName;
|
||||||
var succ = Commands.Branch.Rename(_repo.FullPath, Target.Name, _name);
|
var succ = Commands.Branch.Rename(_repo.FullPath, Target.Name, fixedName);
|
||||||
CallUIThread(() =>
|
CallUIThread(() =>
|
||||||
{
|
{
|
||||||
if (succ)
|
if (succ)
|
||||||
|
@ -65,7 +67,7 @@ namespace SourceGit.ViewModels
|
||||||
if (filter.Type == Models.FilterType.LocalBranch &&
|
if (filter.Type == Models.FilterType.LocalBranch &&
|
||||||
filter.Pattern.Equals(oldName, StringComparison.Ordinal))
|
filter.Pattern.Equals(oldName, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
filter.Pattern = $"refs/heads/{_name}";
|
filter.Pattern = $"refs/heads/{fixedName}";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +80,15 @@ namespace SourceGit.ViewModels
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string FixName(string name)
|
||||||
|
{
|
||||||
|
if (!name.Contains(' '))
|
||||||
|
return name;
|
||||||
|
|
||||||
|
var parts = name.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
return string.Join("-", parts);
|
||||||
|
}
|
||||||
|
|
||||||
private readonly Repository _repo;
|
private readonly Repository _repo;
|
||||||
private string _name;
|
private string _name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,15 +14,7 @@
|
||||||
<TextBlock FontSize="18"
|
<TextBlock FontSize="18"
|
||||||
Classes="bold"
|
Classes="bold"
|
||||||
Text="{DynamicResource Text.CreateBranch.Title}"/>
|
Text="{DynamicResource Text.CreateBranch.Title}"/>
|
||||||
<Grid Margin="0,16,0,0" ColumnDefinitions="140,*">
|
<Grid Margin="0,16,0,0" RowDefinitions="32,32,Auto,Auto,Auto" ColumnDefinitions="140,*">
|
||||||
<Grid.RowDefinitions>
|
|
||||||
<RowDefinition Height="32"/>
|
|
||||||
<RowDefinition Height="32"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
</Grid.RowDefinitions>
|
|
||||||
|
|
||||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||||
Margin="0,0,8,0"
|
Margin="0,0,8,0"
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:vm="using:SourceGit.ViewModels"
|
xmlns:vm="using:SourceGit.ViewModels"
|
||||||
xmlns:v="using:SourceGit.Views"
|
xmlns:v="using:SourceGit.Views"
|
||||||
|
xmlns:c="using:SourceGit.Converters"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="SourceGit.Views.RenameBranch"
|
x:Class="SourceGit.Views.RenameBranch"
|
||||||
x:DataType="vm:RenameBranch">
|
x:DataType="vm:RenameBranch">
|
||||||
|
@ -11,7 +12,7 @@
|
||||||
<TextBlock FontSize="18"
|
<TextBlock FontSize="18"
|
||||||
Classes="bold"
|
Classes="bold"
|
||||||
Text="{DynamicResource Text.RenameBranch}"/>
|
Text="{DynamicResource Text.RenameBranch}"/>
|
||||||
<Grid Margin="0,16,0,0" RowDefinitions="32,32" ColumnDefinitions="120,*">
|
<Grid Margin="0,16,0,0" RowDefinitions="32,32,Auto" ColumnDefinitions="120,*">
|
||||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||||
Margin="0,0,8,0"
|
Margin="0,0,8,0"
|
||||||
|
@ -32,6 +33,13 @@
|
||||||
Text="{Binding Name, Mode=TwoWay}"
|
Text="{Binding Name, Mode=TwoWay}"
|
||||||
Watermark="{DynamicResource Text.RenameBranch.Name.Placeholder}"
|
Watermark="{DynamicResource Text.RenameBranch.Name.Placeholder}"
|
||||||
v:AutoFocusBehaviour.IsEnabled="True"/>
|
v:AutoFocusBehaviour.IsEnabled="True"/>
|
||||||
|
|
||||||
|
<StackPanel Grid.Row="2" Grid.Column="1"
|
||||||
|
Orientation="Horizontal"
|
||||||
|
IsVisible="{Binding Name, Converter={x:Static c:StringConverters.ContainsSpaces}}">
|
||||||
|
<Path Width="10" Height="10" Data="{StaticResource Icons.Error}" Fill="DarkOrange"/>
|
||||||
|
<TextBlock Classes="small" Text="{DynamicResource Text.CreateBranch.Name.WarnSpace}" Margin="4,0,0,0"/>
|
||||||
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue