@@ -2,8 +2,47 @@ use crate::{bstr::BStr, remote, Remote};
2
2
3
3
/// Builder methods
4
4
impl 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
+
5
34
/// Set the `url` to be used when pushing data to a remote.
35
+ #[ deprecated = "Use `with_push_url()` instead" ]
6
36
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 >
7
46
where
8
47
Url : TryInto < gix_url:: Url , Error = E > ,
9
48
gix_url:: parse:: Error : From < E > ,
@@ -16,7 +55,18 @@ impl Remote<'_> {
16
55
17
56
/// Set the `url` to be used when pushing data to a remote, without applying rewrite rules in case these could be faulty,
18
57
/// eliminating one failure mode.
58
+ #[ deprecated = "Use `with_push_url_without_rewrite()` instead" ]
19
59
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 >
20
70
where
21
71
Url : TryInto < gix_url:: Url , Error = E > ,
22
72
gix_url:: parse:: Error : From < E > ,
@@ -50,6 +100,19 @@ impl Remote<'_> {
50
100
Ok ( self )
51
101
}
52
102
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
+
53
116
/// Add `specs` as refspecs for `direction` to our list if they are unique, or ignore them otherwise.
54
117
pub fn with_refspecs < Spec > (
55
118
mut self ,
0 commit comments