Skip to content

Commit

Permalink
Include git output error context on git failures
Browse files Browse the repository at this point in the history
Previously, we'd capture and just throw the error messages away.
Instead, format them with the returned error.
  • Loading branch information
andrewjcg committed Oct 2, 2024
1 parent efe4acd commit 3e8e136
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/source/git_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ pub fn fetch_repo(

if !output.status.success() {
tracing::debug!("Repository fetch for revision {:?} failed!", rev);
return Err(SourceError::GitErrorStr(
"failed to git fetch refs from origin",
));
return Err(SourceError::GitError(format!(
"failed to git fetch refs from origin: {}",
std::str::from_utf8(&output.stderr).unwrap()
)));
}

// try to suppress detached head warning
Expand All @@ -62,7 +63,10 @@ pub fn fetch_repo(

if !output.status.success() {
tracing::debug!("Repository fetch for revision {:?} failed!", rev);
return Err(SourceError::GitErrorStr("failed to checkout FETCH_HEAD"));
return Err(SourceError::GitError(format!(
"failed to checkout FETCH_HEAD: {}",
std::str::from_utf8(&output.stderr).unwrap()
)));
}

let output = git_command(system_tools, "checkout")?
Expand All @@ -73,7 +77,10 @@ pub fn fetch_repo(

if !output.status.success() {
tracing::debug!("Repository checkout for revision {:?} failed!", rev);
return Err(SourceError::GitErrorStr("failed to checkout FETCH_HEAD"));
return Err(SourceError::GitError(format!(
"failed to checkout FETCH_HEAD: {}",
std::str::from_utf8(&output.stderr).unwrap()
)));
}

// Update submodules
Expand All @@ -84,7 +91,10 @@ pub fn fetch_repo(

if !output.status.success() {
tracing::debug!("Submodule update failed!");
return Err(SourceError::GitErrorStr("failed to update submodules"));
return Err(SourceError::GitError(format!(
"failed to update submodules: {}",
std::str::from_utf8(&output.stderr).unwrap()
)));
}

tracing::debug!("Repository fetched successfully!");
Expand Down

0 comments on commit 3e8e136

Please sign in to comment.