Skip to content

Commit db48c63

Browse files
committed
Auto merge of #5812 - dwijnand:move-existing_vcs_repo, r=alexcrichton
Move existing_vcs_repo to the util::vcs module Rather than being in cargo_new publically exposed and used by cargo fix. Just a proposal, as it looked weird to me.
2 parents 03e8934 + eea58f2 commit db48c63

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

src/cargo/ops/cargo_new.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use git2::Config as GitConfig;
88
use git2::Repository as GitRepository;
99

1010
use core::{compiler, Workspace};
11-
use util::{internal, FossilRepo, GitRepo, HgRepo, PijulRepo};
11+
use util::{internal, FossilRepo, GitRepo, HgRepo, PijulRepo, existing_vcs_repo};
1212
use util::{paths, Config};
1313
use util::errors::{CargoResult, CargoResultExt};
1414

@@ -409,21 +409,6 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<()> {
409409
Ok(())
410410
}
411411

412-
// Check if we are in an existing repo. We define that to be true if either:
413-
//
414-
// 1. We are in a git repo and the path to the new project is not an ignored
415-
// path in that repo.
416-
// 2. We are in an HG repo.
417-
pub fn existing_vcs_repo(path: &Path, cwd: &Path) -> bool {
418-
fn in_git_repo(path: &Path, cwd: &Path) -> bool {
419-
if let Ok(repo) = GitRepo::discover(path, cwd) {
420-
repo.is_path_ignored(path).map(|ignored| !ignored).unwrap_or(true)
421-
} else { false }
422-
}
423-
424-
in_git_repo(path, cwd) || HgRepo::discover(path, cwd).is_ok()
425-
}
426-
427412
fn mk(config: &Config, opts: &MkOptions) -> CargoResult<()> {
428413
let path = opts.path;
429414
let name = opts.name;

src/cargo/ops/fix.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ use serde_json;
1414

1515
use core::Workspace;
1616
use ops::{self, CompileOptions};
17-
use ops::cargo_new::existing_vcs_repo;
1817
use util::errors::CargoResult;
19-
use util::{LockServer, LockServerClient};
18+
use util::{LockServer, LockServerClient, existing_vcs_repo};
2019
use util::diagnostic_server::{Message, RustfixDiagnosticServer};
2120
use util::paths;
2221

src/cargo/util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use self::rustc::Rustc;
1515
pub use self::sha256::Sha256;
1616
pub use self::to_semver::ToSemver;
1717
pub use self::to_url::ToUrl;
18-
pub use self::vcs::{FossilRepo, GitRepo, HgRepo, PijulRepo};
18+
pub use self::vcs::{FossilRepo, GitRepo, HgRepo, PijulRepo, existing_vcs_repo};
1919
pub use self::read2::read2;
2020
pub use self::progress::{Progress, ProgressStyle};
2121
pub use self::lockserver::{LockServer, LockServerStarted, LockServerClient};

src/cargo/util/vcs.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ use git2;
55

66
use util::{process, CargoResult};
77

8+
// Check if we are in an existing repo. We define that to be true if either:
9+
//
10+
// 1. We are in a git repo and the path to the new project is not an ignored
11+
// path in that repo.
12+
// 2. We are in an HG repo.
13+
pub fn existing_vcs_repo(path: &Path, cwd: &Path) -> bool {
14+
fn in_git_repo(path: &Path, cwd: &Path) -> bool {
15+
if let Ok(repo) = GitRepo::discover(path, cwd) {
16+
repo.is_path_ignored(path).map(|ignored| !ignored).unwrap_or(true)
17+
} else { false }
18+
}
19+
20+
in_git_repo(path, cwd) || HgRepo::discover(path, cwd).is_ok()
21+
}
22+
823
pub struct HgRepo;
924
pub struct GitRepo;
1025
pub struct PijulRepo;

0 commit comments

Comments
 (0)