From 9edd0af9798215e4459e63862e777218cda72681 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 7 Jan 2023 10:19:17 +0200 Subject: refactor: move GitInvoke, GitError into src/git.rs Sponsored-by: author --- src/error.rs | 6 ------ src/git.rs | 12 +++++++++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/error.rs b/src/error.rs index 50c1ba3..2f3bc91 100644 --- a/src/error.rs +++ b/src/error.rs @@ -45,12 +45,6 @@ pub enum SiteError { #[error("link to missing page {1} on {0}")] PageMissing(PathBuf, PathBuf), - #[error("faileed to invoked git with subcommand {0} in {1}")] - GitInvoke(String, PathBuf, #[source] std::io::Error), - - #[error("git {0} in in {1}:\n{2}")] - GitError(String, PathBuf, String), - #[error("failed to parse date: {0:?}")] UnknownTimestamp(String), diff --git a/src/git.rs b/src/git.rs index c824bfa..c64453a 100644 --- a/src/git.rs +++ b/src/git.rs @@ -9,20 +9,26 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; pub enum GitError { #[error("failed to parse Unix timetamp: {0}")] ParseUnixTimestamp(String, #[source] std::num::ParseIntError), + + #[error("faileed to invoked git with subcommand {0} in {1}")] + GitInvoke(String, PathBuf, #[source] std::io::Error), + + #[error("git {0} in in {1}:\n{2}")] + GitError(String, PathBuf, String), } -pub fn git(args: &[&str], cwd: &Path) -> Result { +pub fn git(args: &[&str], cwd: &Path) -> Result { assert!(!args.is_empty()); let output = Command::new("git") .args(args) .current_dir(cwd) .output() - .map_err(|e| SiteError::GitInvoke(args[0].into(), cwd.into(), e))?; + .map_err(|e| GitError::GitInvoke(args[0].into(), cwd.into(), e))?; if output.status.success() { Ok(String::from_utf8_lossy(&output.stdout).into()) } else { let stderr = String::from_utf8_lossy(&output.stderr).into(); - Err(SiteError::GitError(args[0].into(), cwd.into(), stderr)) + Err(GitError::GitError(args[0].into(), cwd.into(), stderr)) } } -- cgit v1.2.1