Skip to content

Commit

Permalink
feat: improve git-lfs handling (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun authored Apr 3, 2024
1 parent 1a77e25 commit 71a070b
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/source/git_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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"))?;
Expand All @@ -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(())
Expand Down

0 comments on commit 71a070b

Please sign in to comment.