1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
pub mod vcs {
use std::{fs::remove_dir_all, process::Command};
pub struct Git {
repository: String,
url: String,
}
impl Git {
///
/// Git constructor
///
/// - `repo` The repository install path
/// - `uri` The repository remote url
///
/// ```
/// use installation_testing::git::vcs::Git;
/// use std::process::Command;
///
/// let mut cargo = Command::new("cargo");
///
/// let test = cargo.arg("build");
/// let mut checker = Git::new("https://github.com/taishingi/zuu","/tmp/zuu");
///
/// checker.run(test).clean();
/// ```
///
pub fn new(uri: &str, repo: &str) -> Git {
Self {
repository: repo.to_string(),
url: uri.to_string(),
}
.get()
}
///
/// # Get the remote repository
///
fn get(self) -> Git {
assert!(Command::new("git")
.arg("clone")
.arg(self.url.as_str())
.arg(self.repository.as_str())
.spawn()
.expect("Failed to clone repository")
.wait()
.expect("msg")
.success());
self
}
pub fn run(&mut self, command: &mut Command) -> &mut Git {
command
.current_dir(self.repository.as_str())
.spawn()
.expect("failed")
.wait()
.expect("");
self
}
///
/// # remove the local repository
///
pub fn clean(&mut self) -> bool {
remove_dir_all(self.repository.as_str()).expect("Failed to remove the directory");
true
}
}
}
#[cfg(test)]
mod test {
use crate::git::vcs::Git;
#[test]
pub fn all() {
assert!(Git::new("https://github.com/taishingi/zuu", "/tmp/zuu").clean());
}
}