mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-24 10:50:52 +08:00
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
@@ -29,7 +30,7 @@ namespace SourceGit.Models
|
||||
CommitterDate,
|
||||
}
|
||||
|
||||
public class Branch
|
||||
public partial class Branch
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string FullName { get; set; }
|
||||
@@ -44,5 +45,13 @@ namespace SourceGit.Models
|
||||
public bool IsUpstreamGone { get; set; }
|
||||
|
||||
public string FriendlyName => IsLocal ? Name : $"{Remote}/{Name}";
|
||||
|
||||
[GeneratedRegex(@"\s+")]
|
||||
private static partial Regex REG_FIX_NAME();
|
||||
|
||||
public static string FixName(string name)
|
||||
{
|
||||
return REG_FIX_NAME().Replace(name, "-");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
@@ -102,10 +101,10 @@ namespace SourceGit.ViewModels
|
||||
{
|
||||
if (!creator._allowOverwrite)
|
||||
{
|
||||
var fixedName = FixName(name);
|
||||
var fixedName = Models.Branch.FixName(name);
|
||||
foreach (var b in creator._repo.Branches)
|
||||
{
|
||||
if (b.FriendlyName == fixedName)
|
||||
if (b.FriendlyName.Equals(fixedName, StringComparison.Ordinal))
|
||||
return new ValidationResult("A branch with same name already exists!");
|
||||
}
|
||||
}
|
||||
@@ -120,7 +119,7 @@ namespace SourceGit.ViewModels
|
||||
{
|
||||
_repo.SetWatcherEnabled(false);
|
||||
|
||||
var fixedName = FixName(_name);
|
||||
var fixedName = Models.Branch.FixName(_name);
|
||||
var log = _repo.CreateLog($"Create Branch '{fixedName}'");
|
||||
Use(log);
|
||||
|
||||
@@ -228,14 +227,6 @@ namespace SourceGit.ViewModels
|
||||
return true;
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"\s+")]
|
||||
private static partial Regex REG_FIX_NAME();
|
||||
|
||||
private static string FixName(string name)
|
||||
{
|
||||
return REG_FIX_NAME().Replace(name, "-");
|
||||
}
|
||||
|
||||
private readonly Repository _repo = null;
|
||||
private string _name = null;
|
||||
private readonly string _baseOnRevision = null;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
@@ -32,10 +31,10 @@ namespace SourceGit.ViewModels
|
||||
{
|
||||
if (ctx.ObjectInstance is RenameBranch rename)
|
||||
{
|
||||
var fixedName = FixName(name);
|
||||
var fixedName = Models.Branch.FixName(name);
|
||||
foreach (var b in rename._repo.Branches)
|
||||
{
|
||||
if (b.IsLocal && b != rename.Target && b.Name == fixedName)
|
||||
if (b.IsLocal && b != rename.Target && b.Name.Equals(fixedName, StringComparison.Ordinal))
|
||||
{
|
||||
return new ValidationResult("A branch with same name already exists!!!");
|
||||
}
|
||||
@@ -47,8 +46,8 @@ namespace SourceGit.ViewModels
|
||||
|
||||
public override async Task<bool> Sure()
|
||||
{
|
||||
var fixedName = FixName(_name);
|
||||
if (fixedName == Target.Name)
|
||||
var fixedName = Models.Branch.FixName(_name);
|
||||
if (fixedName.Equals(Target.Name, StringComparison.Ordinal))
|
||||
return true;
|
||||
|
||||
_repo.SetWatcherEnabled(false);
|
||||
@@ -59,9 +58,8 @@ namespace SourceGit.ViewModels
|
||||
|
||||
var isCurrent = Target.IsCurrent;
|
||||
var oldName = Target.FullName;
|
||||
var succ = await Commands.Branch
|
||||
.RenameAsync(_repo.FullPath, Target.Name, fixedName, log);
|
||||
|
||||
var succ = await Commands.Branch.RenameAsync(_repo.FullPath, Target.Name, fixedName, log);
|
||||
if (succ)
|
||||
{
|
||||
foreach (var filter in _repo.Settings.HistoriesFilters)
|
||||
@@ -88,14 +86,6 @@ namespace SourceGit.ViewModels
|
||||
return succ;
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"\s+")]
|
||||
private static partial Regex REG_FIX_NAME();
|
||||
|
||||
private static string FixName(string name)
|
||||
{
|
||||
return REG_FIX_NAME().Replace(name, "-");
|
||||
}
|
||||
|
||||
private readonly Repository _repo;
|
||||
private string _name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user