git_next_core/config/
git_dir.rs

1//
2use std::path::PathBuf;
3
4use derive_more::Deref;
5use pike::pike;
6
7/// The path to the directory containing the git repository.
8#[derive(
9    Clone,
10    Debug,
11    derive_more::From,
12    PartialEq,
13    Eq,
14    PartialOrd,
15    Ord,
16    derive_more::AsRef,
17    derive_more::Constructor,
18)]
19pub struct GitDir {
20    pathbuf: PathBuf,
21    /// Whether the directory is under the control of git-next (Internal) or not (External).
22    storage_path_type: StoragePathType,
23}
24impl GitDir {
25    pub(crate) const fn pathbuf(&self) -> &PathBuf {
26        &self.pathbuf
27    }
28
29    pub(crate) const fn storage_path_type(&self) -> StoragePathType {
30        self.storage_path_type
31    }
32
33    pub(crate) fn as_fs(&self) -> kxio::fs::FileSystem {
34        pike! {
35            self
36            |> Self::pathbuf
37            |> PathBuf::clone
38            |> kxio::fs::new
39        }
40    }
41}
42impl std::fmt::Display for GitDir {
43    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44        write!(f, "{}", &self.pathbuf.display())
45    }
46}
47impl Deref for GitDir {
48    type Target = PathBuf;
49
50    fn deref(&self) -> &Self::Target {
51        &self.pathbuf
52    }
53}
54impl From<&GitDir> for PathBuf {
55    fn from(value: &GitDir) -> Self {
56        value.to_path_buf()
57    }
58}
59impl From<&GitDir> for kxio::fs::FileSystem {
60    fn from(gitdir: &GitDir) -> Self {
61        gitdir.as_fs()
62    }
63}
64
65#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
66pub enum StoragePathType {
67    Internal,
68    External,
69}