Skip to content

Commit a395f86

Browse files
rootcursoragent
andcommitted
fix: only retry ref updates on fast-forward conflicts
Avoid retrying unrelated 422 errors during push_files and delete_file ref updates. Match hyphenated fast-forward messages from the GitHub API. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c15cbe9 commit a395f86

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

pkg/github/repositories_helper.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,20 +407,15 @@ func closeGitHubResponse(resp *github.Response) {
407407
}
408408

409409
func isGitRefUpdateConflict(err error, resp *github.Response) bool {
410-
statusCode := 0
411-
if resp != nil && resp.Response != nil {
412-
statusCode = resp.StatusCode
413-
}
414410
if ghErr, ok := err.(*github.ErrorResponse); ok {
415-
if ghErr.Response != nil {
416-
statusCode = ghErr.Response.StatusCode
417-
}
418411
msg := strings.ToLower(ghErr.Message)
419-
if strings.Contains(msg, "fast forward") || strings.Contains(msg, "not a fast forward") {
412+
if strings.Contains(msg, "fast forward") ||
413+
strings.Contains(msg, "fast-forward") ||
414+
strings.Contains(msg, "not a fast forward") {
420415
return true
421416
}
422417
}
423-
return statusCode == http.StatusUnprocessableEntity
418+
return false
424419
}
425420

426421
type gitPushResult struct {

pkg/github/repositories_helper_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ func Test_isGitRefUpdateConflict(t *testing.T) {
8282
Response: resp422.Response,
8383
Message: "Update is not a fast forward",
8484
}, resp422))
85+
assert.True(t, isGitRefUpdateConflict(&github.ErrorResponse{
86+
Response: resp422.Response,
87+
Message: "Cannot fast-forward",
88+
}, resp422))
89+
90+
assert.False(t, isGitRefUpdateConflict(&github.ErrorResponse{
91+
Response: resp422.Response,
92+
Message: "Reference does not exist",
93+
}, resp422))
8594

8695
resp200 := &github.Response{Response: &http.Response{StatusCode: http.StatusOK}}
8796
assert.False(t, isGitRefUpdateConflict(nil, resp200))

0 commit comments

Comments
 (0)