mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 04:34:59 +00:00
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:
parent
dbb1df5f8b
commit
7089f29b85
9 changed files with 121 additions and 22 deletions
48
src/ViewModels/ApplyStash.cs
Normal file
48
src/ViewModels/ApplyStash.cs
Normal 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;
|
||||
}
|
||||
}
|
|
@ -91,7 +91,7 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
|
||||
if (AutoRestore && succ)
|
||||
succ = new Commands.Stash(_repo.FullPath).Apply();
|
||||
succ = new Commands.Stash(_repo.FullPath).Apply("stash@{0}", true);
|
||||
|
||||
CallUIThread(() =>
|
||||
{
|
||||
|
|
|
@ -141,15 +141,9 @@ namespace SourceGit.ViewModels
|
|||
apply.Header = App.Text("StashCM.Apply");
|
||||
apply.Click += (_, ev) =>
|
||||
{
|
||||
Task.Run(() => new Commands.Stash(_repo.FullPath).Apply(stash.Name));
|
||||
ev.Handled = true;
|
||||
};
|
||||
if (_repo.CanCreatePopup())
|
||||
_repo.ShowPopup(new ApplyStash(_repo.FullPath, stash));
|
||||
|
||||
var pop = new MenuItem();
|
||||
pop.Header = App.Text("StashCM.Pop");
|
||||
pop.Click += (_, ev) =>
|
||||
{
|
||||
Task.Run(() => new Commands.Stash(_repo.FullPath).Pop(stash.Name));
|
||||
ev.Handled = true;
|
||||
};
|
||||
|
||||
|
@ -165,7 +159,6 @@ namespace SourceGit.ViewModels
|
|||
|
||||
var menu = new ContextMenu();
|
||||
menu.Items.Add(apply);
|
||||
menu.Items.Add(pop);
|
||||
menu.Items.Add(drop);
|
||||
return menu;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue