mit_commit_message_lints/external/
vcs.rs1use std::convert::Infallible;
2
3use miette::{Diagnostic, Result};
4use thiserror::Error;
5
6pub trait Vcs {
8 fn entries(&self, glob: Option<&str>) -> Result<Vec<String>>;
12 fn get_bool(&self, name: &str) -> Result<Option<bool>>;
16 fn get_str(&self, name: &str) -> Result<Option<&str>>;
20 fn get_i64(&self, name: &str) -> Result<Option<i64>>;
24 fn set_str(&mut self, name: &str, value: &str) -> Result<()>;
28 fn set_i64(&mut self, name: &str, value: i64) -> Result<()>;
32 fn remove(&mut self, name: &str) -> Result<()>;
36
37 fn state(&self) -> Option<RepoState>;
41}
42
43#[derive(Debug, Copy, Clone)]
45pub enum RepoState {
46 Clean,
48 Merge,
50 Revert,
52 RevertSequence,
54 CherryPick,
56 CherryPickSequence,
58 Bisect,
60 Rebase,
62 RebaseInteractive,
64 RebaseMerge,
66 ApplyMailbox,
68 ApplyMailboxOrRebase,
70}
71
72#[derive(Error, Debug, Diagnostic)]
74pub enum Error {
75 #[error("failed to interact with git repository: {0}")]
77 #[diagnostic(
78 url(docsrs),
79 code(mit_commit_message_lints::external::vcs::error::git2_io)
80 )]
81 Git2Io(git2::Error),
82 #[error("failed to read int from in memory datastore: {0}")]
84 #[diagnostic(
85 url(docsrs),
86 code(mit_commit_message_lints::external::vcs::error::in_memory_parse_int)
87 )]
88 InMemoryParseInt(std::num::ParseIntError),
89 #[error("failed to read bool from in memory datastore: {0}")]
91 #[diagnostic(
92 url(docsrs),
93 code(mit_commit_message_lints::external::vcs::error::in_memory_parse_bool)
94 )]
95 InMemoryParseBool(std::str::ParseBoolError),
96 #[error("failed to read git-mit config")]
98 #[diagnostic(url(docsrs), code(mit_commit_message_lints::external::vcs::error::io))]
99 Io(std::io::Error),
100 #[error("failed to parse glob {0}")]
102 #[diagnostic(
103 url(docsrs),
104 code(mit_commit_message_lints::external::vcs::error::glob)
105 )]
106 Glob(glob::PatternError),
107 #[error(transparent)]
109 #[diagnostic(
110 url(docsrs),
111 code(mit_commit_message_lints::external::vcs::error::infallible)
112 )]
113 Infallible(Infallible),
114}