@@ -12,7 +12,7 @@ public Models.Branch Target
12
12
}
13
13
14
14
[ Required ( ErrorMessage = "Branch name is required!!!" ) ]
15
- [ RegularExpression ( @"^[\w\-/\.#]+$" , ErrorMessage = "Bad branch name format!" ) ]
15
+ [ RegularExpression ( @"^[\w \-/\.#]+$" , ErrorMessage = "Bad branch name format!" ) ]
16
16
[ CustomValidation ( typeof ( RenameBranch ) , nameof ( ValidateBranchName ) ) ]
17
17
public string Name
18
18
{
@@ -32,9 +32,10 @@ public static ValidationResult ValidateBranchName(string name, ValidationContext
32
32
{
33
33
if ( ctx . ObjectInstance is RenameBranch rename )
34
34
{
35
+ var fixedName = rename . FixName ( name ) ;
35
36
foreach ( var b in rename . _repo . Branches )
36
37
{
37
- if ( b . IsLocal && b != rename . Target && b . Name == name )
38
+ if ( b . IsLocal && b != rename . Target && b . Name == fixedName )
38
39
{
39
40
return new ValidationResult ( "A branch with same name already exists!!!" ) ;
40
41
}
@@ -46,7 +47,8 @@ public static ValidationResult ValidateBranchName(string name, ValidationContext
46
47
47
48
public override Task < bool > Sure ( )
48
49
{
49
- if ( _name == Target . Name )
50
+ var fixedName = FixName ( _name ) ;
51
+ if ( fixedName == Target . Name )
50
52
return null ;
51
53
52
54
_repo . SetWatcherEnabled ( false ) ;
@@ -55,7 +57,7 @@ public override Task<bool> Sure()
55
57
return Task . Run ( ( ) =>
56
58
{
57
59
var oldName = Target . FullName ;
58
- var succ = Commands . Branch . Rename ( _repo . FullPath , Target . Name , _name ) ;
60
+ var succ = Commands . Branch . Rename ( _repo . FullPath , Target . Name , fixedName ) ;
59
61
CallUIThread ( ( ) =>
60
62
{
61
63
if ( succ )
@@ -65,7 +67,7 @@ public override Task<bool> Sure()
65
67
if ( filter . Type == Models . FilterType . LocalBranch &&
66
68
filter . Pattern . Equals ( oldName , StringComparison . Ordinal ) )
67
69
{
68
- filter . Pattern = $ "refs/heads/{ _name } ";
70
+ filter . Pattern = $ "refs/heads/{ fixedName } ";
69
71
break ;
70
72
}
71
73
}
@@ -78,6 +80,15 @@ public override Task<bool> Sure()
78
80
} ) ;
79
81
}
80
82
83
+ private string FixName ( string name )
84
+ {
85
+ if ( ! name . Contains ( ' ' ) )
86
+ return name ;
87
+
88
+ var parts = name . Split ( ' ' , StringSplitOptions . RemoveEmptyEntries ) ;
89
+ return string . Join ( "-" , parts ) ;
90
+ }
91
+
81
92
private readonly Repository _repo ;
82
93
private string _name ;
83
94
}
0 commit comments