From b455b6747b6f61f074c7b22268bc9a99f304178e Mon Sep 17 00:00:00 2001 From: Michal Date: Sat, 23 Jul 2022 03:26:30 +0100 Subject: [PATCH] Implemented cloning specific branches --- examples/workspace/mlc.toml | 2 +- src/internal/structs.rs | 1 + src/operations/clone.rs | 5 +++++ src/workspace/read.rs | 19 ++++++++++++++++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/examples/workspace/mlc.toml b/examples/workspace/mlc.toml index 77b0e6a..fa6d8b0 100644 --- a/examples/workspace/mlc.toml +++ b/examples/workspace/mlc.toml @@ -16,7 +16,7 @@ on_gen = false [repositories] name = [ "1::amethyst", - "1::jade!", + "1::malachite@development!", "2::notop-git", "3::appendage", ] diff --git a/src/internal/structs.rs b/src/internal/structs.rs index a44a0d6..ce9f916 100755 --- a/src/internal/structs.rs +++ b/src/internal/structs.rs @@ -60,6 +60,7 @@ pub struct ConfigRepositoriesExpanded { pub struct Repo { pub name: String, pub url: String, + pub branch: Option, pub priority: usize, } diff --git a/src/operations/clone.rs b/src/operations/clone.rs index 3d78741..74e442f 100644 --- a/src/operations/clone.rs +++ b/src/operations/clone.rs @@ -47,6 +47,11 @@ pub fn clone(verbose: bool) { info!("Cloning ({} mode): {}", config.base.mode, r.name); Command::new("git") .args(&["clone", &r.url, &r.name]) + .args(if r.branch.is_some() { + vec!["-b", r.branch.as_ref().unwrap()] + } else { + vec![] + }) .spawn() .unwrap() .wait() diff --git a/src/workspace/read.rs b/src/workspace/read.rs index 1c4e439..e3059e9 100755 --- a/src/workspace/read.rs +++ b/src/workspace/read.rs @@ -51,7 +51,23 @@ pub fn read_cfg(verbose: bool) -> Config { // Parses all necessary values for expanding the repo to a Repo struct let index = split_struct.indx; - let name = split_struct.name.replace('!', ""); + + let branch = if split_struct.name.contains('@') { + Some( + split_struct.name.split('@').collect::>()[1] + .to_string() + .replace('!', ""), + ) + } else { + None + }; + + let name = if split_struct.name.contains('@') { + split_struct.name.split('@').collect::>()[0].to_string() + } else { + split_struct.name.to_string().replace('!', "") + }; + let url = config.repositories.urls[index - 1].replace("%repo%", &name); let priority = &split_struct.name.matches('!').count(); @@ -59,6 +75,7 @@ pub fn read_cfg(verbose: bool) -> Config { let repo = Repo { name, url, + branch, priority: *priority, }; log!(verbose, "Expanded repo: {:?}", repo);