standard_error/extras/fromerrs/
git.rs

1#[cfg(feature = "git")]
2use crate::{Interpolate, StandardError};
3
4#[cfg(feature = "git")]
5impl From<git2::Error> for StandardError {
6    fn from(error: git2::Error) -> Self {
7        let code = match error.code() {
8            git2::ErrorCode::GenericError => "ERR-GIT-GENERIC",
9            git2::ErrorCode::NotFound => "ERR-GIT-NOTFOUND",
10            git2::ErrorCode::Exists => "ERR-GIT-EXISTS",
11            git2::ErrorCode::Ambiguous => "ERR-GIT-AMBIGUOUS",
12            git2::ErrorCode::BufSize => "ERR-GIT-BUFSIZE",
13            git2::ErrorCode::User => "ERR-GIT-USER",
14            git2::ErrorCode::BareRepo => "ERR-GIT-BARE-REPO",
15            git2::ErrorCode::UnbornBranch => "ERR-GIT-UNBORN-BRANCH",
16            git2::ErrorCode::Unmerged => "ERR-GIT-UNMERGED",
17            git2::ErrorCode::NotFastForward => "ERR-GIT-NOT-FAST-FORWARD",
18            git2::ErrorCode::InvalidSpec => "ERR-GIT-INVALID-SPEC",
19            git2::ErrorCode::Conflict => "ERR-GIT-CONFLICT",
20            git2::ErrorCode::Locked => "ERR-GIT-LOCKED",
21            git2::ErrorCode::Modified => "ERR-GIT-MODIFIED",
22            git2::ErrorCode::Auth => "ERR-GIT-AUTH",
23            git2::ErrorCode::Certificate => "ERR-GIT-CERTIFICATE",
24            git2::ErrorCode::Applied => "ERR-GIT-APPLIED",
25            git2::ErrorCode::Peel => "ERR-GIT-PEEL",
26            git2::ErrorCode::Eof => "ERR-GIT-EOF",
27            git2::ErrorCode::Invalid => "ERR-GIT-INVALID",
28            git2::ErrorCode::Uncommitted => "ERR-GIT-UNCOMMITTED",
29            git2::ErrorCode::Directory => "ERR-GIT-DIRECTORY",
30            git2::ErrorCode::MergeConflict => "ERR-GIT-MERGE-CONFLICT",
31            git2::ErrorCode::HashsumMismatch => "ERR-GIT-HASHSUM-MISMATCH",
32            git2::ErrorCode::IndexDirty => "ERR-GIT-INDEX-DIRTY",
33            git2::ErrorCode::ApplyFail => "ERR-GIT-APPLY-FAIL",
34            git2::ErrorCode::Owner => "ERR-GIT-OWNER",
35        };
36
37        StandardError::new(code).interpolate_err(error.to_string())
38    }
39}