pre_commit_sort/
remote.rs

1/// ref. <https://pre-commit.com/#pre-commit-configyaml---repos>
2use crate::ConfigHook;
3
4#[serde_with::skip_serializing_none]
5#[derive(serde::Serialize, serde::Deserialize, Debug, Eq, Ord, PartialEq, PartialOrd, Clone)]
6pub struct Remote {
7    repo: String,
8    rev: String,
9    hooks: Vec<ConfigHook>,
10}
11
12impl Remote {
13    #[must_use]
14    pub const fn new(repo: String, rev: String) -> Self {
15        Self {
16            repo,
17            rev,
18            hooks: Vec::new(),
19        }
20    }
21
22    pub fn add_hook(&mut self, hook: ConfigHook) {
23        self.hooks.push(hook);
24    }
25
26    pub fn sort(&mut self) {
27        self.hooks.sort();
28        self.hooks.dedup();
29    }
30
31    #[must_use]
32    pub fn equal_but_rev(&self, other: &Self) -> bool {
33        self.repo == other.repo && self.hooks == other.hooks
34    }
35}