feat: Add stash auto-restore functionality (#947) (#948)

This commit is contained in:
GadflyFang 2025-02-06 10:31:46 +08:00 committed by GitHub
parent 942f349275
commit 3ca4dc488c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 41 additions and 8 deletions

View file

@ -73,21 +73,27 @@ namespace SourceGit.Commands
return Exec(); return Exec();
} }
public bool Apply(string name) public bool Apply(string name = null)
{ {
Args = $"stash apply --index -q {name}"; Args = "stash apply -q";
if (!string.IsNullOrEmpty(name))
Args += $" \"{name}\"";
return Exec(); return Exec();
} }
public bool Pop(string name) public bool Pop(string name = null)
{ {
Args = $"stash pop --index -q {name}"; Args = "stash pop -q";
if (!string.IsNullOrEmpty(name))
Args += $" \"{name}\"";
return Exec(); return Exec();
} }
public bool Drop(string name) public bool Drop(string name = null)
{ {
Args = $"stash drop -q {name}"; Args = "stash drop -q";
if (!string.IsNullOrEmpty(name))
Args += $" \"{name}\"";
return Exec(); return Exec();
} }

View file

@ -182,6 +182,12 @@ namespace SourceGit.Models
set; set;
} = false; } = false;
public bool AutoRestoreAfterStash
{
get;
set;
} = false;
public string PreferedOpenAIService public string PreferedOpenAIService
{ {
get; get;

View file

@ -640,6 +640,8 @@
<x:String x:Key="Text.SSHKey.Placeholder" xml:space="preserve">Private SSH key store path</x:String> <x:String x:Key="Text.SSHKey.Placeholder" xml:space="preserve">Private SSH key store path</x:String>
<x:String x:Key="Text.Start" xml:space="preserve">START</x:String> <x:String x:Key="Text.Start" xml:space="preserve">START</x:String>
<x:String x:Key="Text.Stash" xml:space="preserve">Stash</x:String> <x:String x:Key="Text.Stash" xml:space="preserve">Stash</x:String>
<x:String x:Key="Text.Stash.AutoRestore" xml:space="preserve">Auto-restore after stashing</x:String>
<x:String x:Key="Text.Stash.AutoRestore.Tip" xml:space="preserve">Your working files remain unchanged, but a stash is saved.</x:String>
<x:String x:Key="Text.Stash.IncludeUntracked" xml:space="preserve">Include untracked files</x:String> <x:String x:Key="Text.Stash.IncludeUntracked" xml:space="preserve">Include untracked files</x:String>
<x:String x:Key="Text.Stash.KeepIndex" xml:space="preserve">Keep staged files</x:String> <x:String x:Key="Text.Stash.KeepIndex" xml:space="preserve">Keep staged files</x:String>
<x:String x:Key="Text.Stash.Message" xml:space="preserve">Message:</x:String> <x:String x:Key="Text.Stash.Message" xml:space="preserve">Message:</x:String>

View file

@ -644,6 +644,8 @@
<x:String x:Key="Text.SSHKey.Placeholder" xml:space="preserve">SSH密钥文件</x:String> <x:String x:Key="Text.SSHKey.Placeholder" xml:space="preserve">SSH密钥文件</x:String>
<x:String x:Key="Text.Start" xml:space="preserve">开 始</x:String> <x:String x:Key="Text.Start" xml:space="preserve">开 始</x:String>
<x:String x:Key="Text.Stash" xml:space="preserve">贮藏(stash)</x:String> <x:String x:Key="Text.Stash" xml:space="preserve">贮藏(stash)</x:String>
<x:String x:Key="Text.Stash.AutoRestore" xml:space="preserve">贮藏后自动恢复工作区</x:String>
<x:String x:Key="Text.Stash.AutoRestore.Tip" xml:space="preserve">工作区文件保持未修改状态,但贮藏内容已保存。</x:String>
<x:String x:Key="Text.Stash.IncludeUntracked" xml:space="preserve">包含未跟踪的文件</x:String> <x:String x:Key="Text.Stash.IncludeUntracked" xml:space="preserve">包含未跟踪的文件</x:String>
<x:String x:Key="Text.Stash.KeepIndex" xml:space="preserve">保留暂存区文件</x:String> <x:String x:Key="Text.Stash.KeepIndex" xml:space="preserve">保留暂存区文件</x:String>
<x:String x:Key="Text.Stash.Message" xml:space="preserve">信息 </x:String> <x:String x:Key="Text.Stash.Message" xml:space="preserve">信息 </x:String>

View file

@ -643,6 +643,8 @@
<x:String x:Key="Text.SSHKey.Placeholder" xml:space="preserve">SSH 金鑰檔案</x:String> <x:String x:Key="Text.SSHKey.Placeholder" xml:space="preserve">SSH 金鑰檔案</x:String>
<x:String x:Key="Text.Start" xml:space="preserve">開 始</x:String> <x:String x:Key="Text.Start" xml:space="preserve">開 始</x:String>
<x:String x:Key="Text.Stash" xml:space="preserve">擱置變更 (stash)</x:String> <x:String x:Key="Text.Stash" xml:space="preserve">擱置變更 (stash)</x:String>
<x:String x:Key="Text.Stash.AutoRestore" xml:space="preserve">暫存後自動復原工作區</x:String>
<x:String x:Key="Text.Stash.AutoRestore.Tip" xml:space="preserve">工作區檔案保持未修改,但暫存內容已儲存。</x:String>
<x:String x:Key="Text.Stash.IncludeUntracked" xml:space="preserve">包含未追蹤的檔案</x:String> <x:String x:Key="Text.Stash.IncludeUntracked" xml:space="preserve">包含未追蹤的檔案</x:String>
<x:String x:Key="Text.Stash.KeepIndex" xml:space="preserve">保留已暫存的變更</x:String> <x:String x:Key="Text.Stash.KeepIndex" xml:space="preserve">保留已暫存的變更</x:String>
<x:String x:Key="Text.Stash.Message" xml:space="preserve">擱置變更訊息:</x:String> <x:String x:Key="Text.Stash.Message" xml:space="preserve">擱置變更訊息:</x:String>

View file

@ -36,6 +36,12 @@ namespace SourceGit.ViewModels
set => _repo.Settings.KeepIndexWhenStash = value; set => _repo.Settings.KeepIndexWhenStash = value;
} }
public bool AutoRestore
{
get => _repo.Settings.AutoRestoreAfterStash;
set => _repo.Settings.AutoRestoreAfterStash = value;
}
public StashChanges(Repository repo, List<Models.Change> changes, bool hasSelectedFiles) public StashChanges(Repository repo, List<Models.Change> changes, bool hasSelectedFiles)
{ {
_repo = repo; _repo = repo;
@ -84,6 +90,9 @@ namespace SourceGit.ViewModels
succ = StashWithChanges(_changes); succ = StashWithChanges(_changes);
} }
if (AutoRestore && succ)
succ = new Commands.Stash(_repo.FullPath).Apply();
CallUIThread(() => CallUIThread(() =>
{ {
_repo.MarkWorkingCopyDirtyManually(); _repo.MarkWorkingCopyDirtyManually();

View file

@ -11,7 +11,7 @@
<TextBlock FontSize="18" <TextBlock FontSize="18"
Classes="bold" Classes="bold"
Text="{DynamicResource Text.Stash.Title}"/> Text="{DynamicResource Text.Stash.Title}"/>
<Grid Margin="8,16,0,0" RowDefinitions="32,Auto,Auto,32,Auto" ColumnDefinitions="120,*"> <Grid Margin="8,16,0,0" RowDefinitions="32,Auto,Auto,32,Auto,Auto" ColumnDefinitions="120,*">
<TextBlock Grid.Row="0" Grid.Column="0" <TextBlock Grid.Row="0" Grid.Column="0"
HorizontalAlignment="Right" HorizontalAlignment="Right"
Margin="8,0" Margin="8,0"
@ -43,7 +43,13 @@
IsChecked="{Binding KeepIndex, Mode=TwoWay}" IsChecked="{Binding KeepIndex, Mode=TwoWay}"
ToolTip.Tip="--keep-index"/> ToolTip.Tip="--keep-index"/>
<TextBlock Grid.Row="4" Grid.Column="1" <CheckBox Grid.Row="4" Grid.Column="1"
Height="32"
Content="{DynamicResource Text.Stash.AutoRestore}"
IsChecked="{Binding AutoRestore, Mode=TwoWay}"
ToolTip.Tip="{DynamicResource Text.Stash.AutoRestore.Tip}"/>
<TextBlock Grid.Row="5" Grid.Column="1"
Margin="0,4,0,0" Margin="0,4,0,0"
Text="{DynamicResource Text.Stash.TipForSelectedFiles}" Text="{DynamicResource Text.Stash.TipForSelectedFiles}"
TextWrapping="Wrap" TextWrapping="Wrap"