Skip to content

Commit

Permalink
Add rule
Browse files Browse the repository at this point in the history
  • Loading branch information
luizvbo committed Apr 29, 2024
1 parent 55a807e commit cb88258
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/rules/git_stash_pop.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
use crate::{
cli::command::CrabCommand,
rules::{match_rule_with_git_support, utils::git::get_new_command_with_git_support},
Rule,
rules::{
utils::git::{get_new_command_with_git_support, match_rule_with_git_support},
Rule,
},
shell::Shell,
};
use shell::Shell;

fn auxiliary_match_rule(command: &CrabCommand) -> bool {
command.script.contains("stash")
&& command.script.contains("pop")
&& command.output.as_ref().map_or(false, |o| {
o.contains("Your local changes to the following files would be overwritten by merge")
})
if let Some(stdout) = &command.output {
command.script.contains("stash")
&& command.script.contains("pop")
&& stdout
.contains("Your local changes to the following files would be overwritten by merge")
} else {
false
}
}

pub fn match_rule(command: &mut CrabCommand, _system_shell: Option<&dyn Shell>) -> bool {
pub fn match_rule(command: &mut CrabCommand, system_shell: Option<&dyn Shell>) -> bool {
match_rule_with_git_support(auxiliary_match_rule, command)
}

fn auxiliary_get_new_command(
command: &CrabCommand,
_system_shell: Option<&dyn Shell>,
system_shell: Option<&dyn Shell>,
) -> Vec<String> {
vec!["git add --update && git stash pop && git reset .".to_string()]
vec![system_shell.unwrap().and(vec!["git add --update", "git stash pop", "git reset ."])]
}

pub fn get_new_command(
command: &mut CrabCommand,
_system_shell: Option<&dyn Shell>,
system_shell: Option<&dyn Shell>,
) -> Vec<String> {
get_new_command_with_git_support(auxiliary_get_new_command, command, _system_shell)
get_new_command_with_git_support(auxiliary_get_new_command, command, system_shell)
}

pub fn get_rule() -> Rule {
Rule::new(
"git_stash_pop".to_owned(),
Some(900), // priority
None,
Some(900), // priority
None,
match_rule,
get_new_command,
Expand Down

0 comments on commit cb88258

Please sign in to comment.