2024-06-14 21:44:35 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public partial class InitGitFlow : Popup
|
|
|
|
|
{
|
2024-03-16 02:09:27 -07:00
|
|
|
|
[GeneratedRegex(@"^[\w\-/\.]+$")]
|
|
|
|
|
private static partial Regex TAG_PREFIX();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
|
|
|
|
[Required(ErrorMessage = "Master branch name is required!!!")]
|
|
|
|
|
[RegularExpression(@"^[\w\-/\.]+$", ErrorMessage = "Bad branch name format!")]
|
|
|
|
|
[CustomValidation(typeof(InitGitFlow), nameof(ValidateBaseBranch))]
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string Master
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _master;
|
|
|
|
|
set => SetProperty(ref _master, value, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Required(ErrorMessage = "Develop branch name is required!!!")]
|
|
|
|
|
[RegularExpression(@"^[\w\-/\.]+$", ErrorMessage = "Bad branch name format!")]
|
|
|
|
|
[CustomValidation(typeof(InitGitFlow), nameof(ValidateBaseBranch))]
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string Develop
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _develop;
|
|
|
|
|
set => SetProperty(ref _develop, value, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Required(ErrorMessage = "Feature prefix is required!!!")]
|
|
|
|
|
[RegularExpression(@"^[\w\-\.]+/$", ErrorMessage = "Bad feature prefix format!")]
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string FeturePrefix
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _featurePrefix;
|
|
|
|
|
set => SetProperty(ref _featurePrefix, value, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Required(ErrorMessage = "Release prefix is required!!!")]
|
|
|
|
|
[RegularExpression(@"^[\w\-\.]+/$", ErrorMessage = "Bad release prefix format!")]
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string ReleasePrefix
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _releasePrefix;
|
|
|
|
|
set => SetProperty(ref _releasePrefix, value, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Required(ErrorMessage = "Hotfix prefix is required!!!")]
|
|
|
|
|
[RegularExpression(@"^[\w\-\.]+/$", ErrorMessage = "Bad hotfix prefix format!")]
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string HotfixPrefix
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _hotfixPrefix;
|
|
|
|
|
set => SetProperty(ref _hotfixPrefix, value, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[CustomValidation(typeof(InitGitFlow), nameof(ValidateTagPrefix))]
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public string TagPrefix
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _tagPrefix;
|
|
|
|
|
set => SetProperty(ref _tagPrefix, value, true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public InitGitFlow(Repository repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
2024-06-14 21:44:35 -07:00
|
|
|
|
|
|
|
|
|
var localBranches = new List<string>();
|
|
|
|
|
foreach (var branch in repo.Branches)
|
|
|
|
|
{
|
|
|
|
|
if (branch.IsLocal)
|
|
|
|
|
localBranches.Add(branch.Name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (localBranches.Contains("master"))
|
|
|
|
|
_master = "master";
|
|
|
|
|
else if (localBranches.Contains("main"))
|
|
|
|
|
_master = "main";
|
|
|
|
|
else if (localBranches.Count > 0)
|
|
|
|
|
_master = localBranches[0];
|
|
|
|
|
else
|
|
|
|
|
_master = "master";
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
View = new Views.InitGitFlow() { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static ValidationResult ValidateBaseBranch(string _, ValidationContext ctx)
|
|
|
|
|
{
|
|
|
|
|
if (ctx.ObjectInstance is InitGitFlow initializer)
|
|
|
|
|
{
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (initializer._master == initializer._develop)
|
|
|
|
|
return new ValidationResult("Develop branch has the same name with master branch!");
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ValidationResult.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static ValidationResult ValidateTagPrefix(string tagPrefix, ValidationContext ctx)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(tagPrefix) && !TAG_PREFIX().IsMatch(tagPrefix))
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return new ValidationResult("Bad tag prefix format!");
|
|
|
|
|
|
|
|
|
|
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-02-25 19:29:57 -08:00
|
|
|
|
ProgressDescription = "Init git-flow ...";
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
2024-06-14 21:44:35 -07:00
|
|
|
|
var succ = Commands.GitFlow.Init(_repo.FullPath, _repo.Branches, _master, _develop, _featurePrefix, _releasePrefix, _hotfixPrefix, _tagPrefix);
|
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 _master = "master";
|
|
|
|
|
private string _develop = "develop";
|
|
|
|
|
private string _featurePrefix = "feature/";
|
|
|
|
|
private string _releasePrefix = "release/";
|
|
|
|
|
private string _hotfixPrefix = "hotfix/";
|
|
|
|
|
private string _tagPrefix = string.Empty;
|
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|