11use crate :: info:: utils:: info_field:: InfoField ;
2+ use anyhow:: Result ;
23use gix:: Repository ;
34use regex:: Regex ;
45use serde:: Serialize ;
@@ -16,29 +17,17 @@ impl UrlInfo {
1617 }
1718}
1819
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 ( ) ) ,
2424 } ;
2525
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 ( ) )
3730
38- match remote_url {
39- Some ( url) => format_url ( & url, hide_token, http_url) ,
40- None => String :: default ( ) ,
41- }
4231}
4332
4433fn format_url ( url : & str , hide_token : bool , http_url : bool ) -> String {
0 commit comments