git_prole/
app_git.rs

1use std::fmt::Debug;
2use std::ops::Deref;
3use std::ops::DerefMut;
4
5use camino::Utf8Path;
6
7use crate::config::Config;
8use crate::git::Git;
9use crate::git::GitLike;
10
11/// A [`Git`] with borrowed [`Config`].
12#[derive(Clone)]
13pub struct AppGit<'a, C> {
14    pub git: Git<C>,
15    pub config: &'a Config,
16}
17
18impl<C> Debug for AppGit<'_, C>
19where
20    C: AsRef<Utf8Path>,
21{
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        f.debug_tuple("AppGit")
24            .field(&self.git.get_current_dir().as_ref())
25            .finish()
26    }
27}
28
29impl<C> Deref for AppGit<'_, C> {
30    type Target = Git<C>;
31
32    fn deref(&self) -> &Self::Target {
33        &self.git
34    }
35}
36
37impl<C> DerefMut for AppGit<'_, C> {
38    fn deref_mut(&mut self) -> &mut Self::Target {
39        &mut self.git
40    }
41}
42
43impl<C> AsRef<Git<C>> for AppGit<'_, C> {
44    fn as_ref(&self) -> &Git<C> {
45        &self.git
46    }
47}
48
49impl<C> AsRef<Config> for AppGit<'_, C> {
50    fn as_ref(&self) -> &Config {
51        self.config
52    }
53}
54
55impl<C> AsRef<Utf8Path> for AppGit<'_, C>
56where
57    C: AsRef<Utf8Path>,
58{
59    fn as_ref(&self) -> &Utf8Path {
60        self.git.as_ref()
61    }
62}
63
64impl<C> GitLike for AppGit<'_, C>
65where
66    C: AsRef<Utf8Path>,
67{
68    type CurrentDir = C;
69
70    fn as_git(&self) -> &Git<Self::CurrentDir> {
71        &self.git
72    }
73}
74
75impl<'a, C> AppGit<'a, C>
76where
77    C: AsRef<Utf8Path>,
78{
79    pub fn with_current_dir<C2>(&self, path: C2) -> AppGit<'a, C2> {
80        AppGit {
81            git: self.git.with_current_dir(path),
82            config: self.config,
83        }
84    }
85}