File tree 3 files changed +14
-0
lines changed
3 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -106,4 +106,10 @@ impl<'a> FullNameRef<'a> {
106
106
pub fn to_owned ( & self ) -> FullName {
107
107
FullName ( self . 0 . to_owned ( ) )
108
108
}
109
+
110
+ /// Return the file name portion of a full name, for instance `main` if the
111
+ /// full name was `refs/heads/main`.
112
+ pub fn file_name ( & self ) -> & BStr {
113
+ self . 0 . rsplitn ( 2 , |b| * b == b'/' ) . next ( ) . expect ( "valid ref" ) . as_bstr ( )
114
+ }
109
115
}
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ pub type Error = git_validate::reference::name::Error;
13
13
14
14
impl < ' a > FullNameRef < ' a > {
15
15
/// Convert this name into the relative path identifying the reference location.
16
+ // TODO: use custom `Path` type instead, as this isn't really a path. See ref iteration with prefix for
17
+ // similar comment.
16
18
pub fn to_path ( self ) -> Cow < ' a , Path > {
17
19
self . 0 . to_path ( ) . expect ( "UTF-8 conversion always succeeds" ) . into ( )
18
20
}
Original file line number Diff line number Diff line change 1
1
use std:: convert:: TryInto ;
2
2
3
+ #[ test]
4
+ fn file_name ( ) {
5
+ let name: git_ref:: FullName = "refs/heads/main" . try_into ( ) . unwrap ( ) ;
6
+ assert_eq ! ( name. to_ref( ) . file_name( ) , "main" ) ;
7
+ }
8
+
3
9
#[ test]
4
10
fn prefix_with_namespace_and_stripping ( ) {
5
11
let ns = git_ref:: namespace:: expand ( "foo" ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments