#[cfg(test)]
mod tests;
use std::path::Path;
use serde::Deserialize;
use crate::config::ConfigError;
use crate::verdict::Verdict;
pub const DEFAULT: &str = include_str!("../assets/policy/git.toml");
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct GitPolicy {
pub git_available: Rule,
pub in_work_tree: Rule,
pub head_exists: Rule,
pub head_detached: Rule,
pub index_has_staged: Rule,
pub index_conflicted: Rule,
pub work_tree_clean: Rule,
pub merge_in_progress: Rule,
pub cherry_pick_in_progress: Rule,
pub revert_in_progress: Rule,
pub bisect_in_progress: Rule,
pub am_in_progress: Rule,
pub rebase_in_progress: Rule,
}
impl GitPolicy {
pub fn parse(text: &str, path: &Path) -> Result<GitPolicy, ConfigError> {
toml::from_str(text).map_err(|source| ConfigError::new(path, source))
}
}
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Rule {
pub value: bool,
pub prompt: String,
pub action: Action,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Action {
Proceed,
Adjust,
Stop,
}
impl Action {
#[must_use]
pub fn verdict(self, prompt: String) -> Verdict {
match self {
Action::Proceed => Verdict::Proceed(prompt),
Action::Adjust => Verdict::Adjust(prompt),
Action::Stop => Verdict::Stop(prompt),
}
}
}