2024-02-05 23:08:37 -08:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class Squash : Popup
|
|
|
|
|
{
|
|
|
|
|
public Models.Commit Head
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Models.Commit Parent
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Required(ErrorMessage = "Commit message is required!!!")]
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string Message
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _message;
|
|
|
|
|
set => SetProperty(ref _message, value, true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Squash(Repository repo, Models.Commit head, Models.Commit parent)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
2024-06-24 19:26:31 -07:00
|
|
|
|
_message = new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).Result();
|
2024-06-13 18:46:30 -07:00
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Head = head;
|
|
|
|
|
Parent = parent;
|
|
|
|
|
View = new Views.Squash() { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public override Task<bool> Sure()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo.SetWatcherEnabled(false);
|
2024-02-25 19:29:57 -08:00
|
|
|
|
ProgressDescription = "Squashing ...";
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var succ = new Commands.Reset(_repo.FullPath, Parent.SHA, "--soft").Exec();
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (succ)
|
2024-07-06 19:28:14 -07:00
|
|
|
|
succ = new Commands.Commit(_repo.FullPath, _message, false, true).Exec();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
|
|
|
|
return succ;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly Repository _repo = null;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private string _message = string.Empty;
|
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|