Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/ViewModels/CreateBranch.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace SourceGit.ViewModels
{
public class CreateBranch : Popup
public partial class CreateBranch : Popup
{
[Required(ErrorMessage = "Branch name is required!")]
[RegularExpression(@"^[\w \-/\.#\+]+$", ErrorMessage = "Bad branch name format!")]
Expand Down Expand Up @@ -101,7 +102,7 @@ public static ValidationResult ValidateBranchName(string name, ValidationContext
{
if (!creator._allowOverwrite)
{
var fixedName = creator.FixName(name);
var fixedName = FixName(name);
foreach (var b in creator._repo.Branches)
{
if (b.FriendlyName == fixedName)
Expand Down Expand Up @@ -227,13 +228,12 @@ public override async Task<bool> Sure()
return true;
}

private string FixName(string name)
{
if (!name.Contains(' '))
return name;
[GeneratedRegex(@"\s+")]
private static partial Regex REG_FIX_NAME();

var parts = name.Split(' ', System.StringSplitOptions.RemoveEmptyEntries);
return string.Join("-", parts);
private static string FixName(string name)
{
return REG_FIX_NAME().Replace(name, "-");
}

private readonly Repository _repo = null;
Expand Down
16 changes: 8 additions & 8 deletions src/ViewModels/RenameBranch.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace SourceGit.ViewModels
{
public class RenameBranch : Popup
public partial class RenameBranch : Popup
{
public Models.Branch Target
{
Expand All @@ -31,7 +32,7 @@ public static ValidationResult ValidateBranchName(string name, ValidationContext
{
if (ctx.ObjectInstance is RenameBranch rename)
{
var fixedName = rename.FixName(name);
var fixedName = FixName(name);
foreach (var b in rename._repo.Branches)
{
if (b.IsLocal && b != rename.Target && b.Name == fixedName)
Expand Down Expand Up @@ -87,13 +88,12 @@ public override async Task<bool> Sure()
return succ;
}

private string FixName(string name)
{
if (!name.Contains(' '))
return name;
[GeneratedRegex(@"\s+")]
private static partial Regex REG_FIX_NAME();

var parts = name.Split(' ', StringSplitOptions.RemoveEmptyEntries);
return string.Join("-", parts);
private static string FixName(string name)
{
return REG_FIX_NAME().Replace(name, "-");
}

private readonly Repository _repo;
Expand Down