refactor: re-implement git stash apply

* supports `--index` option
* add an option to drop selected stash after applying
* remove `Pop` context menu for stash

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-02-06 16:33:55 +08:00
parent dbb1df5f8b
commit 7089f29b85
No known key found for this signature in database
9 changed files with 121 additions and 22 deletions

View file

@ -0,0 +1,48 @@
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class ApplyStash : Popup
{
public Models.Stash Stash
{
get;
private set;
}
public bool RestoreIndex
{
get;
set;
} = true;
public bool DropAfterApply
{
get;
set;
} = false;
public ApplyStash(string repo, Models.Stash stash)
{
_repo = repo;
Stash = stash;
View = new Views.ApplyStash() { DataContext = this };
}
public override Task<bool> Sure()
{
ProgressDescription = $"Applying stash: {Stash.Name}";
return Task.Run(() =>
{
var succ = new Commands.Stash(_repo).Apply(Stash.Name, RestoreIndex);
if (succ && DropAfterApply)
new Commands.Stash(_repo).Drop(Stash.Name);
return true;
});
}
private readonly string _repo;
}
}