Discover vcs in new-cmd only if --vcs not set
authorLukas Lueg <lukas.lueg@gmail.com>
Fri, 27 Oct 2017 13:00:23 +0000 (15:00 +0200)
committerLukas Lueg <lukas.lueg@gmail.com>
Fri, 27 Oct 2017 13:00:23 +0000 (15:00 +0200)
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

src/cargo/ops/cargo_new.rs

index 10174d0a142c3f24388455b8eef642f952e9b91f..f31e4ade7e44a1c12cb51a0d8a79adbb89046f5a 100644 (file)
@@ -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() {