Skip to content

Commit

Permalink
Auto merge of #3842 - pwoolcoc:add-pijul-vcs-support, r=alexcrichton
Browse files Browse the repository at this point in the history
Add Pijul support to Cargo

[Pijul](https://pijul.org) is a version control system written in Rust. This commit adds the ability to create a cargo project using pijul as the vcs for the project.

To use it, run `cargo new my-awesome-project --vcs=pijul`
  • Loading branch information
bors committed Apr 1, 2017
2 parents 35bf210 + 2b31978 commit 4729175
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
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)
}
}

0 comments on commit 4729175

Please # to comment.