Run git reset before pulling changes to cached aur packages

Fixes #101
main
trivernis 1 year ago
parent d2008a5a89
commit 182daa2493
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -67,3 +67,33 @@ impl GitPullBuilder {
}
}
}
#[derive(Debug, Default)]
pub struct GitResetBuilder {
directory: PathBuf,
}
impl GitResetBuilder {
pub fn directory<P: AsRef<Path>>(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))
}
}
}

@ -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<BuildContex
pkg_name.clone().bold(),
fl!("pulling-latest-changes")
));
GitResetBuilder::default()
.directory(&pkg_dir)
.reset()
.await?;
GitPullBuilder::default().directory(&pkg_dir).pull().await?;
} else {
let aur_url = crate::internal::rpc::URL;

Loading…
Cancel
Save