aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/error.rs9
-rw-r--r--src/project.rs3
-rw-r--r--src/project/error.rs15
-rw-r--r--src/project/git.rs15
4 files changed, 17 insertions, 25 deletions
diff --git a/src/error.rs b/src/error.rs
index d923642..c7b6448 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -6,7 +6,14 @@ pub enum Error {
Ignore(#[from] ignore::Error),
#[error(transparent)]
- Project(#[from] crate::project::Error),
+ IO(#[from] std::io::Error),
+
+ #[cfg(feature = "git")]
+ #[error(transparent)]
+ Git(#[from] git2::Error),
+
+ #[error(transparent)]
+ SystemTime(#[from] std::time::SystemTimeError),
#[error(transparent)]
Other(#[from] anyhow::Error),
diff --git a/src/project.rs b/src/project.rs
index 18c2083..b776cc2 100644
--- a/src/project.rs
+++ b/src/project.rs
@@ -1,8 +1,5 @@
use std::{path::PathBuf, time::Duration};
-pub use self::error::Error;
-
-mod error;
pub mod path;
#[cfg(feature = "git")]
diff --git a/src/project/error.rs b/src/project/error.rs
deleted file mode 100644
index 2e9f4a3..0000000
--- a/src/project/error.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-#[derive(thiserror::Error, Debug)]
-pub enum Error {
- #[error(transparent)]
- IO(#[from] std::io::Error),
-
- #[cfg(feature = "git")]
- #[error(transparent)]
- Git(#[from] git2::Error),
-
- #[error(transparent)]
- SystemTime(#[from] std::time::SystemTimeError),
-
- #[error(transparent)]
- Other(#[from] anyhow::Error),
-}
diff --git a/src/project/git.rs b/src/project/git.rs
index 759f632..6c8f329 100644
--- a/src/project/git.rs
+++ b/src/project/git.rs
@@ -5,7 +5,9 @@ use std::io;
use std::{path::PathBuf, time::Duration};
use tracing::{debug, warn};
-use super::{Error, Preview, ProjectParser, Timestamp};
+use crate::{Error, Result};
+
+use super::{Preview, ProjectParser, Timestamp};
#[derive(Debug, Clone)]
pub struct GitMatcher;
@@ -30,7 +32,7 @@ pub struct GitProject {
}
impl GitProject {
- fn new(path_buf: PathBuf) -> Result<Self, Error> {
+ fn new(path_buf: PathBuf) -> Result<Self> {
let repo = Repository::open(&path_buf)?;
let latest_commit = Self::get_timestamp(&repo);
Ok(Self {
@@ -49,7 +51,7 @@ impl GitProject {
}
}
- fn latest_commit(repository: &Repository) -> Result<u64, git2::Error> {
+ fn latest_commit(repository: &Repository) -> Result<u64> {
let mut branches = repository.branches(Some(BranchType::Local))?;
branches.try_fold(0, |latest, branch| {
let (branch, _) = branch?;
@@ -62,6 +64,7 @@ impl GitProject {
.revparse_single(name)?
.peel_to_commit()
.map(|c| (c.time().seconds() as u64).max(latest))
+ .map_err(Into::into)
})
}
}
@@ -76,7 +79,7 @@ impl Timestamp for GitProject {
impl Preview for GitProject {
type Error = Error;
- fn preview(&self) -> Result<(), Self::Error> {
+ fn preview(&self) -> Result<()> {
let config = onefetch::cli::Config {
input: self.path_buf.to_owned(),
include_hidden: true,
@@ -99,7 +102,7 @@ impl AsRef<PathBuf> for GitProject {
impl TryFrom<PathBuf> for GitProject {
type Error = Error;
- fn try_from(value: PathBuf) -> Result<Self, Self::Error> {
+ fn try_from(value: PathBuf) -> Result<Self> {
Self::new(value)
}
}
@@ -107,7 +110,7 @@ impl TryFrom<PathBuf> for GitProject {
impl TryFrom<DirEntry> for GitProject {
type Error = Error;
- fn try_from(value: DirEntry) -> Result<Self, Self::Error> {
+ fn try_from(value: DirEntry) -> Result<Self> {
Self::new(value.into_path())
}
}