feature: cherry-pick multiple commits (#418)

This commit is contained in:
leo 2024-08-28 11:26:00 +08:00
parent b2bbbb191c
commit ce2340456e
No known key found for this signature in database
11 changed files with 138 additions and 39 deletions

View file

@ -1,10 +1,12 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class CherryPick : Popup
{
public Models.Commit Target
public List<Models.Commit> Targets
{
get;
private set;
@ -16,10 +18,10 @@ namespace SourceGit.ViewModels
set;
}
public CherryPick(Repository repo, Models.Commit target)
public CherryPick(Repository repo, List<Models.Commit> targets)
{
_repo = repo;
Target = target;
Targets = targets;
AutoCommit = true;
View = new Views.CherryPick() { DataContext = this };
}
@ -27,11 +29,16 @@ namespace SourceGit.ViewModels
public override Task<bool> Sure()
{
_repo.SetWatcherEnabled(false);
ProgressDescription = $"Cherry-Pick commit '{Target.SHA}' ...";
ProgressDescription = $"Cherry-Pick commit(s) ...";
return Task.Run(() =>
{
var succ = new Commands.CherryPick(_repo.FullPath, Target.SHA, !AutoCommit).Exec();
// Get commit SHAs reverted
var builder = new StringBuilder();
for (int i = Targets.Count - 1; i >= 0; i--)
builder.Append($"{Targets[i].SHA} ");
var succ = new Commands.CherryPick(_repo.FullPath, builder.ToString(), !AutoCommit).Exec();
CallUIThread(() => _repo.SetWatcherEnabled(true));
return succ;
});