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 Pijul support to Cargo #3842

Merged
merged 1 commit into from
Apr 1, 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
2 changes: 1 addition & 1 deletion src/bin/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Usage:
Options:
-h, --help Print this message
--vcs VCS Initialize a new repository for the given version
control system (git or hg) or do not initialize any version
control system (git, hg, or pijul) 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
Expand Down
17 changes: 14 additions & 3 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use git2::Config as GitConfig;
use term::color::BLACK;

use core::Workspace;
use util::{GitRepo, HgRepo, CargoResult, human, ChainError, internal};
use util::{GitRepo, HgRepo, PijulRepo, CargoResult, human, ChainError, internal};
use util::{Config, paths};

use toml;

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

pub struct NewOptions<'a> {
pub version_control: Option<VersionControl>,
Expand Down Expand Up @@ -45,6 +45,7 @@ impl Decodable for VersionControl {
Ok(match &d.read_str()?[..] {
"git" => VersionControl::Git,
"hg" => VersionControl::Hg,
"pijul" => VersionControl::Pijul,
"none" => VersionControl::NoVcs,
n => {
let err = format!("could not decode '{}' as version control", n);
Expand Down Expand Up @@ -331,10 +332,15 @@ pub fn init(opts: NewOptions, config: &Config) -> CargoResult<()> {
num_detected_vsces += 1;
}

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

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

if num_detected_vsces > 1 {
bail!("both .git and .hg directories found \
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");
Expand Down Expand Up @@ -401,6 +407,11 @@ fn mk(config: &Config, opts: &MkOptions) -> CargoResult<()> {
}
paths::append(&path.join(".hgignore"), ignore.as_bytes())?;
},
VersionControl::Pijul => {
if !fs::metadata(&path.join(".pijul")).is_ok() {
PijulRepo::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 @@ -17,7 +17,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};
pub use self::vcs::{GitRepo, HgRepo, PijulRepo};
pub use self::read2::read2;

pub mod config;
Expand Down
7 changes: 7 additions & 0 deletions src/cargo/util/vcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use util::{CargoResult, process};

pub struct HgRepo;
pub struct GitRepo;
pub struct PijulRepo;

impl GitRepo {
pub fn init(path: &Path, _: &Path) -> CargoResult<GitRepo> {
Expand All @@ -28,3 +29,9 @@ impl HgRepo {
}
}

impl PijulRepo {
pub fn init(path: &Path, cwd: &Path) -> CargoResult<PijulRepo> {
process("pijul").cwd(cwd).arg("init").arg(path).exec()?;
Ok(PijulRepo)
}
}