git-next/crates/config/src/git_dir.rs
Paul Campbell 341dc97a51
All checks were successful
Rust / build (push) Successful in 1m7s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
refactor(git): add mock repository and tests
Repository is now behind an enum to allow selection of a mock Repsitory
for use in tests.
2024-05-21 19:47:01 +01:00

43 lines
843 B
Rust

use std::path::PathBuf;
#[derive(
Clone,
Default,
Debug,
Hash,
PartialEq,
Eq,
serde::Deserialize,
derive_more::Deref,
derive_more::From,
)]
pub struct GitDir(PathBuf);
impl GitDir {
pub fn new(pathbuf: &std::path::Path) -> Self {
Self(pathbuf.to_path_buf())
}
pub const fn pathbuf(&self) -> &PathBuf {
&self.0
}
}
impl std::fmt::Display for GitDir {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", &self.0.display())
}
}
impl From<&str> for GitDir {
fn from(value: &str) -> Self {
Self(value.into())
}
}
impl From<&GitDir> for PathBuf {
fn from(value: &GitDir) -> Self {
value.to_path_buf()
}
}
impl From<GitDir> for PathBuf {
fn from(value: GitDir) -> Self {
value.0
}
}