use camino::Utf8PathBuf;
use thiserror::Error;
#[derive(Clone, Debug, Error, PartialEq)]
#[non_exhaustive]
pub enum CommitHashParseError {
#[error(
"invalid length: expected 40 (SHA-1) or 64 (SHA-256) hex characters, \
got {0}"
)]
InvalidLength(usize),
#[error("invalid hexadecimal")]
InvalidHex(hex::FromHexError),
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum GitStubParseError {
#[error("git stub is empty")]
EmptyInput,
#[error(
"invalid git stub format: expected 'commit:path', got {0:?} \
(missing ':' separator)"
)]
InvalidFormat(String),
#[error("invalid commit hash in git stub")]
InvalidCommitHash(#[from] CommitHashParseError),
#[error("git stub has empty path (nothing after ':')")]
EmptyPath,
#[error(
"git stub path {path:?} contains non-normal component {component:?} \
(only plain file/directory names are allowed)"
)]
InvalidPathComponent {
path: Utf8PathBuf,
component: String,
},
#[error("git stub path contains a newline character")]
NewlineInPath,
}