Skip to content

Commit 65be82e

Browse files
authored
fix(gitter): index.lock error fallback (#4816)
1 parent aa74065 commit 65be82e

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

go/cmd/gitter/gitter.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ func isAuthError(err error) bool {
114114
}
115115

116116
func isIndexLockError(err error) bool {
117+
if err == nil {
118+
return false
119+
}
117120
errString := err.Error()
121+
118122
return strings.Contains(errString, "index.lock") && strings.Contains(errString, "File exists")
119123
}
120124

@@ -145,7 +149,7 @@ func fetchBlob(ctx context.Context, url string, forceUpdate bool) ([]byte, error
145149
return nil, fmt.Errorf("git fetch failed: %w", err)
146150
}
147151
err = runCmd(ctx, repoPath, nil, "git", "reset", "--hard", "origin/HEAD")
148-
if isIndexLockError(err) {
152+
if err != nil && isIndexLockError(err) {
149153
// index.lock exists, likely a previous git reset got terminated and wasn't cleaned up properly.
150154
// We can remove the file and retry the command
151155
logger.Warn("index.lock exists, attempting to remove and retry", slog.String("url", ctx.Value(urlKey).(string)))
@@ -156,7 +160,6 @@ func fetchBlob(ctx context.Context, url string, forceUpdate bool) ([]byte, error
156160
// One more attempt at git reset
157161
err = runCmd(ctx, repoPath, nil, "git", "reset", "--hard", "origin/HEAD")
158162
}
159-
160163
if err != nil {
161164
return nil, fmt.Errorf("git reset failed: %w", err)
162165
}

0 commit comments

Comments
 (0)