Compare commits
3 Commits
86dcbef727
...
60ffc3b806
| Author | SHA1 | Date | |
|---|---|---|---|
| 60ffc3b806 | |||
| 586e6a8e4b | |||
| c838ad326b |
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user