Skip to main content

aqc_git_helpers/
error.rs

1//! The git query error contract.
2
3/// Why a git query failed.
4#[derive(Debug)]
5pub enum GitError {
6    /// The directory is not inside a Git worktree.
7    NotARepository,
8    /// The `git` executable is missing.
9    GitNotInstalled,
10    /// `git` exited nonzero.
11    CommandFailed {
12        /// The command that failed.
13        command: String,
14        /// Its stderr.
15        stderr: String,
16    },
17    /// Unparseable porcelain output.
18    ParseError {
19        /// What could not be parsed.
20        message: String,
21    },
22}
23
24impl core::fmt::Display for GitError {
25    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
26        match self {
27            Self::NotARepository => write!(f, "not a git repository"),
28            Self::GitNotInstalled => write!(f, "git executable not found"),
29            Self::CommandFailed { command, stderr } => {
30                write!(f, "`{command}` failed: {stderr}")
31            }
32            Self::ParseError { message } => write!(f, "porcelain parse error: {message}"),
33        }
34    }
35}
36
37impl core::error::Error for GitError {}