1+ use crate :: bstr:: ByteSlice ;
12use crate :: repository:: { branch_remote_ref_name, branch_remote_tracking_ref_name} ;
23use crate :: { remote, Reference } ;
3- use gix_ref:: FullNameRef ;
4+ use gix_ref:: { Category , FullNameRef } ;
45use std:: borrow:: Cow ;
56
67/// Remotes
@@ -9,8 +10,31 @@ impl<'repo> Reference<'repo> {
910 /// Return `None` if no remote is configured.
1011 ///
1112 /// See also [`Repository::branch_remote_name()`](crate::Repository::branch_remote_name()) for more details.
12- pub fn remote_name ( & self , direction : remote:: Direction ) -> Option < remote:: Name < ' repo > > {
13- self . repo . branch_remote_name ( self . name ( ) . shorten ( ) , direction)
13+ pub fn remote_name ( & self , direction : remote:: Direction ) -> Option < remote:: Name < ' _ > > {
14+ let ( category, shortname) = self . name ( ) . category_and_short_name ( ) ?;
15+ match category {
16+ Category :: RemoteBranch => {
17+ if shortname. find_iter ( "/" ) . take ( 2 ) . count ( ) == 1 {
18+ let slash_pos = shortname. find_byte ( b'/' ) . expect ( "it was just found" ) ;
19+ shortname[ ..slash_pos]
20+ . as_bstr ( )
21+ . to_str ( )
22+ . ok ( )
23+ . map ( |n| remote:: Name :: Symbol ( n. into ( ) ) )
24+ } else {
25+ let remotes = self . repo . remote_names ( ) ;
26+ for slash_pos in shortname. rfind_iter ( "/" ) {
27+ let candidate = shortname[ ..slash_pos] . as_bstr ( ) ;
28+ if remotes. contains ( candidate) {
29+ return candidate. to_str ( ) . ok ( ) . map ( |n| remote:: Name :: Symbol ( n. into ( ) ) ) ;
30+ }
31+ }
32+ None
33+ }
34+ }
35+ Category :: LocalBranch => self . repo . branch_remote_name ( shortname, direction) ,
36+ _ => None ,
37+ }
1438 }
1539
1640 /// Find the remote along with all configuration associated with it suitable for handling this reference.
0 commit comments