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 GitFlowStart : Popup
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
[Required(ErrorMessage = "Name is required!!!")]
|
2024-07-21 02:43:23 -07:00
|
|
|
|
[RegularExpression(@"^[\w\-/\.#]+$", ErrorMessage = "Bad branch name format!")]
|
2024-02-05 23:08:37 -08:00
|
|
|
|
[CustomValidation(typeof(GitFlowStart), nameof(ValidateBranchName))]
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string Name
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _name;
|
|
|
|
|
set => SetProperty(ref _name, value, true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string Prefix
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _prefix;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-14 21:44:35 -07:00
|
|
|
|
public bool IsFeature => _type == "feature";
|
|
|
|
|
public bool IsRelease => _type == "release";
|
|
|
|
|
public bool IsHotfix => _type == "hotfix";
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-06-14 21:44:35 -07:00
|
|
|
|
public GitFlowStart(Repository repo, string type)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
_type = type;
|
2024-07-14 09:30:31 -07:00
|
|
|
|
_prefix = Commands.GitFlow.GetPrefix(repo.FullPath, type);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
View = new Views.GitFlowStart() { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static ValidationResult ValidateBranchName(string name, ValidationContext ctx)
|
|
|
|
|
{
|
|
|
|
|
if (ctx.ObjectInstance is GitFlowStart starter)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var check = $"{starter._prefix}{name}";
|
2024-03-17 18:37:06 -07:00
|
|
|
|
foreach (var b in starter._repo.Branches)
|
|
|
|
|
{
|
2024-07-01 19:23:21 -07:00
|
|
|
|
if (b.FriendlyName == check)
|
2024-03-31 01:54:29 -07:00
|
|
|
|
return new ValidationResult("A branch with same name already exists!");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ValidationResult.Success;
|
|
|
|
|
}
|
|
|
|
|
|
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-03-17 18:37:06 -07:00
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
2024-06-14 21:44:35 -07:00
|
|
|
|
SetProgressDescription($"Git Flow - starting {_type} {_name} ...");
|
|
|
|
|
var succ = Commands.GitFlow.Start(_repo.FullPath, _type, _name);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
|
|
|
|
return succ;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-14 09:30:31 -07:00
|
|
|
|
private readonly Repository _repo;
|
|
|
|
|
private readonly string _type;
|
|
|
|
|
private readonly string _prefix;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private string _name = null;
|
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|