File tree 2 files changed +21
-0
lines changed
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -2740,6 +2740,7 @@ extern "C" {
2740
2740
force : c_int ,
2741
2741
) -> c_int ;
2742
2742
pub fn git_branch_name ( out : * mut * const c_char , branch : * const git_reference ) -> c_int ;
2743
+ pub fn git_branch_name_is_valid ( valid : * mut c_int , name : * const c_char ) -> c_int ;
2743
2744
pub fn git_branch_remote_name (
2744
2745
out : * mut git_buf ,
2745
2746
repo : * mut git_repository ,
@@ -3072,6 +3073,7 @@ extern "C" {
3072
3073
) -> c_int ;
3073
3074
pub fn git_tag_message ( tag : * const git_tag ) -> * const c_char ;
3074
3075
pub fn git_tag_name ( tag : * const git_tag ) -> * const c_char ;
3076
+ pub fn git_tag_name_is_valid ( valid : * mut c_int , name : * const c_char ) -> c_int ;
3075
3077
pub fn git_tag_peel ( tag_target_out : * mut * mut git_object , tag : * const git_tag ) -> c_int ;
3076
3078
pub fn git_tag_tagger ( tag : * const git_tag ) -> * const git_signature ;
3077
3079
pub fn git_tag_target ( target_out : * mut * mut git_object , tag : * const git_tag ) -> c_int ;
Original file line number Diff line number Diff line change @@ -28,6 +28,16 @@ impl<'repo> Branch<'repo> {
28
28
Branch { inner : reference }
29
29
}
30
30
31
+ /// Ensure the branch name is well-formed.
32
+ pub fn name_is_valid ( name : & str ) -> Result < bool , Error > {
33
+ let name = CString :: new ( name) . unwrap ( ) ;
34
+ let mut valid: libc:: c_int = 0 ;
35
+ unsafe {
36
+ try_call ! ( raw:: git_branch_name_is_valid( & mut valid, name. as_ptr( ) ) ) ;
37
+ }
38
+ Ok ( valid == 1 )
39
+ }
40
+
31
41
/// Gain access to the reference that is this branch
32
42
pub fn get ( & self ) -> & Reference < ' repo > {
33
43
& self . inner
@@ -151,6 +161,7 @@ impl<'repo> Drop for Branches<'repo> {
151
161
152
162
#[ cfg( test) ]
153
163
mod tests {
164
+ use crate :: Branch ;
154
165
use crate :: BranchType ;
155
166
156
167
#[ test]
@@ -175,4 +186,12 @@ mod tests {
175
186
176
187
b1. delete ( ) . unwrap ( ) ;
177
188
}
189
+
190
+ #[ test]
191
+ fn name_is_valid ( ) {
192
+ assert ! ( Branch :: name_is_valid( "foo" ) . unwrap( ) ) ;
193
+ assert ! ( !Branch :: name_is_valid( "" ) . unwrap( ) ) ;
194
+ assert ! ( !Branch :: name_is_valid( "with spaces" ) . unwrap( ) ) ;
195
+ assert ! ( !Branch :: name_is_valid( "~tilde" ) . unwrap( ) ) ;
196
+ }
178
197
}
You can’t perform that action at this time.
0 commit comments