mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
feature: add Do Nothing
option to deal with local changes before creating a new branch (#143)
This commit is contained in:
parent
9f0ec7d60d
commit
a52124c479
5 changed files with 37 additions and 13 deletions
9
src/Converters/EnumConverters.cs
Normal file
9
src/Converters/EnumConverters.cs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
using Avalonia.Controls.Converters;
|
||||||
|
|
||||||
|
namespace SourceGit.Converters
|
||||||
|
{
|
||||||
|
public static class EnumConverters
|
||||||
|
{
|
||||||
|
public static readonly EnumToBoolConverter Equals = new EnumToBoolConverter();
|
||||||
|
}
|
||||||
|
}
|
|
@ -111,6 +111,7 @@
|
||||||
<x:String x:Key="Text.CreateBranch.LocalChanges" xml:space="preserve">Local Changes :</x:String>
|
<x:String x:Key="Text.CreateBranch.LocalChanges" xml:space="preserve">Local Changes :</x:String>
|
||||||
<x:String x:Key="Text.CreateBranch.LocalChanges.Discard" xml:space="preserve">Discard</x:String>
|
<x:String x:Key="Text.CreateBranch.LocalChanges.Discard" xml:space="preserve">Discard</x:String>
|
||||||
<x:String x:Key="Text.CreateBranch.LocalChanges.StashAndReply" xml:space="preserve">Stash & Reapply</x:String>
|
<x:String x:Key="Text.CreateBranch.LocalChanges.StashAndReply" xml:space="preserve">Stash & Reapply</x:String>
|
||||||
|
<x:String x:Key="Text.CreateBranch.LocalChanges.DoNothing" xml:space="preserve">Do Nothing</x:String>
|
||||||
<x:String x:Key="Text.CreateBranch.Name" xml:space="preserve">New Branch Name :</x:String>
|
<x:String x:Key="Text.CreateBranch.Name" xml:space="preserve">New Branch Name :</x:String>
|
||||||
<x:String x:Key="Text.CreateBranch.Name.Placeholder" xml:space="preserve">Enter branch name.</x:String>
|
<x:String x:Key="Text.CreateBranch.Name.Placeholder" xml:space="preserve">Enter branch name.</x:String>
|
||||||
<x:String x:Key="Text.CreateBranch.Title" xml:space="preserve">Create Local Branch</x:String>
|
<x:String x:Key="Text.CreateBranch.Title" xml:space="preserve">Create Local Branch</x:String>
|
||||||
|
|
|
@ -109,8 +109,9 @@
|
||||||
<x:String x:Key="Text.CreateBranch.BasedOn" xml:space="preserve">新分支基于 :</x:String>
|
<x:String x:Key="Text.CreateBranch.BasedOn" xml:space="preserve">新分支基于 :</x:String>
|
||||||
<x:String x:Key="Text.CreateBranch.Checkout" xml:space="preserve">完成后切换到新分支</x:String>
|
<x:String x:Key="Text.CreateBranch.Checkout" xml:space="preserve">完成后切换到新分支</x:String>
|
||||||
<x:String x:Key="Text.CreateBranch.LocalChanges" xml:space="preserve">未提交更改 :</x:String>
|
<x:String x:Key="Text.CreateBranch.LocalChanges" xml:space="preserve">未提交更改 :</x:String>
|
||||||
<x:String x:Key="Text.CreateBranch.LocalChanges.Discard" xml:space="preserve">忽略</x:String>
|
<x:String x:Key="Text.CreateBranch.LocalChanges.Discard" xml:space="preserve">放弃所有</x:String>
|
||||||
<x:String x:Key="Text.CreateBranch.LocalChanges.StashAndReply" xml:space="preserve">贮藏(stash)并自动恢复</x:String>
|
<x:String x:Key="Text.CreateBranch.LocalChanges.StashAndReply" xml:space="preserve">贮藏并自动恢复</x:String>
|
||||||
|
<x:String x:Key="Text.CreateBranch.LocalChanges.DoNothing" xml:space="preserve">GIT默认</x:String>
|
||||||
<x:String x:Key="Text.CreateBranch.Name" xml:space="preserve">新分支名 :</x:String>
|
<x:String x:Key="Text.CreateBranch.Name" xml:space="preserve">新分支名 :</x:String>
|
||||||
<x:String x:Key="Text.CreateBranch.Name.Placeholder" xml:space="preserve">填写分支名称。</x:String>
|
<x:String x:Key="Text.CreateBranch.Name.Placeholder" xml:space="preserve">填写分支名称。</x:String>
|
||||||
<x:String x:Key="Text.CreateBranch.Title" xml:space="preserve">创建本地分支</x:String>
|
<x:String x:Key="Text.CreateBranch.Title" xml:space="preserve">创建本地分支</x:String>
|
||||||
|
|
|
@ -3,6 +3,13 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels
|
namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
|
public enum BeforeCreateBranchAction
|
||||||
|
{
|
||||||
|
StashAndReaply,
|
||||||
|
Discard,
|
||||||
|
DoNothing,
|
||||||
|
}
|
||||||
|
|
||||||
public class CreateBranch : Popup
|
public class CreateBranch : Popup
|
||||||
{
|
{
|
||||||
[Required(ErrorMessage = "Branch name is required!")]
|
[Required(ErrorMessage = "Branch name is required!")]
|
||||||
|
@ -19,14 +26,14 @@ namespace SourceGit.ViewModels
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CheckoutAfterCreated
|
public BeforeCreateBranchAction PreAction
|
||||||
{
|
{
|
||||||
get;
|
get => _preAction;
|
||||||
set;
|
set => SetProperty(ref _preAction, value);
|
||||||
} = true;
|
}
|
||||||
|
|
||||||
public bool AutoStash
|
public bool CheckoutAfterCreated
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
set;
|
set;
|
||||||
|
@ -90,7 +97,7 @@ namespace SourceGit.ViewModels
|
||||||
bool needPopStash = false;
|
bool needPopStash = false;
|
||||||
if (_repo.WorkingCopyChangesCount > 0)
|
if (_repo.WorkingCopyChangesCount > 0)
|
||||||
{
|
{
|
||||||
if (AutoStash)
|
if (_preAction == BeforeCreateBranchAction.StashAndReaply)
|
||||||
{
|
{
|
||||||
SetProgressDescription("Adding untracked changes...");
|
SetProgressDescription("Adding untracked changes...");
|
||||||
var succ = new Commands.Add(_repo.FullPath).Exec();
|
var succ = new Commands.Add(_repo.FullPath).Exec();
|
||||||
|
@ -108,7 +115,7 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
needPopStash = true;
|
needPopStash = true;
|
||||||
}
|
}
|
||||||
else
|
else if (_preAction == BeforeCreateBranchAction.Discard)
|
||||||
{
|
{
|
||||||
SetProgressDescription("Discard local changes...");
|
SetProgressDescription("Discard local changes...");
|
||||||
Commands.Discard.All(_repo.FullPath);
|
Commands.Discard.All(_repo.FullPath);
|
||||||
|
@ -137,5 +144,6 @@ namespace SourceGit.ViewModels
|
||||||
private readonly Repository _repo = null;
|
private readonly Repository _repo = null;
|
||||||
private string _name = null;
|
private string _name = null;
|
||||||
private readonly string _baseOnRevision = null;
|
private readonly string _baseOnRevision = null;
|
||||||
|
private BeforeCreateBranchAction _preAction = BeforeCreateBranchAction.StashAndReaply;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,10 +62,15 @@
|
||||||
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
|
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
|
||||||
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.StashAndReply}"
|
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.StashAndReply}"
|
||||||
GroupName="LocalChanges"
|
GroupName="LocalChanges"
|
||||||
IsChecked="{Binding AutoStash, Mode=TwoWay}"/>
|
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={x:Static c:EnumConverters.Equals}, ConverterParameter={x:Static vm:BeforeCreateBranchAction.StashAndReaply}}"/>
|
||||||
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.Discard}"
|
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.Discard}"
|
||||||
GroupName="LocalChanges"
|
GroupName="LocalChanges"
|
||||||
Margin="8,0,0,0"/>
|
Margin="8,0,0,0"
|
||||||
|
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={x:Static c:EnumConverters.Equals}, ConverterParameter={x:Static vm:BeforeCreateBranchAction.Discard}}"/>
|
||||||
|
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.DoNothing}"
|
||||||
|
GroupName="LocalChanges"
|
||||||
|
Margin="8,0,0,0"
|
||||||
|
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={x:Static c:EnumConverters.Equals}, ConverterParameter={x:Static vm:BeforeCreateBranchAction.DoNothing}}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
<CheckBox Grid.Row="3" Grid.Column="1"
|
<CheckBox Grid.Row="3" Grid.Column="1"
|
||||||
|
|
Loading…
Reference in a new issue