Skip to content

Commit

Permalink
feat: include git output error context on git failures (#1079)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjcg authored Oct 2, 2024
1 parent 5b54e0a commit 85f53f8
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 85f53f8

Please sign in to comment.