@@ -139,7 +139,7 @@ impl Index {
139
139
. and_then ( |r| r. try_id ( ) . map ( |id| id. detach ( ) ) )
140
140
. unwrap_or_else ( || git:: hash:: ObjectId :: empty_tree ( repo. object_hash ( ) ) ) ;
141
141
let to = {
142
- let remote = self
142
+ let mut remote = self
143
143
. remote_name
144
144
. and_then ( |name| {
145
145
self . repo . find_remote ( name) . ok ( ) . or_else ( || {
@@ -171,20 +171,21 @@ impl Index {
171
171
. map ( |r| r. map_err ( Error :: from) )
172
172
} )
173
173
. unwrap_or_else ( || {
174
- let spec = format ! (
175
- "+refs/heads/{branch}:refs/remotes/{remote}/{branch}" ,
176
- remote = self . remote_name. unwrap_or( "origin" ) ,
177
- branch = self . branch_name,
178
- ) ;
179
174
self . repo
180
175
. remote_at ( "https://github.com/rust-lang/crates.io-index" )
181
176
. map_err ( Into :: into)
182
- . map ( |r| {
183
- r. with_refspec ( spec. as_str ( ) , git:: remote:: Direction :: Fetch )
184
- . expect ( "valid refspec" )
185
- } )
186
177
} )
187
178
} ) ?;
179
+ if remote. refspecs ( git:: remote:: Direction :: Fetch ) . is_empty ( ) {
180
+ let spec = format ! (
181
+ "+refs/heads/{branch}:refs/remotes/{remote}/{branch}" ,
182
+ remote = self . remote_name. unwrap_or( "origin" ) ,
183
+ branch = self . branch_name,
184
+ ) ;
185
+ remote
186
+ . replace_refspecs ( Some ( spec. as_str ( ) ) , git:: remote:: Direction :: Fetch )
187
+ . expect ( "valid statically known refspec" ) ;
188
+ }
188
189
let res: git:: remote:: fetch:: Outcome < ' _ > = remote
189
190
. connect ( git:: remote:: Direction :: Fetch , progress) ?
190
191
. prepare_fetch ( Default :: default ( ) ) ?
0 commit comments