From 3f188dea518fe29324f7a2416316c436cea8e88a Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Sun, 27 Nov 2022 23:10:11 -0600 Subject: fix: fix bug in project matching for git repositories --- src/project/git.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/project') 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 { - 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 { - let repository = Repository::open(path_buf)?; + fn latest_commit(repository: &Repository) -> Result { 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 { - 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", + ))) } } -- cgit v1.2.3-70-g09d2