8000 feature: add `Do Nothing` option to deal with local changes before cr… · sourcegit-scm/sourcegit@a52124c · GitHub
[go: up one dir, main page]

Skip to content

Commit a52124c

Browse files
committed
feature: add Do Nothing option to deal with local changes before creating a new branch (#143)
1 parent 9f0ec7d commit a52124c

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

src/Converters/EnumConverters.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Avalonia.Controls.Converters;
2+
3+
namespace SourceGit.Converters
4+
{
5+
public static class EnumConverters
6+
{
7+
public static readonly EnumToBoolConverter Equals = new EnumToBoolConverter();
8+
}
9+
}

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
<x:String x:Key="Text.CreateBranch.LocalChanges" xml:space="preserve">Local Changes :</x:String>
112112
<x:String x:Key="Text.CreateBranch.LocalChanges.Discard" xml:space="preserve">Discard</x:String>
113113
<x:String x:Key="Text.CreateBranch.LocalChanges.StashAndReply" xml:space="preserve">Stash &amp; Reapply</x:String>
114+
<x:String x:Key="Text.CreateBranch.LocalChanges.DoNothing" xml:space="preserve">Do Nothing</x:String>
114115
<x:String x:Key="Text.CreateBranch.Name" xml:space="preserve">New Branch Name :</x:String>
115116
<x:String x:Key="Text.CreateBranch.Name.Placeholder" xml:space="preserve">Enter branch name.</x:String>
116117
<x:String x:Key="Text.CreateBranch.Title" xml:space="preserve">Create Local Branch</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@
109109
<x:String x:Key="Text.CreateBranch.BasedOn" xml:space="preserve">新分支基于 :</x:String>
110110
<x:String x:Key="Text.CreateBranch.Checkout" xml:space="preserve">完成后切换到新分支</x:String>
111111
<x:String x:Key="Text.CreateBranch.LocalChanges" xml:space="preserve">未提交更改 :</x:String>
112-
<x:String x:Key="Text.CreateBranch.LocalChanges.Discard" xml:space="preserve">忽略</x:String>
113-
<x:String x:Key="Text.CreateBranch.LocalChanges.StashAndReply" xml:space="preserve">贮藏(stash)并自动恢复</x:String>
112+
<x:String x:Key="Text.CreateBranch.LocalChanges.Discard" xml:space="preserve">放弃所有</x:String>
113+
<x:String x:Key="Text.CreateBranch.LocalChanges.StashAndReply" xml:space="preserve">贮藏并自动恢复</x:S 8000 tring>
114+
<x:String x:Key="Text.CreateBranch.LocalChanges.DoNothing" xml:space="preserve">GIT默认</x:String>
114115
<x:String x:Key="Text.CreateBranch.Name" xml:space="preserve">新分支名 :</x:String>
115116
<x:String x:Key="Text.CreateBranch.Name.Placeholder" xml:space="preserve">填写分支名称。</x:String>
116117
<x:String x:Key="Text.CreateBranch.Title" xml:space="preserve">创建本地分支</x:String>

src/ViewModels/CreateBranch.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33

44
namespace SourceGit.ViewModels
55
{
6+
public enum BeforeCreateBranchAction
7+
{
8+
StashAndReaply,
9+
Discard,
10+
DoNothing,
11+
}
12+
613
public class CreateBranch : Popup
714
{
815
[Required(ErrorMessage = "Branch name is required!")]
@@ -19,14 +26,14 @@ public object BasedOn
1926
get;
2027
private set;
2128
}
22-
23-
public bool CheckoutAfterCreated
29+
30+
public BeforeCreateBranchAction PreAction
2431
{
25-
get;
26-
set;
27-
} = true;
28-
29-
public bool AutoStash
32+
get => _preAction;
33+
set => SetProperty(ref _preAction, value);
34+
}
35+
36+
public bool CheckoutAfterCreated
3037
{
3138
get;
3239
set;
@@ -90,7 +97,7 @@ public override Task<bool> Sure()
9097
bool needPopStash = false;
9198
if (_repo.WorkingCopyChangesCount > 0)
9299
{
93-
if (AutoStash)
100+
if (_preAction == BeforeCreateBranchAction.StashAndReaply)
94101
{
95102
SetProgressDescription("Adding untracked changes...");
96103
var succ = new Commands.Add(_repo.FullPath).Exec();
@@ -108,7 +115,7 @@ public override Task<bool> Sure()
108115

109116
needPopStash = true;
110117
}
111-
else
118+
else if (_preAction == BeforeCreateBranchAction.Discard)
112119
{
113120
SetProgressDescription("Discard local changes...");
114121
Commands.Discard.All(_repo.FullPath);
@@ -137,5 +144,6 @@ public override Task<bool> Sure()
137144
private readonly Repository _repo = null;
138145
private string _name = null;
139146
private readonly string _baseOnRevision = null;
147+
private BeforeCreateBranchAction _preAction = BeforeCreateBranchAction.StashAndReaply;
140148
}
141149
}

src/Views/CreateBranch.axaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,15 @@
6262
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
6363
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.StashAndReply}"
6464
GroupName="LocalChanges"
65-
IsChecked="{Binding AutoStash, Mode=TwoWay}"/>
65+
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={x:Static c:EnumConverters.Equals}, ConverterParameter={x:Static vm:BeforeCreateBranchAction.StashAndReaply}}"/>
6666
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.Discard}"
6767
GroupName="LocalChanges"
68-
Margin="8,0,0,0"/>
68+
Margin="8,0,0,0"
69+
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={x:Static c:EnumConverters.Equals}, ConverterParameter={x:Static vm:BeforeCreateBranchAction.Discard}}"/>
70+
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.DoNothing}"
71+
GroupName="LocalChanges"
72+
Margin="8,0,0,0"
73+
IsChecked="{Binding PreAction, Mode=TwoWay, Converter={x:Static c:EnumConverters.Equals}, ConverterParameter={x:Static vm:BeforeCreateBranchAction.DoNothing}}"/>
6974
</StackPanel>
7075

7176
<CheckBox Grid.Row="3" Grid.Column="1"

0 commit comments

Comments
 (0)
0