You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
use std::error::Error;
|
|
use std::fmt;
|
|
use std::io;
|
|
|
|
use command_runner::CommandRunner;
|
|
use symbols::Symbol;
|
|
|
|
pub struct GitSubmodules<'a> {
|
|
target: &'a str,
|
|
command_runner: &'a CommandRunner
|
|
}
|
|
|
|
impl<'a> GitSubmodules<'a> {
|
|
pub fn new(target: &'a str, command_runner: &'a CommandRunner) -> GitSubmodules<'a> {
|
|
GitSubmodules {
|
|
target: target,
|
|
command_runner: command_runner
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<'a> fmt::Display for GitSubmodules<'a> {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(f, "Submodules for {}", self.target)
|
|
}
|
|
}
|
|
|
|
impl<'a> GitSubmodules<'a> {
|
|
fn _run_in_target_repo(&self, args: &[&str]) -> Result<Vec<u8>, io::Error> {
|
|
let mut new_args = vec!["-C", self.target];
|
|
new_args.extend_from_slice(args);
|
|
self.command_runner.run_with_args("git", &new_args).map(|res| res.stdout)
|
|
}
|
|
}
|
|
|
|
impl<'a> Symbol for GitSubmodules<'a> {
|
|
fn target_reached(&self) -> Result<bool, Box<Error>> {
|
|
let output = try!(self._run_in_target_repo(&["submodule", "status"]));
|
|
Ok(String::from_utf8(output).unwrap().lines().all(|line| line.len() == 0 || line.starts_with(' ')))
|
|
}
|
|
|
|
fn execute(&self) -> Result<(), Box<Error>> {
|
|
try!(self._run_in_target_repo(&["submodule", "update", "--init"]));
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
}
|