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
use std::{
io::{Error, ErrorKind},
path::{Path, PathBuf},
};
use crate::Result;
pub (crate) const CMD_LIST: &str = "list";
pub (crate) const OPTION_PORCELAIN: &str = "--porcelain";
pub (crate) const OPTION_Z: &str = "-z";
#[derive(Debug, Eq, PartialEq, Hash)]
pub struct WorkTree {
path: PathBuf,
}
impl WorkTree {
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)))
}
}
pub fn path(&self) -> &Path {
&self.path
}
}