File tree 3 files changed +66
-0
lines changed
3 files changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -259,6 +259,17 @@ impl SourceId {
259
259
}
260
260
}
261
261
262
+ /// Returns `true` if this source is a "remote" registry.
263
+ ///
264
+ /// "remote" may also mean a file URL to a git index, so it is not
265
+ /// necessarily "remote". This just means it is not `local-registry`.
266
+ pub fn is_remote_registry ( self ) -> bool {
267
+ match self . inner . kind {
268
+ Kind :: Registry => true ,
269
+ _ => false ,
270
+ }
271
+ }
272
+
262
273
/// Returns `true` if this source from a Git repository.
263
274
pub fn is_git ( self ) -> bool {
264
275
match self . inner . kind {
Original file line number Diff line number Diff line change @@ -345,6 +345,13 @@ fn registry(
345
345
} = registry_configuration ( config, registry. clone ( ) ) ?;
346
346
let token = token. or ( token_config) ;
347
347
let sid = get_source_id ( config, index_config. or ( index) , registry) ?;
348
+ if !sid. is_remote_registry ( ) {
349
+ bail ! (
350
+ "{} does not support API commands.\n \
351
+ Check for a source-replacement in .cargo/config.",
352
+ sid
353
+ ) ;
354
+ }
348
355
let api_host = {
349
356
let _lock = config. acquire_package_cache_lock ( ) ?;
350
357
let mut src = RegistrySource :: remote ( sid, & HashSet :: new ( ) , config) ;
Original file line number Diff line number Diff line change @@ -1022,3 +1022,51 @@ fn publish_checks_for_token_before_verify() {
1022
1022
. with_stderr_contains ( "[VERIFYING] foo v0.0.1 ([CWD])" )
1023
1023
. run ( ) ;
1024
1024
}
1025
+
1026
+ #[ cargo_test]
1027
+ fn publish_with_bad_source ( ) {
1028
+ let p = project ( )
1029
+ . file (
1030
+ ".cargo/config" ,
1031
+ r#"
1032
+ [source.crates-io]
1033
+ replace-with = 'local-registry'
1034
+
1035
+ [source.local-registry]
1036
+ local-registry = 'registry'
1037
+ "# ,
1038
+ )
1039
+ . file ( "src/lib.rs" , "" )
1040
+ . build ( ) ;
1041
+
1042
+ p. cargo ( "publish" )
1043
+ . with_status ( 101 )
1044
+ . with_stderr (
1045
+ "\
1046
+ [ERROR] registry `[..]/foo/registry` does not support API commands.
1047
+ Check for a source-replacement in .cargo/config.
1048
+ " ,
1049
+ )
1050
+ . run ( ) ;
1051
+
1052
+ p. change_file (
1053
+ ".cargo/config" ,
1054
+ r#"
1055
+ [source.crates-io]
1056
+ replace-with = "vendored-sources"
1057
+
1058
+ [source.vendored-sources]
1059
+ directory = "vendor"
1060
+ "# ,
1061
+ ) ;
1062
+
1063
+ p. cargo ( "publish" )
1064
+ . with_status ( 101 )
1065
+ . with_stderr (
1066
+ "\
1067
+ [ERROR] dir [..]/foo/vendor does not support API commands.
1068
+ Check for a source-replacement in .cargo/config.
1069
+ " ,
1070
+ )
1071
+ . run ( ) ;
1072
+ }
You can’t perform that action at this time.
0 commit comments