git/errors/
mod.rs

1//! Git Interactive Rebase Tool - Git crate errors
2//!
3//! # Description
4//! This module contains error types used in the Git crate.
5
6use std::fmt::{Display, Formatter};
7
8use thiserror::Error;
9
10/// The kind of repository load kind.
11#[derive(Copy, Clone, Debug, PartialEq, Eq)]
12#[non_exhaustive]
13pub enum RepositoryLoadKind {
14	/// Repository was loaded from the path provided through an environment variable
15	Environment,
16	/// Repository was loaded from a direct path
17	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/// Git errors
31#[derive(Error, Debug, PartialEq)]
32#[non_exhaustive]
33pub enum GitError {
34	/// The repository could not be loaded
35	#[error("Could not open repository from {kind}")]
36	RepositoryLoad {
37		/// The kind of load error.
38		kind: RepositoryLoadKind,
39		/// The internal cause of the load error.
40		#[source]
41		cause: git2::Error,
42	},
43	/// The configuration could not be loaded
44	#[error("Could not load configuration")]
45	ConfigLoad {
46		/// The internal cause of the load error.
47		#[source]
48		cause: git2::Error,
49	},
50	/// The configuration could not be loaded
51	#[error("Could not load configuration")]
52	ReferenceNotFound {
53		/// The internal cause of the load error.
54		#[source]
55		cause: git2::Error,
56	},
57	/// The commit could not be loaded
58	#[error("Could not load commit")]
59	CommitLoad {
60		/// The internal cause of the load error.
61		#[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}