From 182daa24936d72e01e30172ff8aa47342022f425 Mon Sep 17 00:00:00 2001 From: trivernis Date: Tue, 3 Jan 2023 19:32:59 +0100 Subject: [PATCH] Run git reset before pulling changes to cached aur packages Fixes #101 --- src/builder/git.rs | 30 ++++++++++++++++++++++++++++ src/operations/aur_install/common.rs | 9 ++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/builder/git.rs b/src/builder/git.rs index 1f1416e..61317fe 100644 --- a/src/builder/git.rs +++ b/src/builder/git.rs @@ -67,3 +67,33 @@ impl GitPullBuilder { } } } + +#[derive(Debug, Default)] +pub struct GitResetBuilder { + directory: PathBuf, +} + +impl GitResetBuilder { + pub fn directory>(mut self, path: P) -> Self { + self.directory = path.as_ref().into(); + + self + } + + pub async fn reset(self) -> AppResult<()> { + let result = ShellCommand::git() + .arg("-C") + .arg(self.directory) + .arg("reset") + .arg("HEAD") + .arg("--hard") + .wait_with_output() + .await?; + + if result.status.success() { + Ok(()) + } else { + Err(AppError::Other(result.stderr)) + } + } +} diff --git a/src/operations/aur_install/common.rs b/src/operations/aur_install/common.rs index 47b9306..23b4fc7 100644 --- a/src/operations/aur_install/common.rs +++ b/src/operations/aur_install/common.rs @@ -15,7 +15,10 @@ use tokio::{ task, }; -use crate::error::{AppError, AppResult}; +use crate::{ + builder::git::GitResetBuilder, + error::{AppError, AppResult}, +}; use crate::{ builder::{ git::{GitCloneBuilder, GitPullBuilder}, @@ -56,6 +59,10 @@ pub async fn download_aur_source(mut ctx: BuildContext) -> AppResult