Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 673a1b6

Browse files
Update class name and conditions
1 parent fe1c52c commit 673a1b6

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
<Compile Include="Application\ApplicationManagerBase.cs" />
105105
<Compile Include="Helpers\Constants.cs" />
106106
<Compile Include="Cache\IBranchCache.cs" />
107-
<Compile Include="Helpers\RegularExpressions.cs" />
107+
<Compile Include="Helpers\Validation.cs" />
108108
<Compile Include="Platform\DefaultEnvironment.cs" />
109109
<Compile Include="Extensions\EnvironmentExtensions.cs" />
110110
<Compile Include="Extensions\FileEventExtensions.cs" />
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
using System.Text.RegularExpressions;
1+
using System;
2+
using System.Text.RegularExpressions;
23

34
namespace GitHub.Unity.Helpers
45
{
5-
public static class RegularExpressions
6-
{
7-
public static readonly Regex BranchNameRegex = new Regex(@"^(?<name>[\.\w\d\/\-_]+)$");
8-
}
9-
10-
public static class BranchNameValidator
6+
public static class Validation
117
{
128
public static bool IsBranchNameValid(string branchName)
139
{
14-
return !string.IsNullOrEmpty(branchName)
10+
return !String.IsNullOrEmpty(branchName)
1511
&& !branchName.Equals(".")
1612
&& !branchName.StartsWith("/")
1713
&& !branchName.EndsWith("/")
14+
&& !branchName.StartsWith(".")
1815
&& !branchName.EndsWith(".")
1916
&& !branchName.Contains("//")
2017
&& !branchName.Contains(@"\")
2118
&& !branchName.EndsWith(".lock")
22-
&& !(branchName.StartsWith(".") && branchName.Contains("/"))
23-
&& RegularExpressions.BranchNameRegex.IsMatch(branchName);
19+
&& BranchNameRegex.IsMatch(branchName);
2420
}
21+
22+
public static readonly Regex BranchNameRegex = new Regex(@"^(?<name>[\.\w\d\/\-_]+)$");
2523
}
2624
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ private void OnCreateGUI()
454454
var cancelCreate = false;
455455
var cannotCreate = selectedNode == null ||
456456
selectedNode.Type == NodeType.Folder ||
457-
!BranchNameValidator.IsBranchNameValid(newBranchName);
457+
!Validation.IsBranchNameValid(newBranchName);
458458

459459
// Create on return/enter or cancel on escape
460460
var offsetID = GUIUtility.GetControlID(FocusType.Passive);

src/tests/UnitTests/Git/BranchNameValidationTests.cs renamed to src/tests/UnitTests/Git/ValidationTests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace UnitTests
88
{
99
[TestFixture]
10-
public class BranchNameValidatorTests
10+
public class ValidationTests
1111
{
1212
[TestCase(true, "feature1", TestName = "Branch name is valid")]
1313
[TestCase(true, "feature-1", TestName = "Branch name with hyphen is valid")]
@@ -29,16 +29,15 @@ public class BranchNameValidatorTests
2929
[TestCase(false, ".", TestName = "Single character cannot be [period]")]
3030
[TestCase(true, "features/feature-1", TestName = "Folder and branch name is valid")]
3131
[TestCase(false, @"features\feature-1", TestName = "Backslash is not a valid character")]
32-
[TestCase(true, ".hidden", TestName = "Branch name is valid when starting with [period]")]
33-
[TestCase(false, ".features/feature-1", TestName = "Folder and branch name is not valid when starting with [period]")]
32+
[TestCase(false, ".hidden", TestName = "Branch name is not valid when starting with [period]")]
3433
[TestCase(false, "features//feature-1", TestName = "Multiple consecutive slashes are not valid")]
3534
[TestCase(false, null, TestName = "null string is not valid")]
3635
[TestCase(false, "", TestName = "Empty string is not valid")]
3736
[TestCase(false, "/", TestName = "Single slash is not valid")]
3837
[TestCase(false, "asdf@{", TestName = "Sequence @{ is not valid")]
3938
public void TestFeatureString(bool isValid, string branch)
4039
{
41-
BranchNameValidator.IsBranchNameValid(branch).Should().Be(isValid);
40+
Validation.IsBranchNameValid(branch).Should().Be(isValid);
4241
}
4342

4443
[TestCase(true, 65, 65, 65, TestName = "Can test with ascii values")]
@@ -47,7 +46,7 @@ public void TestFeatureString(bool isValid, string branch)
4746
public void TestFeatureStringFromAsciiArray(bool isValid, params int[] asciiValues)
4847
{
4948
var branch = new string(asciiValues.Select(Convert.ToChar).ToArray());
50-
BranchNameValidator.IsBranchNameValid(branch).Should().Be(isValid);
49+
Validation.IsBranchNameValid(branch).Should().Be(isValid);
5150
}
5251
}
5352
}

src/tests/UnitTests/UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
</ItemGroup>
8282
<ItemGroup>
8383
<Compile Include="Authentication\KeychainTests.cs" />
84-
<Compile Include="Git\BranchNameValidationTests.cs" />
84+
<Compile Include="Git\ValidationTests.cs" />
8585
<Compile Include="Git\GitConfigTests.cs" />
8686
<Compile Include="IO\BranchListOutputProcessorTests.cs" />
8787
<Compile Include="Extensions\EnvironmentExtensionTests.cs" />

0 commit comments

Comments
 (0)