Compare commits

..

3 Commits

Author SHA1 Message Date
60ffc3b806 feat: add check git status 2020-12-27 22:17:24 +08:00
586e6a8e4b chore: add justfile 2020-12-27 22:17:16 +08:00
c838ad326b feat: add cmd gitchecl 2020-12-27 22:08:10 +08:00
2 changed files with 24 additions and 4 deletions

5
justfile Normal file
View File

@@ -0,0 +1,5 @@
_:
@just --list
install:
cargo install --path .

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,26 @@ 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 {
failure!("Git repo has not fetched codes");
return Ok(-2); // fetch check failed
}
let git_status = util_git::git_status(dir)?;
let git_status_local_unpush_messages = vec![
"Changes not staged for commit",
"Changes to be committed",
"Your branch is ahead of"
];
if git_status_local_unpush_messages.iter().find(|m| git_status.contains(**m)).is_some() {
failure!("Git repo has un-push changes");
return Ok(-3);
}
Ok(0)
}
}