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
use std::fmt;
use std::path::PathBuf;
use git2;
#[derive(Clone, Eq, Hash, PartialEq)]
pub struct Repo {
path: PathBuf,
}
impl Repo {
pub fn new(path: String) -> Repo {
Repo {
path: PathBuf::from(path),
}
}
pub fn as_git2_repo(&self) -> Option<git2::Repository> {
git2::Repository::open(&self.path).ok()
}
pub fn path(&self) -> String {
self.path.to_str().unwrap().to_string()
}
}
impl fmt::Display for Repo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.path())
}
}