mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-02 17:44:59 +00:00
refactor: rewrite git flow init
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
4d5be9f280
commit
3386cb177b
3 changed files with 40 additions and 18 deletions
|
@ -1,24 +1,12 @@
|
||||||
using System.Collections.Generic;
|
using System.Text;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
|
|
||||||
namespace SourceGit.Commands
|
namespace SourceGit.Commands
|
||||||
{
|
{
|
||||||
public static class GitFlow
|
public static class GitFlow
|
||||||
{
|
{
|
||||||
public static bool Init(string repo, List<Models.Branch> branches, string master, string develop, string feature, string release, string hotfix, string version, Models.ICommandLog log)
|
public static bool Init(string repo, string master, string develop, string feature, string release, string hotfix, string version, Models.ICommandLog log)
|
||||||
{
|
{
|
||||||
var current = branches.Find(x => x.IsCurrent);
|
|
||||||
|
|
||||||
var masterBranch = branches.Find(x => x.Name == master);
|
|
||||||
if (masterBranch == null && current != null)
|
|
||||||
Branch.Create(repo, master, current.Head, log);
|
|
||||||
|
|
||||||
var devBranch = branches.Find(x => x.Name == develop);
|
|
||||||
if (devBranch == null && current != null)
|
|
||||||
Branch.Create(repo, develop, current.Head, log);
|
|
||||||
|
|
||||||
var config = new Config(repo);
|
var config = new Config(repo);
|
||||||
config.Set("gitflow.branch.master", master);
|
config.Set("gitflow.branch.master", master);
|
||||||
config.Set("gitflow.branch.develop", develop);
|
config.Set("gitflow.branch.develop", develop);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -109,9 +110,35 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
return Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
var succ = Commands.GitFlow.Init(
|
var succ = false;
|
||||||
|
var current = _repo.CurrentBranch;
|
||||||
|
|
||||||
|
var masterBranch = _repo.Branches.Find(x => x.IsLocal && x.Name.Equals(_master, StringComparison.Ordinal));
|
||||||
|
if (masterBranch == null)
|
||||||
|
{
|
||||||
|
succ = Commands.Branch.Create(_repo.FullPath, _master, current.Head, log);
|
||||||
|
if (!succ)
|
||||||
|
{
|
||||||
|
log.Complete();
|
||||||
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var developBranch = _repo.Branches.Find(x => x.IsLocal && x.Name.Equals(_develop, StringComparison.Ordinal));
|
||||||
|
if (developBranch == null)
|
||||||
|
{
|
||||||
|
succ = Commands.Branch.Create(_repo.FullPath, _develop, current.Head, log);
|
||||||
|
if (!succ)
|
||||||
|
{
|
||||||
|
log.Complete();
|
||||||
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
succ = Commands.GitFlow.Init(
|
||||||
_repo.FullPath,
|
_repo.FullPath,
|
||||||
_repo.Branches,
|
|
||||||
_master,
|
_master,
|
||||||
_develop,
|
_develop,
|
||||||
_featurePrefix,
|
_featurePrefix,
|
||||||
|
|
|
@ -1459,8 +1459,15 @@ namespace SourceGit.ViewModels
|
||||||
init.Icon = App.CreateMenuIcon("Icons.Init");
|
init.Icon = App.CreateMenuIcon("Icons.Init");
|
||||||
init.Click += (_, e) =>
|
init.Click += (_, e) =>
|
||||||
{
|
{
|
||||||
if (CanCreatePopup())
|
if (_currentBranch == null)
|
||||||
|
{
|
||||||
|
App.RaiseException(_fullpath, "Git flow init failed: No branch found!!!");
|
||||||
|
}
|
||||||
|
else if (CanCreatePopup())
|
||||||
|
{
|
||||||
ShowPopup(new InitGitFlow(this));
|
ShowPopup(new InitGitFlow(this));
|
||||||
|
}
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
menu.Items.Add(init);
|
menu.Items.Add(init);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue