feat: add cmd gitchecl

This commit is contained in:
2020-12-27 22:08:10 +08:00
parent 86dcbef727
commit c838ad326b

View File

@@ -1,4 +1,4 @@
use clap::{ArgMatches, SubCommand, App/*, Arg */};
use clap::{ArgMatches, SubCommand, App, Arg};
use rust_util::util_git;
use crate::cmd::{Command, CommandResult};
@@ -10,11 +10,18 @@ impl Command for CommandImpl {
fn subcommand<'a>(&self) -> App<'a, 'a> {
SubCommand::with_name(self.name()).about("Git check subcommand")
// .arg(Arg::with_name("add").short("A").long("add").multiple(true).takes_value(true).help("Add crates to project"))
.arg(Arg::with_name("dir").long("dir").required(false).takes_value(true).help("Git check dir"))
}
fn run(&self, _arg_matches: &ArgMatches, _sub_arg_matches: &ArgMatches) -> CommandResult {
// util_git::git_fetch_dry_run("working_dir");
fn run(&self, _arg_matches: &ArgMatches, sub_arg_matches: &ArgMatches) -> CommandResult {
let dir = sub_arg_matches.value_of("dir");
let has_remote_cannotbe_fetched = util_git::git_fetch_dry_run(dir)?;
if !has_remote_cannotbe_fetched {
warning!("Git repo has not fetched codes");
return Ok(-2); // fetch check failed
}
let git_status = util_git::git_status(dir)?;
if git_status.contains("Changes not staged for commit") || git_status.contains("Changes to be committed")
Ok(0)
}
}