@@ -2,8 +2,47 @@ use crate::{bstr::BStr, remote, Remote};
22
33/// Builder methods
44impl Remote < ' _ > {
5+ /// Override the `url` to be used when fetching data from a remote.
6+ ///
7+ /// Note that this URL is typically set during instantiation with [`crate::Repository::remote_at()`].
8+ pub fn with_url < Url , E > ( self , url : Url ) -> Result < Self , remote:: init:: Error >
9+ where
10+ Url : TryInto < gix_url:: Url , Error = E > ,
11+ gix_url:: parse:: Error : From < E > ,
12+ {
13+ self . url_inner (
14+ url. try_into ( ) . map_err ( |err| remote:: init:: Error :: Url ( err. into ( ) ) ) ?,
15+ true ,
16+ )
17+ }
18+
19+ /// Set the `url` to be used when fetching data from a remote, without applying rewrite rules in case these could be faulty,
20+ /// eliminating one failure mode.
21+ ///
22+ /// Note that this URL is typically set during instantiation with [`crate::Repository::remote_at_without_url_rewrite()`].
23+ pub fn with_url_without_url_rewrite < Url , E > ( self , url : Url ) -> Result < Self , remote:: init:: Error >
24+ where
25+ Url : TryInto < gix_url:: Url , Error = E > ,
26+ gix_url:: parse:: Error : From < E > ,
27+ {
28+ self . url_inner (
29+ url. try_into ( ) . map_err ( |err| remote:: init:: Error :: Url ( err. into ( ) ) ) ?,
30+ false ,
31+ )
32+ }
33+
534 /// Set the `url` to be used when pushing data to a remote.
35+ #[ deprecated = "Use `with_push_url()` instead" ]
636 pub fn push_url < Url , E > ( self , url : Url ) -> Result < Self , remote:: init:: Error >
37+ where
38+ Url : TryInto < gix_url:: Url , Error = E > ,
39+ gix_url:: parse:: Error : From < E > ,
40+ {
41+ self . with_push_url ( url)
42+ }
43+
44+ /// Set the `url` to be used when pushing data to a remote.
45+ pub fn with_push_url < Url , E > ( self , url : Url ) -> Result < Self , remote:: init:: Error >
746 where
847 Url : TryInto < gix_url:: Url , Error = E > ,
948 gix_url:: parse:: Error : From < E > ,
@@ -16,7 +55,18 @@ impl Remote<'_> {
1655
1756 /// Set the `url` to be used when pushing data to a remote, without applying rewrite rules in case these could be faulty,
1857 /// eliminating one failure mode.
58+ #[ deprecated = "Use `with_push_url_without_rewrite()` instead" ]
1959 pub fn push_url_without_url_rewrite < Url , E > ( self , url : Url ) -> Result < Self , remote:: init:: Error >
60+ where
61+ Url : TryInto < gix_url:: Url , Error = E > ,
62+ gix_url:: parse:: Error : From < E > ,
63+ {
64+ self . with_push_url_without_url_rewrite ( url)
65+ }
66+
67+ /// Set the `url` to be used when pushing data to a remote, without applying rewrite rules in case these could be faulty,
68+ /// eliminating one failure mode.
69+ pub fn with_push_url_without_url_rewrite < Url , E > ( self , url : Url ) -> Result < Self , remote:: init:: Error >
2070 where
2171 Url : TryInto < gix_url:: Url , Error = E > ,
2272 gix_url:: parse:: Error : From < E > ,
@@ -50,6 +100,19 @@ impl Remote<'_> {
50100 Ok ( self )
51101 }
52102
103+ fn url_inner ( mut self , url : gix_url:: Url , should_rewrite_urls : bool ) -> Result < Self , remote:: init:: Error > {
104+ self . url = url. into ( ) ;
105+
106+ let ( fetch_url_alias, _) = if should_rewrite_urls {
107+ remote:: init:: rewrite_urls ( & self . repo . config , self . url . as_ref ( ) , None )
108+ } else {
109+ Ok ( ( None , None ) )
110+ } ?;
111+ self . url_alias = fetch_url_alias;
112+
113+ Ok ( self )
114+ }
115+
53116 /// Add `specs` as refspecs for `direction` to our list if they are unique, or ignore them otherwise.
54117 pub fn with_refspecs < Spec > (
55118 mut self ,
0 commit comments