File tree Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Expand file tree Collapse file tree 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> {
106106 pub fn to_owned ( & self ) -> FullName {
107107 FullName ( self . 0 . to_owned ( ) )
108108 }
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+ }
109115}
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ pub type Error = git_validate::reference::name::Error;
1313
1414impl < ' a > FullNameRef < ' a > {
1515 /// 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.
1618 pub fn to_path ( self ) -> Cow < ' a , Path > {
1719 self . 0 . to_path ( ) . expect ( "UTF-8 conversion always succeeds" ) . into ( )
1820 }
Original file line number Diff line number Diff line change 11use std:: convert:: TryInto ;
22
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+
39#[ test]
410fn prefix_with_namespace_and_stripping ( ) {
511 let ns = git_ref:: namespace:: expand ( "foo" ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments