@@ -69,7 +69,7 @@ impl ProtofetchGitCache {
69
69
pub fn repository ( & self , entry : & Coordinate ) -> Result < ProtoGitRepository , CacheError > {
70
70
let repo = match self . get_entry ( entry) {
71
71
None => self . clone_repo ( entry) ?,
72
- Some ( path) => self . open_entry ( & path) ?,
72
+ Some ( path) => self . open_entry ( & path, entry ) ?,
73
73
} ;
74
74
75
75
Ok ( ProtoGitRepository :: new ( self , repo) )
@@ -90,8 +90,28 @@ impl ProtofetchGitCache {
90
90
}
91
91
}
92
92
93
- fn open_entry ( & self , path : & Path ) -> Result < Repository , CacheError > {
94
- Repository :: open ( path) . map_err ( |e| e. into ( ) )
93
+ fn open_entry ( & self , path : & Path , entry : & Coordinate ) -> Result < Repository , CacheError > {
94
+ let repo = Repository :: open ( path) . map_err ( CacheError :: from) ?;
95
+
96
+ {
97
+ let remote = repo. find_remote ( "origin" ) . map_err ( CacheError :: from) ?;
98
+
99
+ if let ( Some ( url) , Some ( protocol) ) = ( remote. url ( ) , entry. protocol ) {
100
+ let new_url = entry. to_git_url ( protocol) ;
101
+
102
+ if url != new_url {
103
+ // If true then the protocol was updated before updating the cache.
104
+ trace ! (
105
+ "Updating remote existing url {} to new url {}" ,
106
+ url,
107
+ new_url
108
+ ) ;
109
+ repo. remote_set_url ( "origin" , & new_url) ?;
110
+ }
111
+ }
112
+ } // `remote` reference is dropped here so that we can return `repo`
113
+
114
+ Ok ( repo)
95
115
}
96
116
97
117
fn clone_repo ( & self , entry : & Coordinate ) -> Result < Repository , CacheError > {
0 commit comments