From a52124c479e44235cb1ee946880ed69e9fa58e70 Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 25 May 2024 19:40:30 +0800 Subject: [PATCH] feature: add `Do Nothing` option to deal with local changes before creating a new branch (#143) --- src/Converters/EnumConverters.cs | 9 +++++++++ src/Resources/Locales/en_US.axaml | 1 + src/Resources/Locales/zh_CN.axaml | 5 +++-- src/ViewModels/CreateBranch.cs | 26 +++++++++++++++++--------- src/Views/CreateBranch.axaml | 9 +++++++-- 5 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 src/Converters/EnumConverters.cs diff --git a/src/Converters/EnumConverters.cs b/src/Converters/EnumConverters.cs new file mode 100644 index 00000000..4b719cba --- /dev/null +++ b/src/Converters/EnumConverters.cs @@ -0,0 +1,9 @@ +using Avalonia.Controls.Converters; + +namespace SourceGit.Converters +{ + public static class EnumConverters + { + public static readonly EnumToBoolConverter Equals = new EnumToBoolConverter(); + } +} diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 7f03b873..a9971637 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -111,6 +111,7 @@ Local Changes : Discard Stash & Reapply + Do Nothing New Branch Name : Enter branch name. Create Local Branch diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index a1ca44f6..7b496f75 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -109,8 +109,9 @@ 新分支基于 : 完成后切换到新分支 未提交更改 : - 忽略 - 贮藏(stash)并自动恢复 + 放弃所有 + 贮藏并自动恢复 + GIT默认 新分支名 : 填写分支名称。 创建本地分支 diff --git a/src/ViewModels/CreateBranch.cs b/src/ViewModels/CreateBranch.cs index 15761f03..c6bc43c9 100644 --- a/src/ViewModels/CreateBranch.cs +++ b/src/ViewModels/CreateBranch.cs @@ -3,6 +3,13 @@ using System.Threading.Tasks; namespace SourceGit.ViewModels { + public enum BeforeCreateBranchAction + { + StashAndReaply, + Discard, + DoNothing, + } + public class CreateBranch : Popup { [Required(ErrorMessage = "Branch name is required!")] @@ -19,14 +26,14 @@ namespace SourceGit.ViewModels get; private set; } - - public bool CheckoutAfterCreated + + public BeforeCreateBranchAction PreAction { - get; - set; - } = true; - - public bool AutoStash + get => _preAction; + set => SetProperty(ref _preAction, value); + } + + public bool CheckoutAfterCreated { get; set; @@ -90,7 +97,7 @@ namespace SourceGit.ViewModels bool needPopStash = false; if (_repo.WorkingCopyChangesCount > 0) { - if (AutoStash) + if (_preAction == BeforeCreateBranchAction.StashAndReaply) { SetProgressDescription("Adding untracked changes..."); var succ = new Commands.Add(_repo.FullPath).Exec(); @@ -108,7 +115,7 @@ namespace SourceGit.ViewModels needPopStash = true; } - else + else if (_preAction == BeforeCreateBranchAction.Discard) { SetProgressDescription("Discard local changes..."); Commands.Discard.All(_repo.FullPath); @@ -137,5 +144,6 @@ namespace SourceGit.ViewModels private readonly Repository _repo = null; private string _name = null; private readonly string _baseOnRevision = null; + private BeforeCreateBranchAction _preAction = BeforeCreateBranchAction.StashAndReaply; } } diff --git a/src/Views/CreateBranch.axaml b/src/Views/CreateBranch.axaml index 3028f81c..3089f9e4 100644 --- a/src/Views/CreateBranch.axaml +++ b/src/Views/CreateBranch.axaml @@ -62,10 +62,15 @@ + IsChecked="{Binding PreAction, Mode=TwoWay, Converter={x:Static c:EnumConverters.Equals}, ConverterParameter={x:Static vm:BeforeCreateBranchAction.StashAndReaply}}"/> + Margin="8,0,0,0" + IsChecked="{Binding PreAction, Mode=TwoWay, Converter={x:Static c:EnumConverters.Equals}, ConverterParameter={x:Static vm:BeforeCreateBranchAction.Discard}}"/> +