@@ -6,7 +6,7 @@ namespace SourceGit.ViewModels
6
6
public class CreateBranch : Popup
7
7
{
8
8
[ Required ( ErrorMessage = "Branch name is required!" ) ]
9
- [ RegularExpression ( @"^[\w\-/\.#]+$" , ErrorMessage = "Bad branch name format!" ) ]
9
+ [ RegularExpression ( @"^[\w \-/\.#]+$" , ErrorMessage = "Bad branch name format!" ) ]
10
10
[ CustomValidation ( typeof ( CreateBranch ) , nameof ( ValidateBranchName ) ) ]
11
11
public string Name
12
12
{
@@ -74,9 +74,10 @@ public static ValidationResult ValidateBranchName(string name, ValidationContext
74
74
if ( creator == null )
75
75
return new ValidationResult ( "Missing runtime context to create branch!" ) ;
76
76
77
+ var fixedName = creator . FixName ( name ) ;
77
78
foreach ( var b in creator . _repo . Branches )
78
79
{
79
- if ( b . FriendlyName == name )
80
+ if ( b . FriendlyName == fixedName )
80
81
return new ValidationResult ( "A branch with same name already exists!" ) ;
81
82
}
82
83
@@ -86,6 +87,8 @@ public static ValidationResult ValidateBranchName(string name, ValidationContext
86
87
public override Task < bool > Sure ( )
87
88
{
88
89
_repo . SetWatcherEnabled ( false ) ;
90
+
91
+ var fixedName = FixName ( _name ) ;
89
92
return Task . Run ( ( ) =>
90
93
{
91
94
var succ = false ;
@@ -114,8 +117,8 @@ public override Task<bool> Sure()
114
117
}
115
118
}
116
119
117
- SetProgressDescription ( $ "Create new branch '{ _name } '") ;
118
- succ = new Commands . Checkout ( _repo . FullPath ) . Branch ( _name , _baseOnRevision , SetProgressDescription ) ;
120
+ SetProgressDescription ( $ "Create new branch '{ fixedName } '") ;
121
+ succ = new Commands . Checkout ( _repo . FullPath ) . Branch ( fixedName , _baseOnRevision , SetProgressDescription ) ;
119
122
120
123
if ( needPopStash )
121
124
{
@@ -125,15 +128,15 @@ public override Task<bool> Sure()
125
128
}
126
129
else
127
130
{
128
- SetProgressDescription ( $ "Create new branch '{ _name } '") ;
129
- succ = Commands . Branch . Create ( _repo . FullPath , _name , _baseOnRevision ) ;
131
+ SetProgressDescription ( $ "Create new branch '{ fixedName } '") ;
132
+ succ = Commands . Branch . Create ( _repo . FullPath , fixedName , _baseOnRevision ) ;
130
133
}
131
134
132
135
CallUIThread ( ( ) =>
133
136
{
134
137
if ( succ && CheckoutAfterCreated )
135
138
{
136
- var fake = new Models . Branch ( ) { IsLocal = true , FullName = $ "refs/heads/{ _name } " } ;
139
+ var fake = new Models . Branch ( ) { IsLocal = true , FullName = $ "refs/heads/{ fixedName } " } ;
137
140
if ( BasedOn is Models . Branch based && ! based . IsLocal )
138
141
fake . Upstream = based . FullName ;
139
142
@@ -153,6 +156,15 @@ public override Task<bool> Sure()
153
156
} ) ;
154
157
}
155
158
159
+ private string FixName ( string name )
160
+ {
161
+ if ( ! name . Contains ( ' ' ) )
162
+ return name ;
163
+
164
+ var parts = name . Split ( ' ' , System . StringSplitOptions . RemoveEmptyEntries ) ;
165
+ return string . Join ( "-" , parts ) ;
166
+ }
167
+
156
168
private readonly Repository _repo = null ;
157
169
private string _name = null ;
158
170
private readonly string _baseOnRevision = null ;
0 commit comments