Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fossil VCS support to cargo new #4155

Merged
merged 1 commit into from
Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/bin/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ Usage:
Options:
-h, --help Print this message
--vcs VCS Initialize a new repository for the given version
control system (git, hg, or pijul) or do not initialize any version
control at all (none) overriding a global configuration.
control system (git, hg, pijul, or fossil) or do not
initialize any version control at all (none), overriding
a global configuration.
--bin Use a binary (application) template
--lib Use a library template [default]
--name NAME Set the resulting package name, defaults to the value of <path>
Expand Down
22 changes: 16 additions & 6 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use term::color::BLACK;

use core::Workspace;
use ops::is_bad_artifact_name;
use util::{GitRepo, HgRepo, PijulRepo, internal};
use util::{GitRepo, HgRepo, PijulRepo, FossilRepo, internal};
use util::{Config, paths};
use util::errors::{CargoError, CargoResult, CargoResultExt};

use toml;

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum VersionControl { Git, Hg, Pijul, NoVcs }
pub enum VersionControl { Git, Hg, Pijul, Fossil, NoVcs }

pub struct NewOptions<'a> {
pub version_control: Option<VersionControl>,
Expand Down Expand Up @@ -49,6 +49,7 @@ impl Decodable for VersionControl {
"git" => VersionControl::Git,
"hg" => VersionControl::Hg,
"pijul" => VersionControl::Pijul,
"fossil" => VersionControl::Fossil,
"none" => VersionControl::NoVcs,
n => {
let err = format!("could not decode '{}' as version control", n);
Expand Down Expand Up @@ -340,13 +341,17 @@ pub fn init(opts: NewOptions, config: &Config) -> CargoResult<()> {
num_detected_vsces += 1;
}

if fs::metadata(&path.join(".fossil")).is_ok() {
version_control = Some(VersionControl::Fossil);
num_detected_vsces += 1;
}

// if none exists, maybe create git, like in `cargo new`

if num_detected_vsces > 1 {
bail!("more than one of .hg, .git, or .pijul directories found \
and the ignore file can't be \
filled in as a result, \
specify --vcs to override detection");
bail!("more than one of .hg, .git, .pijul, .fossil configurations \
found and the ignore file can't be filled in as \
a result. specify --vcs to override detection");
}
}

Expand Down Expand Up @@ -415,6 +420,11 @@ fn mk(config: &Config, opts: &MkOptions) -> CargoResult<()> {
PijulRepo::init(path, config.cwd())?;
}
},
VersionControl::Fossil => {
if !fs::metadata(&path.join(".fossil")).is_ok() {
FossilRepo::init(path, config.cwd())?;
}
},
VersionControl::NoVcs => {
fs::create_dir_all(path)?;
},
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub use self::rustc::Rustc;
pub use self::sha256::Sha256;
pub use self::to_semver::ToSemver;
pub use self::to_url::ToUrl;
pub use self::vcs::{GitRepo, HgRepo, PijulRepo};
pub use self::vcs::{GitRepo, HgRepo, PijulRepo, FossilRepo};
pub use self::read2::read2;

pub mod config;
Expand Down
29 changes: 29 additions & 0 deletions src/cargo/util/vcs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::path::Path;
use std::fs::create_dir;

use git2;

Expand All @@ -7,6 +8,7 @@ use util::{CargoResult, process};
pub struct HgRepo;
pub struct GitRepo;
pub struct PijulRepo;
pub struct FossilRepo;

impl GitRepo {
pub fn init(path: &Path, _: &Path) -> CargoResult<GitRepo> {
Expand Down Expand Up @@ -35,3 +37,30 @@ impl PijulRepo {
Ok(PijulRepo)
}
}

impl FossilRepo {
pub fn init(path: &Path, cwd: &Path) -> CargoResult<FossilRepo> {
// fossil doesn't create the directory so we'll do that first
create_dir(path)?;

// set up the paths we'll use
let db_fname = ".fossil";
let mut db_path = path.to_owned();
db_path.push(db_fname);

// then create the fossil DB in that location
process("fossil").cwd(cwd).arg("init").arg(&db_path).exec()?;

// open it in that new directory
process("fossil").cwd(&path).arg("open").arg(db_fname).exec()?;

// set `target` as ignoreable and cleanable
process("fossil").cwd(cwd).arg("settings")
.arg("ignore-glob")
.arg("target");
process("fossil").cwd(cwd).arg("settings")
.arg("clean-glob")
.arg("target");
Ok(FossilRepo)
}
}