@@ -3,12 +3,9 @@ use crate::util::errors::{CargoResult, CargoResultExt};
3
3
use crate :: util:: { existing_vcs_repo, FossilRepo , GitRepo , HgRepo , PijulRepo } ;
4
4
use crate :: util:: { restricted_names, Config } ;
5
5
use cargo_util:: paths;
6
- use git2:: Config as GitConfig ;
7
- use git2:: Repository as GitRepository ;
8
6
use serde:: de;
9
7
use serde:: Deserialize ;
10
8
use std:: collections:: BTreeMap ;
11
- use std:: env;
12
9
use std:: fmt;
13
10
use std:: io:: { BufRead , BufReader , ErrorKind } ;
14
11
use std:: path:: { Path , PathBuf } ;
@@ -129,8 +126,6 @@ impl NewOptions {
129
126
130
127
#[ derive( Deserialize ) ]
131
128
struct CargoNewConfig {
132
- name : Option < String > ,
133
- email : Option < String > ,
134
129
#[ serde( rename = "vcs" ) ]
135
130
version_control : Option < VersionControl > ,
136
131
}
@@ -666,32 +661,6 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
666
661
init_vcs ( path, vcs, config) ?;
667
662
write_ignore_file ( path, & ignore, vcs) ?;
668
663
669
- let ( discovered_name, discovered_email) = discover_author ( path) ;
670
-
671
- // "Name <email>" or "Name" or "<email>" or None if neither name nor email is obtained
672
- // cfg takes priority over the discovered ones
673
- let author_name = cfg. name . or ( discovered_name) ;
674
- let author_email = cfg. email . or ( discovered_email) ;
675
-
676
- let author = match ( author_name, author_email) {
677
- ( Some ( name) , Some ( email) ) => {
678
- if email. is_empty ( ) {
679
- Some ( name)
680
- } else {
681
- Some ( format ! ( "{} <{}>" , name, email) )
682
- }
683
- }
684
- ( Some ( name) , None ) => Some ( name) ,
685
- ( None , Some ( email) ) => {
686
- if email. is_empty ( ) {
687
- None
688
- } else {
689
- Some ( format ! ( "<{}>" , email) )
690
- }
691
- }
692
- ( None , None ) => None ,
693
- } ;
694
-
695
664
let mut cargotoml_path_specifier = String :: new ( ) ;
696
665
697
666
// Calculate what `[lib]` and `[[bin]]`s we need to append to `Cargo.toml`.
@@ -730,18 +699,13 @@ path = {}
730
699
r#"[package]
731
700
name = "{}"
732
701
version = "0.1.0"
733
- authors = [{}]
734
702
edition = {}
735
703
{}
736
704
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
737
705
738
706
[dependencies]
739
707
{}"# ,
740
708
name,
741
- match author {
742
- Some ( value) => format!( "{}" , toml:: Value :: String ( value) ) ,
743
- None => format!( "" ) ,
744
- } ,
745
709
match opts. edition {
746
710
Some ( edition) => toml:: Value :: String ( edition. to_string( ) ) ,
747
711
None => toml:: Value :: String ( Edition :: LATEST_STABLE . to_string( ) ) ,
@@ -811,76 +775,3 @@ mod tests {
811
775
812
776
Ok ( ( ) )
813
777
}
814
-
815
- fn get_environment_variable ( variables : & [ & str ] ) -> Option < String > {
816
- variables. iter ( ) . filter_map ( |var| env:: var ( var) . ok ( ) ) . next ( )
817
- }
818
-
819
- fn discover_author ( path : & Path ) -> ( Option < String > , Option < String > ) {
820
- let git_config = find_git_config ( path) ;
821
- let git_config = git_config. as_ref ( ) ;
822
-
823
- let name_variables = [
824
- "CARGO_NAME" ,
825
- "GIT_AUTHOR_NAME" ,
826
- "GIT_COMMITTER_NAME" ,
827
- "USER" ,
828
- "USERNAME" ,
829
- "NAME" ,
830
- ] ;
831
- let name = get_environment_variable ( & name_variables[ 0 ..3 ] )
832
- . or_else ( || git_config. and_then ( |g| g. get_string ( "user.name" ) . ok ( ) ) )
833
- . or_else ( || get_environment_variable ( & name_variables[ 3 ..] ) ) ;
834
-
835
- let name = name. map ( |namestr| namestr. trim ( ) . to_string ( ) ) ;
836
-
837
- let email_variables = [
838
- "CARGO_EMAIL" ,
839
- "GIT_AUTHOR_EMAIL" ,
840
- "GIT_COMMITTER_EMAIL" ,
841
- "EMAIL" ,
842
- ] ;
843
- let email = get_environment_variable ( & email_variables[ 0 ..3 ] )
844
- . or_else ( || git_config. and_then ( |g| g. get_string ( "user.email" ) . ok ( ) ) )
845
- . or_else ( || get_environment_variable ( & email_variables[ 3 ..] ) ) ;
846
-
847
- let email = email. map ( |s| {
848
- let mut s = s. trim ( ) ;
849
-
850
- // In some cases emails will already have <> remove them since they
851
- // are already added when needed.
852
- if s. starts_with ( '<' ) && s. ends_with ( '>' ) {
853
- s = & s[ 1 ..s. len ( ) - 1 ] ;
854
- }
855
-
856
- s. to_string ( )
857
- } ) ;
858
-
859
- ( name, email)
860
- }
861
-
862
- fn find_git_config ( path : & Path ) -> Option < GitConfig > {
863
- match env:: var ( "__CARGO_TEST_ROOT" ) {
864
- Ok ( _) => find_tests_git_config ( path) ,
865
- Err ( _) => find_real_git_config ( path) ,
866
- }
867
- }
868
-
869
- fn find_tests_git_config ( path : & Path ) -> Option < GitConfig > {
870
- // Don't escape the test sandbox when looking for a git repository.
871
- // NOTE: libgit2 has support to define the path ceiling in
872
- // git_repository_discover, but the git2 bindings do not expose that.
873
- for path in paths:: ancestors ( path, None ) {
874
- if let Ok ( repo) = GitRepository :: open ( path) {
875
- return Some ( repo. config ( ) . expect ( "test repo should have valid config" ) ) ;
876
- }
877
- }
878
- GitConfig :: open_default ( ) . ok ( )
879
- }
880
-
881
- fn find_real_git_config ( path : & Path ) -> Option < GitConfig > {
882
- GitRepository :: discover ( path)
883
- . and_then ( |repo| repo. config ( ) )
884
- . or_else ( |_| GitConfig :: open_default ( ) )
885
- . ok ( )
886
- }
0 commit comments