File tree 2 files changed +28
-7
lines changed 2 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -486,13 +486,18 @@ impl Config {
486
486
_ => unreachable ! ( ) ,
487
487
} ;
488
488
489
- let mut registry = cfg. entry ( "registry" . into ( ) )
490
- . or_insert ( CV :: Table ( HashMap :: new ( ) ,
491
- PathBuf :: from ( "." ) ) ) ;
492
- registry. merge ( value) . chain_err ( || {
493
- format ! ( "failed to merge configuration at `{}`" ,
494
- credentials. display( ) )
495
- } ) ?;
489
+ let registry = cfg. entry ( "registry" . into ( ) )
490
+ . or_insert ( CV :: Table ( HashMap :: new ( ) , PathBuf :: from ( "." ) ) ) ;
491
+
492
+ match ( registry, value) {
493
+ ( & mut CV :: Table ( ref mut old, _) , CV :: Table ( ref mut new, _) ) => {
494
+ let new = mem:: replace ( new, HashMap :: new ( ) ) ;
495
+ for ( key, value) in new. into_iter ( ) {
496
+ old. insert ( key, value) ;
497
+ }
498
+ }
499
+ _ => unreachable ! ( ) ,
500
+ }
496
501
497
502
Ok ( ( ) )
498
503
}
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ use cargotest::cargo_process;
11
11
use cargotest:: support:: execs;
12
12
use cargotest:: support:: registry:: registry;
13
13
use cargotest:: install:: cargo_home;
14
+ use cargo:: util:: config:: Config ;
15
+ use cargo:: core:: Shell ;
14
16
use hamcrest:: { assert_that, existing_file, is_not} ;
15
17
16
18
const TOKEN : & str = "test-token" ;
@@ -110,3 +112,17 @@ fn login_without_credentials() {
110
112
File :: open ( & credentials) . unwrap ( ) . read_to_string ( & mut contents) . unwrap ( ) ;
111
113
assert ! ( check_host_token( contents. parse( ) . unwrap( ) ) ) ;
112
114
}
115
+
116
+ #[ test]
117
+ fn new_credentials_is_used_instead_old ( ) {
118
+ setup_old_credentials ( ) ;
119
+ setup_new_credentials ( ) ;
120
+
121
+ assert_that ( cargo_process ( ) . arg ( "login" )
122
+ . arg ( "--host" ) . arg ( registry ( ) . to_string ( ) ) . arg ( TOKEN ) ,
123
+ execs ( ) . with_status ( 0 ) ) ;
124
+
125
+ let config = Config :: new ( Shell :: new ( ) , cargo_home ( ) , cargo_home ( ) ) ;
126
+ let token = config. get_string ( "registry.token" ) . unwrap ( ) . map ( |p| p. val ) ;
127
+ assert ! ( token. unwrap( ) == TOKEN ) ;
128
+ }
You can’t perform that action at this time.
0 commit comments