From: Lukas Lueg Date: Fri, 27 Oct 2017 13:00:23 +0000 (+0200) Subject: Discover vcs in new-cmd only if --vcs not set X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~5^2~26^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=0c26596a84298ab491a201cf2466476e10f12a5f;p=cargo.git Discover vcs in new-cmd only if --vcs not set If a commandline-argument is given, it takes precedence over the config and existing vcs. Avoid trying to discover existing repositories in that case, saving use from shelling out to `hg`. Fixes #4327 --- diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 10174d0a1..f31e4ade7 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -403,13 +403,17 @@ fn mk(config: &Config, opts: &MkOptions) -> CargoResult<()> { if !opts.bin { "glob:Cargo.lock\n" } else { "" }] .concat(); - let in_existing_vcs_repo = existing_vcs_repo(path.parent().unwrap_or(path), config.cwd()); - let vcs = match (opts.version_control, cfg.version_control, in_existing_vcs_repo) { - (None, None, false) => VersionControl::Git, - (None, Some(option), false) => option, - (Some(option), _, _) => option, - (_, _, true) => VersionControl::NoVcs, - }; + let vcs = opts.version_control + .unwrap_or_else(|| { + let in_existing_vcs = existing_vcs_repo(path.parent().unwrap_or(path), + config.cwd()); + match (cfg.version_control, in_existing_vcs) { + (None, false) => VersionControl::Git, + (Some(opt), false) => opt, + (_, true) => VersionControl::NoVcs, + } + }); + match vcs { VersionControl::Git => { if !fs::metadata(&path.join(".git")).is_ok() {