1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// License: see LICENSE file at root directory of main branch

//! # Work Tree

use std::{
    io::{Error, ErrorKind},
    path::{Path, PathBuf},
};

use crate::Result;

/// # List command
pub (crate) const CMD_LIST: &str = "list";

/// # Option: --porcelain
pub (crate) const OPTION_PORCELAIN: &str = "--porcelain";

/// # Option: -z
pub (crate) const OPTION_Z: &str = "-z";

/// # Work Tree
///
/// Currently, this struct only provides a path.
#[derive(Debug, Eq, PartialEq, Hash)]
pub struct WorkTree {

    path: PathBuf,

}

impl WorkTree {

    /// # Makes new instance
    ///
    /// An error is returned if given path is not correct.
    pub (crate) fn make<P>(path: P) -> Result<Self> where P: AsRef<Path> {
        let path = path.as_ref().to_path_buf().canonicalize()?;
        if path.is_dir() {
            Ok(Self {
                path,
            })
        } else {
            Err(Error::new(ErrorKind::InvalidInput, __!("Not a directory: {:?}", path)))
        }
    }

    /// # Path of this work tree
    pub fn path(&self) -> &Path {
        &self.path
    }

}