1
1
use crate :: info:: utils:: info_field:: InfoField ;
2
+ use anyhow:: Result ;
2
3
use gix:: Repository ;
3
4
use regex:: Regex ;
4
5
use serde:: Serialize ;
@@ -16,29 +17,17 @@ impl UrlInfo {
16
17
}
17
18
}
18
19
19
- pub fn get_repo_url ( repo : & Repository , hide_token : bool , http_url : bool ) -> String {
20
- let config = repo. config_snapshot ( ) ;
21
- let remotes = match config. plumbing ( ) . sections_by_name ( "remote" ) {
22
- Some ( sections) => sections,
23
- None => return String :: default ( ) ,
20
+ pub fn get_repo_url ( repo : & Repository , hide_token : bool , http_url : bool ) -> Result < String > {
21
+ let remote = match repo. try_find_remote ( "origin" ) {
22
+ Some ( remote) => remote?,
23
+ None => return Ok ( String :: new ( ) ) ,
24
24
} ;
25
25
26
- let mut remote_url: Option < String > = None ;
27
- for ( name, url) in remotes. filter_map ( |section| {
28
- let remote_name = section. header ( ) . subsection_name ( ) ?;
29
- let url = section. value ( "url" ) ?;
30
- ( remote_name, url) . into ( )
31
- } ) {
32
- remote_url = url. to_string ( ) . into ( ) ;
33
- if name == "origin" {
34
- break ;
35
- }
36
- }
26
+ Ok ( remote
27
+ . url ( gix:: remote:: Direction :: Push )
28
+ . map ( |url| format_url ( & url. to_string ( ) , hide_token, http_url) )
29
+ . unwrap_or_default ( ) )
37
30
38
- match remote_url {
39
- Some ( url) => format_url ( & url, hide_token, http_url) ,
40
- None => String :: default ( ) ,
41
- }
42
31
}
43
32
44
33
fn format_url ( url : & str , hide_token : bool , http_url : bool ) -> String {
0 commit comments