Skip to content

Commit

Permalink
Clean-retry on "fatal: bad object"
Browse files Browse the repository at this point in the history
  • Loading branch information
DrJosh9000 committed Jul 18, 2023
1 parent 15c730e commit 286959c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/job/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,8 @@ func (e *Executor) CheckoutPhase(ctx context.Context) error {
switch ge.Type {
// These types can fail because of corrupted checkouts
case gitErrorClean, gitErrorCleanSubmodules, gitErrorClone,
gitErrorCheckoutRetryClean, gitErrorFetchRetryClean:
gitErrorCheckoutRetryClean, gitErrorFetchRetryClean,
gitErrorFetchBadObject:
// Otherwise, don't clean the checkout dir
default:
return err
Expand Down
11 changes: 11 additions & 0 deletions internal/job/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
gitErrorClone
gitErrorFetch
gitErrorFetchRetryClean
gitErrorFetchBadObject
gitErrorClean
gitErrorCleanSubmodules
)
Expand Down Expand Up @@ -139,6 +140,16 @@ func gitFetch(ctx context.Context, sh shellRunner, gitFetchFlags, repository str
}

if err := sh.Run(ctx, "git", commandArgs...); err != nil {
// "fatal: bad object" can happen when the local repo in the checkout
// directory is corrupted, not just the remote or the mirror.
// When using git mirrors, the existing checkout directory might have a
// reference to an object that it expects in the mirror, but the mirror
// no longer contains it (for whatever reason).
// See the NOTE under --shared at https://git-scm.com/docs/git-clone.
if strings.HasPrefix(err.Error(), "fatal: bad object") {
return &gitError{error: err, Type: gitErrorFetchBadObject}
}

// 128 is extremely broad, but it seems permissions errors, network unreachable errors etc, don't result in it
if exitErr := new(exec.ExitError); errors.As(err, &exitErr) && exitErr.ExitCode() == 128 {
return &gitError{error: err, Type: gitErrorFetchRetryClean}
Expand Down

0 comments on commit 286959c

Please sign in to comment.