59 lines
1.5 KiB
Rust
59 lines
1.5 KiB
Rust
use std::process::Command;
|
|
|
|
pub fn from_setting(setting: Option<String>) -> Backend {
|
|
// Git is the default setting until further notice
|
|
setting.map_or(Backend::Git, |name| match name.as_ref() {
|
|
"git" => Backend::Git,
|
|
"mercurial" => Backend::Mercurial,
|
|
_ => Backend::Unknown(name.to_string())
|
|
})
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum Backend {
|
|
Git,
|
|
Mercurial,
|
|
Unknown(String),
|
|
}
|
|
|
|
impl Backend {
|
|
pub fn clone(&self, source: &str, dest: &str) -> bool {
|
|
match self {
|
|
Backend::Git => {
|
|
let status = Command::new("git")
|
|
.arg("clone")
|
|
.arg("--recursive")
|
|
.arg(source)
|
|
.arg(dest)
|
|
.status().expect("PROCESS ERROR!");
|
|
status.success()
|
|
},
|
|
Backend::Mercurial => {
|
|
unreachable!("Unimplemented");
|
|
},
|
|
Backend::Unknown(name) => {
|
|
eprintln!("Unknown DVCS: {}", name);
|
|
false
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
/// Runs an update on the repository in dest. Returns true
|
|
/// when an update was performed, false otherwise
|
|
pub fn update(&self, dest: &str) -> bool {
|
|
match self {
|
|
Backend::Git => {
|
|
|
|
},
|
|
Backend::Mercurial => {
|
|
|
|
},
|
|
Backend::Unknown(name) => {
|
|
eprintln!("Unknown DVCS: {}", name);
|
|
false
|
|
}
|
|
}
|
|
}*/
|
|
}
|