diff options
Diffstat (limited to 'src/project')
-rw-r--r-- | src/project/git.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/project/git.rs b/src/project/git.rs index 00cd000..17573c3 100644 --- a/src/project/git.rs +++ b/src/project/git.rs @@ -14,15 +14,14 @@ pub struct GitProject { impl GitProject { fn new(path_buf: PathBuf) -> Result<Self, Error> { - let latest_commit = Self::latest_commit(&path_buf).ok(); + let repo = Repository::open(&path_buf)?; Ok(Self { path_buf, - latest_commit, + latest_commit: Self::latest_commit(&repo).ok(), }) } - fn latest_commit(path_buf: &PathBuf) -> Result<Duration, Error> { - let repository = Repository::open(path_buf)?; + fn latest_commit(repository: &Repository) -> Result<Duration, Error> { let mut branches = repository.branches(Some(BranchType::Local))?; branches .try_fold(0, |latest, branch| { @@ -46,10 +45,9 @@ impl Timestamp for GitProject { type Error = Error; fn timestamp(&self) -> Result<Duration, Self::Error> { - match self.latest_commit { - Some(t) => Ok(t), - None => Self::latest_commit(&self.path_buf), - } + self.latest_commit.ok_or(Error::Git(git2::Error::from_str( + "Failed to get latest commit", + ))) } } |