Skip to content

Commit

Permalink
Auto merge of #4665 - lukaslueg:issue4327, r=matklad
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Oct 27, 2017
2 parents e5562dd + 0c26596 commit 1c9dc0a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 1c9dc0a

Please sign in to comment.