From c9311e898b2b69d498702feefcad2b3f162828ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Wed, 3 Apr 2024 12:43:25 +0300 Subject: [PATCH] feat: improve git-lfs handling --- src/source/git_source.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/source/git_source.rs b/src/source/git_source.rs index 74ee4185..b57308e5 100644 --- a/src/source/git_source.rs +++ b/src/source/git_source.rs @@ -199,7 +199,7 @@ pub fn git_src( // only do lfs pull if a requirement! if source.lfs() { - git_lfs_pull()?; + git_lfs_pull(&ref_git)?; } tracing::info!( @@ -211,10 +211,10 @@ pub fn git_src( Ok((cache_path, ref_git)) } -fn git_lfs_pull() -> Result<(), SourceError> { - // verify lfs install +fn git_lfs_pull(git_ref: &str) -> Result<(), SourceError> { + // verify git-lfs is installed let mut command = Command::new("git"); - command.args(["lfs", "install"]); + command.args(["lfs", "ls-files"]); let output = command .output() .map_err(|_| SourceError::GitErrorStr("failed to execute command"))?; @@ -224,14 +224,24 @@ fn git_lfs_pull() -> Result<(), SourceError> { )); } - // git lfs pull + // git lfs fetch let mut command = Command::new("git"); - command.args(["lfs", "pull"]); + command.args(["lfs", "fetch", "origin", git_ref]); let output = command .output() .map_err(|_| SourceError::GitErrorStr("failed to execute command"))?; if !output.status.success() { - return Err(SourceError::GitErrorStr("`git lfs pull` failed!")); + return Err(SourceError::GitErrorStr("`git lfs fetch` failed!")); + } + + // git lfs checkout + let mut command = Command::new("git"); + command.args(["lfs", "checkout"]); + let output = command + .output() + .map_err(|_| SourceError::GitErrorStr("failed to execute command"))?; + if !output.status.success() { + return Err(SourceError::GitErrorStr("`git lfs checkout` failed!")); } Ok(())