aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-11-27 23:10:11 -0600
committerToby Vincent <tobyv13@gmail.com>2022-11-27 23:10:11 -0600
commit3f188dea518fe29324f7a2416316c436cea8e88a (patch)
treecb98ab6f517f65510b6aa0988ec88c6f976d01ae
parentdfd99151bcc364b2ea947f1d4ae8a5523b92d40a (diff)
fix: fix bug in project matching for git repositoriesv0.1.0
-rw-r--r--src/project/git.rs14
-rw-r--r--src/search/entry.rs1
2 files changed, 6 insertions, 9 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",
+ )))
}
}
diff --git a/src/search/entry.rs b/src/search/entry.rs
index 1d885c8..778c75c 100644
--- a/src/search/entry.rs
+++ b/src/search/entry.rs
@@ -41,7 +41,6 @@ impl Entry {
impl Iterator for Entry {
type Item = ProjectItem;
- #[tracing::instrument]
fn next(&mut self) -> Option<Self::Item> {
match self.iter.next()? {
Ok(dir_entry) => self.parse_dir_entry(dir_entry),