11mod existing {
22 use git_testtools:: hex_to_id;
3+ use std:: convert:: { TryFrom , TryInto } ;
34
45 use crate :: file:: store_at;
56
@@ -13,6 +14,69 @@ mod existing {
1314 assert_eq ! ( r. name. as_bstr( ) , "refs/heads/main" ) ;
1415 Ok ( ( ) )
1516 }
17+
18+ /// Gain an understanding how uses might want to call this function, and see what happens
19+ #[ test]
20+ fn possible_inputs ( ) -> crate :: Result {
21+ let store = crate :: file:: store ( ) ?;
22+ store. find_loose ( "dt1" ) ?;
23+ store. find_loose ( & String :: from ( "dt1" ) ) ?; // Owned Strings don't have an impl for PartialName
24+
25+ struct CustomType ( String ) ;
26+ impl < ' a > TryFrom < & ' a CustomType > for git_ref:: PartialNameRef < ' a > {
27+ type Error = git_ref:: name:: Error ;
28+
29+ fn try_from ( value : & ' a CustomType ) -> Result < Self , Self :: Error > {
30+ git_ref:: PartialNameRef :: try_from ( & value. 0 )
31+ }
32+ }
33+ store. find_loose ( & CustomType ( "dt1" . into ( ) ) ) ?;
34+
35+ struct CustomName {
36+ remote : & ' static str ,
37+ branch : & ' static str ,
38+ }
39+
40+ impl CustomName {
41+ fn to_partial_name ( & self ) -> String {
42+ format ! ( "{}/{}" , self . remote, self . branch)
43+ }
44+ fn to_partial_name_from_string ( & self ) -> git_ref:: PartialNameRef < ' static > {
45+ self . to_partial_name ( ) . try_into ( ) . expect ( "cannot fail" )
46+ }
47+ fn to_partial_name_from_bstring ( & self ) -> git_ref:: PartialNameRef < ' static > {
48+ git_object:: bstr:: BString :: from ( self . to_partial_name ( ) )
49+ . try_into ( )
50+ . expect ( "cannot fail" )
51+ }
52+ fn to_full_name ( & self ) -> git_ref:: FullName {
53+ format ! ( "{}/{}" , self . remote, self . branch)
54+ . try_into ( )
55+ . expect ( "always valid" )
56+ }
57+ }
58+
59+ impl < ' a > TryFrom < & ' a CustomName > for git_ref:: PartialNameRef < ' static > {
60+ type Error = git_ref:: name:: Error ;
61+
62+ fn try_from ( value : & ' a CustomName ) -> Result < Self , Self :: Error > {
63+ git_ref:: PartialNameRef :: try_from ( value. to_partial_name ( ) )
64+ }
65+ }
66+
67+ let name = CustomName {
68+ remote : "origin" ,
69+ branch : "main" ,
70+ } ;
71+ store. find_loose ( & name. to_partial_name ( ) ) ?;
72+ store. find_loose ( name. to_partial_name ( ) ) ?;
73+ store. find_loose ( name. to_partial_name_from_string ( ) ) ?;
74+ store. find_loose ( name. to_partial_name_from_bstring ( ) ) ?;
75+ store. find_loose ( name. to_full_name ( ) . to_partial ( ) ) ?;
76+ store. find_loose ( & name) ?;
77+
78+ Ok ( ( ) )
79+ }
1680}
1781
1882mod loose {
0 commit comments