Skip to content

Commit d4ce0b9

Browse files
committed
feature: add a checkbox in Preferences > GIT to use Stash & Reapply by default when checking-out or merging branches
Signed-off-by: leo <longshuang@msn.cn>
1 parent 89ed387 commit d4ce0b9

11 files changed

Lines changed: 44 additions & 7 deletions

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@
680680
<x:String x:Key="Text.Preferences.Git.UseLibsecret" xml:space="preserve">Use git-credential-libsecret instead of git-credential-manager</x:String>
681681
<x:String x:Key="Text.Preferences.Git.User" xml:space="preserve">User Name</x:String>
682682
<x:String x:Key="Text.Preferences.Git.User.Placeholder" xml:space="preserve">Global git user name</x:String>
683+
<x:String x:Key="Text.Preferences.Git.UseStashAndReapplyByDefault" xml:space="preserve">Stash &amp; reapply changes by default when checking-out or merging branches</x:String>
683684
<x:String x:Key="Text.Preferences.Git.Version" xml:space="preserve">Git version</x:String>
684685
<x:String x:Key="Text.Preferences.GPG" xml:space="preserve">GPG SIGNING</x:String>
685686
<x:String x:Key="Text.Preferences.GPG.CommitEnabled" xml:space="preserve">Commit GPG signing</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@
684684
<x:String x:Key="Text.Preferences.Git.UseLibsecret" xml:space="preserve">使用 git-credential-libsecret 替代 git-credential-manager</x:String>
685685
<x:String x:Key="Text.Preferences.Git.User" xml:space="preserve">用户名</x:String>
686686
<x:String x:Key="Text.Preferences.Git.User.Placeholder" xml:space="preserve">默认GIT用户名</x:String>
687+
<x:String x:Key="Text.Preferences.Git.UseStashAndReapplyByDefault" xml:space="preserve">迁出或合并分支时,默认贮藏并自动恢复本地更改</x:String>
687688
<x:String x:Key="Text.Preferences.Git.Version" xml:space="preserve">Git 版本</x:String>
688689
<x:String x:Key="Text.Preferences.GPG" xml:space="preserve">GPG签名</x:String>
689690
<x:String x:Key="Text.Preferences.GPG.CommitEnabled" xml:space="preserve">启用提交签名</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@
684684
<x:String x:Key="Text.Preferences.Git.UseLibsecret" xml:space="preserve">使用 git-credential-libsecret 取代 git-credential-manager</x:String>
685685
<x:String x:Key="Text.Preferences.Git.User" xml:space="preserve">使用者名稱</x:String>
686686
<x:String x:Key="Text.Preferences.Git.User.Placeholder" xml:space="preserve">預設 Git 使用者名稱</x:String>
687+
<x:String x:Key="Text.Preferences.Git.UseStashAndReapplyByDefault" xml:space="preserve">在檢出或合併分支時,預設擱置變更並自動復原</x:String>
687688
<x:String x:Key="Text.Preferences.Git.Version" xml:space="preserve">Git 版本</x:String>
688689
<x:String x:Key="Text.Preferences.GPG" xml:space="preserve">GPG 簽章</x:String>
689690
<x:String x:Key="Text.Preferences.GPG.CommitEnabled" xml:space="preserve">啟用提交簽章</x:String>

src/ViewModels/Checkout.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ public Checkout(Repository repo, Models.Branch branch)
2424
{
2525
_repo = repo;
2626
_branch = branch;
27-
DealWithLocalChanges = Models.DealWithLocalChanges.DoNothing;
27+
28+
DealWithLocalChanges = Preferences.Instance.UseStashAndReapplyByDefault ?
29+
Models.DealWithLocalChanges.StashAndReapply :
30+
Models.DealWithLocalChanges.DoNothing;
2831
}
2932

3033
public override async Task<bool> Sure()

src/ViewModels/CheckoutAndFastForward.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public CheckoutAndFastForward(Repository repo, Models.Branch localBranch, Models
3030
_repo = repo;
3131
LocalBranch = localBranch;
3232
RemoteBranch = remoteBranch;
33-
DealWithLocalChanges = Models.DealWithLocalChanges.DoNothing;
33+
34+
DealWithLocalChanges = Preferences.Instance.UseStashAndReapplyByDefault ?
35+
Models.DealWithLocalChanges.StashAndReapply :
36+
Models.DealWithLocalChanges.DoNothing;
3437
}
3538

3639
public override async Task<bool> Sure()

src/ViewModels/CheckoutCommit.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ public CheckoutCommit(Repository repo, Models.Commit commit)
2424
{
2525
_repo = repo;
2626
Commit = commit;
27-
DealWithLocalChanges = Models.DealWithLocalChanges.DoNothing;
27+
28+
DealWithLocalChanges = Preferences.Instance.UseStashAndReapplyByDefault ?
29+
Models.DealWithLocalChanges.StashAndReapply :
30+
Models.DealWithLocalChanges.DoNothing;
2831
}
2932

3033
public override async Task<bool> Sure()

src/ViewModels/Preferences.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ public bool IgnoreCRAtEOLInDiff
254254
}
255255
}
256256

257+
public bool UseStashAndReapplyByDefault
258+
{
259+
get;
260+
set;
261+
} = false;
262+
257263
public bool EnableAutoFetch
258264
{
259265
get;

src/ViewModels/Pull.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Models.DealWithLocalChanges DealWithLocalChanges
4747
{
4848
get;
4949
set;
50-
} = Models.DealWithLocalChanges.DoNothing;
50+
}
5151

5252
public bool UseRebase
5353
{
@@ -60,6 +60,10 @@ public Pull(Repository repo, Models.Branch specifiedRemoteBranch)
6060
_repo = repo;
6161
Current = repo.CurrentBranch;
6262

63+
DealWithLocalChanges = Preferences.Instance.UseStashAndReapplyByDefault ?
64+
Models.DealWithLocalChanges.StashAndReapply :
65+
Models.DealWithLocalChanges.DoNothing;
66+
6367
if (specifiedRemoteBranch != null)
6468
{
6569
_selectedRemote = repo.Remotes.Find(x => x.Name == specifiedRemoteBranch.Remote);

src/Views/DealWithLocalChangesMethod.axaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@
1010
<RadioButton Content="{DynamicResource Text.DealWithLocalChanges.DoNothing}"
1111
x:Name="RadioDoNothing"
1212
Height="24"
13+
IsChecked="True"
1314
Click="OnRadioButtonClicked"
1415
Tag="{Binding Source={x:Static m:DealWithLocalChanges.DoNothing}}"/>
1516
<RadioButton Content="{DynamicResource Text.DealWithLocalChanges.StashAndReapply}"
1617
x:Name="RadioStashAndReapply"
1718
Height="24"
19+
IsChecked="False"
1820
Click="OnRadioButtonClicked"
1921
Tag="{Binding Source={x:Static m:DealWithLocalChanges.StashAndReapply}}"/>
2022
<RadioButton Content="{DynamicResource Text.DealWithLocalChanges.Discard}"
2123
x:Name="RadioDiscard"
2224
Height="24"
25+
IsChecked="False"
2326
Click="OnRadioButtonClicked"
2427
Tag="{Binding Source={x:Static m:DealWithLocalChanges.Discard}}"/>
2528
</StackPanel>

src/Views/DealWithLocalChangesMethod.axaml.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ public Models.DealWithLocalChanges Method
1818
public DealWithLocalChangesMethod()
1919
{
2020
InitializeComponent();
21-
UpdateRadioButtons();
21+
}
22+
23+
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
24+
{
25+
base.OnPropertyChanged(change);
26+
27+
if (change.Property == MethodProperty)
28+
UpdateRadioButtons();
2229
}
2330

2431
private void OnRadioButtonClicked(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)