Skip to content

Commit

Permalink
feature: add Do Nothing option to deal with local changes before cr…
Browse files Browse the repository at this point in the history
…eating a new branch (#143)
  • Loading branch information
love-linger committed May 25, 2024
1 parent 9f0ec7d commit a52124c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
9 changes: 9 additions & 0 deletions src/Converters/EnumConverters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Avalonia.Controls.Converters;

namespace SourceGit.Converters
{
public static class EnumConverters
{
public static readonly EnumToBoolConverter Equals = new EnumToBoolConverter();

Check warning on line 7 in src/Converters/EnumConverters.cs

View workflow job for this annotation

GitHub Actions / Build Windows x64

'EnumConverters.Equals' hides inherited member 'object.Equals(object?)'. Use the new keyword if hiding was intended.

Check warning on line 7 in src/Converters/EnumConverters.cs

View workflow job for this annotation

GitHub Actions / Build Windows x64

'EnumConverters.Equals' hides inherited member 'object.Equals(object?)'. Use the new keyword if hiding was intended.

Check warning on line 7 in src/Converters/EnumConverters.cs

View workflow job for this annotation

GitHub Actions / Build Windows x64

'EnumConverters.Equals' hides inherited member 'object.Equals(object?)'. Use the new keyword if hiding was intended.

Check warning on line 7 in src/Converters/EnumConverters.cs

View workflow job for this annotation

GitHub Actions / Build macOS (Intel)

'EnumConverters.Equals' hides inherited member 'object.Equals(object?)'. Use the new keyword if hiding was intended.

Check warning on line 7 in src/Converters/EnumConverters.cs

View workflow job for this annotation

GitHub Actions / Build macOS (Intel)

'EnumConverters.Equals' hides inherited member 'object.Equals(object?)'. Use the new keyword if hiding was intended.

Check warning on line 7 in src/Converters/EnumConverters.cs

View workflow job for this annotation

GitHub Actions / Build macOS (Intel)

'EnumConverters.Equals' hides inherited member 'object.Equals(object?)'. Use the new keyword if hiding was intended.

Check warning on line 7 in src/Converters/EnumConverters.cs

View workflow job for this annotation

GitHub Actions / Build Linux

'EnumConverters.Equals' hides inherited member 'object.Equals(object?)'. Use the new keyword if hiding was intended.

Check warning on line 7 in src/Converters/EnumConverters.cs

View workflow job for this annotation

GitHub Actions / Build Linux

'EnumConverters.Equals' hides inherited member 'object.Equals(object?)'. Use the new keyword if hiding was intended.

Check warning on line 7 in src/Converters/EnumConverters.cs

View workflow job for this annotation

GitHub Actions / Build Linux

'EnumConverters.Equals' hides inherited member 'object.Equals(object?)'. Use the new keyword if hiding was intended.

Check warning on line 7 in src/Converters/EnumConverters.cs

View workflow job for this annotation

GitHub Actions / Build macOS (Apple Silicon)

'EnumConverters.Equals' hides inherited member 'object.Equals(object?)'. Use the new keyword if hiding was intended.

Check warning on line 7 in src/Converters/EnumConverters.cs

View workflow job for this annotation

GitHub Actions / Build macOS (Apple Silicon)

'EnumConverters.Equals' hides inherited member 'object.Equals(object?)'. Use the new keyword if hiding was intended.

Check warning on line 7 in src/Converters/EnumConverters.cs

View workflow job for this annotation

GitHub Actions / Build macOS (Apple Silicon)

'EnumConverters.Equals' hides inherited member 'object.Equals(object?)'. Use the new keyword if hiding was intended.
}
}
1 change: 1 addition & 0 deletions src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.Discard" xml:space="preserve">Discard</x:String>
<x:String x:Key="Text.CreateBranch.LocalChanges.StashAndReply" xml:space="preserve">Stash &amp; 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.Placeholder" xml:space="preserve">Enter branch name.</x:String>
<x:String x:Key="Text.CreateBranch.Title" xml:space="preserve">Create Local Branch</x:String>
Expand Down
5 changes: 3 additions & 2 deletions src/Resources/Locales/zh_CN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@
<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.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.StashAndReply" xml:space="preserve">贮藏(stash)并自动恢复</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">贮藏并自动恢复</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.Placeholder" xml:space="preserve">填写分支名称。</x:String>
<x:String x:Key="Text.CreateBranch.Title" xml:space="preserve">创建本地分支</x:String>
Expand Down
26 changes: 17 additions & 9 deletions src/ViewModels/CreateBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

namespace SourceGit.ViewModels
{
public enum BeforeCreateBranchAction
{
StashAndReaply,
Discard,
DoNothing,
}

public class CreateBranch : Popup
{
[Required(ErrorMessage = "Branch name is required!")]
Expand All @@ -19,14 +26,14 @@ public object BasedOn
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;
Expand Down Expand Up @@ -90,7 +97,7 @@ public override Task<bool> Sure()
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();
Expand All @@ -108,7 +115,7 @@ public override Task<bool> Sure()
needPopStash = true;
}
else
else if (_preAction == BeforeCreateBranchAction.Discard)
{
SetProgressDescription("Discard local changes...");
Commands.Discard.All(_repo.FullPath);
Expand Down Expand Up @@ -137,5 +144,6 @@ public override Task<bool> Sure()
private readonly Repository _repo = null;
private string _name = null;
private readonly string _baseOnRevision = null;
private BeforeCreateBranchAction _preAction = BeforeCreateBranchAction.StashAndReaply;
}
}
9 changes: 7 additions & 2 deletions src/Views/CreateBranch.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,15 @@
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal">
<RadioButton Content="{DynamicResource Text.CreateBranch.LocalChanges.StashAndReply}"
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}"
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>

<CheckBox Grid.Row="3" Grid.Column="1"
Expand Down

0 comments on commit a52124c

Please sign in to comment.