1use std::fmt::{Display, Formatter};
7
8use thiserror::Error;
9
10#[derive(Copy, Clone, Debug, PartialEq, Eq)]
12#[non_exhaustive]
13pub enum RepositoryLoadKind {
14 Environment,
16 Path,
18}
19
20impl Display for RepositoryLoadKind {
21 #[inline]
22 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
23 match *self {
24 Self::Environment => write!(f, "environment"),
25 Self::Path => write!(f, "path"),
26 }
27 }
28}
29
30#[derive(Error, Debug, PartialEq)]
32#[non_exhaustive]
33pub enum GitError {
34 #[error("Could not open repository from {kind}")]
36 RepositoryLoad {
37 kind: RepositoryLoadKind,
39 #[source]
41 cause: git2::Error,
42 },
43 #[error("Could not load configuration")]
45 ConfigLoad {
46 #[source]
48 cause: git2::Error,
49 },
50 #[error("Could not load configuration")]
52 ReferenceNotFound {
53 #[source]
55 cause: git2::Error,
56 },
57 #[error("Could not load commit")]
59 CommitLoad {
60 #[source]
62 cause: git2::Error,
63 },
64}
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn repository_load_kind_display_environment() {
72 assert_eq!(format!("{}", RepositoryLoadKind::Environment), "environment");
73 }
74
75 #[test]
76 fn repository_load_kind_display_path() {
77 assert_eq!(format!("{}", RepositoryLoadKind::Path), "path");
78 }
79}