|
1 | 1 | using System;
|
2 | 2 | using System.ComponentModel.DataAnnotations;
|
| 3 | +using System.Text.RegularExpressions; |
3 | 4 | using System.Threading.Tasks;
|
4 | 5 |
|
5 | 6 | namespace SourceGit.ViewModels
|
6 | 7 | {
|
7 |
| - public class CreateBranch : Popup |
| 8 | + public partial class CreateBranch : Popup |
8 | 9 | {
|
9 | 10 | [Required(ErrorMessage = "Branch name is required!")]
|
10 | 11 | [RegularExpression(@"^[\w \-/\.#\+]+$", ErrorMessage = "Bad branch name format!")]
|
@@ -101,7 +102,7 @@ public static ValidationResult ValidateBranchName(string name, ValidationContext
|
101 | 102 | {
|
102 | 103 | if (!creator._allowOverwrite)
|
103 | 104 | {
|
104 |
| - var fixedName = creator.FixName(name); |
| 105 | + var fixedName = FixName(name); |
105 | 106 | foreach (var b in creator._repo.Branches)
|
106 | 107 | {
|
107 | 108 | if (b.FriendlyName == fixedName)
|
@@ -227,13 +228,12 @@ public override async Task<bool> Sure()
|
227 | 228 | return true;
|
228 | 229 | }
|
229 | 230 |
|
230 |
| - private string FixName(string name) |
231 |
| - { |
232 |
| - if (!name.Contains(' ')) |
233 |
| - return name; |
| 231 | + [GeneratedRegex(@"\s+")] |
| 232 | + private static partial Regex REG_FIX_NAME(); |
234 | 233 |
|
235 |
| - var parts = name.Split(' ', System.StringSplitOptions.RemoveEmptyEntries); |
236 |
| - return string.Join("-", parts); |
| 234 | + private static string FixName(string name) |
| 235 | + { |
| 236 | + return REG_FIX_NAME().Replace(name, "-"); |
237 | 237 | }
|
238 | 238 |
|
239 | 239 | private readonly Repository _repo = null;
|
|
0 commit comments