git_shell/git/
work_tree.rs

1// License: see LICENSE file at root directory of main branch
2
3//! # Work Tree
4
5use std::{
6    io::{Error, ErrorKind},
7    path::{Path, PathBuf},
8};
9
10use crate::Result;
11
12/// # List command
13pub (crate) const CMD_LIST: &str = "list";
14
15/// # Option: --porcelain
16pub (crate) const OPTION_PORCELAIN: &str = "--porcelain";
17
18/// # Option: -z
19pub (crate) const OPTION_Z: &str = "-z";
20
21/// # Work Tree
22///
23/// Currently, this struct only provides a path.
24#[derive(Debug, Eq, PartialEq, Hash)]
25pub struct WorkTree {
26
27    path: PathBuf,
28
29}
30
31impl WorkTree {
32
33    /// # Makes new instance
34    ///
35    /// An error is returned if given path is not correct.
36    pub (crate) fn make<P>(path: P) -> Result<Self> where P: AsRef<Path> {
37        let path = path.as_ref().to_path_buf().canonicalize()?;
38        if path.is_dir() {
39            Ok(Self {
40                path,
41            })
42        } else {
43            Err(Error::new(ErrorKind::InvalidInput, __!("Not a directory: {:?}", path)))
44        }
45    }
46
47    /// # Path of this work tree
48    pub fn path(&self) -> &Path {
49        &self.path
50    }
51
52}