From c838ad326b053236ea504c3ae235dd76b48d5134 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 27 Dec 2020 22:08:10 +0800 Subject: [PATCH] feat: add cmd gitchecl --- src/cmd_gitcheck.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cmd_gitcheck.rs b/src/cmd_gitcheck.rs index 561fa4e..b6ddbc0 100644 --- a/src/cmd_gitcheck.rs +++ b/src/cmd_gitcheck.rs @@ -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) } }