mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 20:54:59 +00:00
project: reorganize the structure of the project.
* remove dotnet-tool.json because the project does not rely on any dotnet tools. * remove Directory.Build.props because the solution has only one project. * move src/SourceGit to src. It's not needed to put all sources into a subfolder of src since there's only one project.
This commit is contained in:
parent
96e60da7ad
commit
96d4150d26
319 changed files with 37 additions and 53 deletions
117
src/ViewModels/InitGitFlow.cs
Normal file
117
src/ViewModels/InitGitFlow.cs
Normal file
|
@ -0,0 +1,117 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public partial class InitGitFlow : Popup
|
||||
{
|
||||
|
||||
[GeneratedRegex(@"^[\w\-/\.]+$")]
|
||||
private static partial Regex TAG_PREFIX();
|
||||
|
||||
[Required(ErrorMessage = "Master branch name is required!!!")]
|
||||
[RegularExpression(@"^[\w\-/\.]+$", ErrorMessage = "Bad branch name format!")]
|
||||
[CustomValidation(typeof(InitGitFlow), nameof(ValidateBaseBranch))]
|
||||
public string Master
|
||||
{
|
||||
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))]
|
||||
public string Develop
|
||||
{
|
||||
get => _develop;
|
||||
set => SetProperty(ref _develop, value, true);
|
||||
}
|
||||
|
||||
[Required(ErrorMessage = "Feature prefix is required!!!")]
|
||||
[RegularExpression(@"^[\w\-\.]+/$", ErrorMessage = "Bad feature prefix format!")]
|
||||
public string FeturePrefix
|
||||
{
|
||||
get => _featurePrefix;
|
||||
set => SetProperty(ref _featurePrefix, value, true);
|
||||
}
|
||||
|
||||
[Required(ErrorMessage = "Release prefix is required!!!")]
|
||||
[RegularExpression(@"^[\w\-\.]+/$", ErrorMessage = "Bad release prefix format!")]
|
||||
public string ReleasePrefix
|
||||
{
|
||||
get => _releasePrefix;
|
||||
set => SetProperty(ref _releasePrefix, value, true);
|
||||
}
|
||||
|
||||
[Required(ErrorMessage = "Hotfix prefix is required!!!")]
|
||||
[RegularExpression(@"^[\w\-\.]+/$", ErrorMessage = "Bad hotfix prefix format!")]
|
||||
public string HotfixPrefix
|
||||
{
|
||||
get => _hotfixPrefix;
|
||||
set => SetProperty(ref _hotfixPrefix, value, true);
|
||||
}
|
||||
|
||||
[CustomValidation(typeof(InitGitFlow), nameof(ValidateTagPrefix))]
|
||||
public string TagPrefix
|
||||
{
|
||||
get => _tagPrefix;
|
||||
set => SetProperty(ref _tagPrefix, value, true);
|
||||
}
|
||||
|
||||
public InitGitFlow(Repository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
View = new Views.InitGitFlow() { DataContext = this };
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateBaseBranch(string _, ValidationContext ctx)
|
||||
{
|
||||
if (ctx.ObjectInstance is InitGitFlow initializer)
|
||||
{
|
||||
if (initializer._master == initializer._develop)
|
||||
return new ValidationResult("Develop branch has the same name with master branch!");
|
||||
}
|
||||
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateTagPrefix(string tagPrefix, ValidationContext ctx)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(tagPrefix) && !TAG_PREFIX().IsMatch(tagPrefix))
|
||||
{
|
||||
return new ValidationResult("Bad tag prefix format!");
|
||||
}
|
||||
|
||||
return ValidationResult.Success;
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
{
|
||||
_repo.SetWatcherEnabled(false);
|
||||
ProgressDescription = "Init git-flow ...";
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var succ = new Commands.GitFlow(_repo.FullPath).Init(_repo.Branches, _master, _develop, _featurePrefix, _releasePrefix, _hotfixPrefix, _tagPrefix);
|
||||
if (succ)
|
||||
{
|
||||
_repo.GitFlow.Feature = _featurePrefix;
|
||||
_repo.GitFlow.Release = _releasePrefix;
|
||||
_repo.GitFlow.Hotfix = _hotfixPrefix;
|
||||
}
|
||||
|
||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||
return succ;
|
||||
});
|
||||
}
|
||||
|
||||
private readonly Repository _repo = null;
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue