Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve git-lfs handling #756

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading