From ef060bcc5cbb4b18621dccdec70a35667c4159a9 Mon Sep 17 00:00:00 2001 From: qiansc Date: Sat, 14 Nov 2026 08:43:43 +0000 Subject: [PATCH] feat: treat anonymous credential prompts as unavailable repositories GitHub answers an anonymous request for a private or missing repository with a credential prompt ("could not read Username"). Report it as GIT_REPOSITORY_UNAVAILABLE so registration offers to bind a token instead of only suggesting a retry. Co-Authored-By: Claude Opus 5.5 --- internal/gitstore/remote_error.go | 5 +++-- internal/gitstore/remote_error_test.go | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/gitstore/remote_error.go b/internal/gitstore/remote_error.go index 3aaa270..89a41bf 100644 --- a/internal/gitstore/remote_error.go +++ b/internal/gitstore/remote_error.go @@ -15,8 +15,9 @@ func remoteFailure(diagnostic, code, message string) error { return contract.Fail("GIT_AUTH_FAILED", "Code-service credential was rejected; update the credential.", 401) } // Code hosts answer "not found" both for missing repositories and for private - // ones the credential cannot see, so the message names both causes. - if httpStatus(text, "404") || strings.Contains(text, "repository not found") || (strings.Contains(text, "repository '") && strings.Contains(text, "' not found")) { + // ones the credential cannot see, so the message names both causes. An + // anonymous request the host answers with a credential prompt means the same. + if httpStatus(text, "404") || strings.Contains(text, "could not read username") || strings.Contains(text, "repository not found") || (strings.Contains(text, "repository '") && strings.Contains(text, "' not found")) { return contract.Fail("GIT_REPOSITORY_UNAVAILABLE", "Repository not found, or the code-service credential used cannot see it.", 404) } return contract.Fail(code, message, 503) diff --git a/internal/gitstore/remote_error_test.go b/internal/gitstore/remote_error_test.go index dbdbe83..f315544 100644 --- a/internal/gitstore/remote_error_test.go +++ b/internal/gitstore/remote_error_test.go @@ -11,10 +11,11 @@ func TestRemoteFailureNamesMissingOrInvisibleRepositories(t *testing.T) { for diagnostic, want := range map[string]string{ "remote: Repository not found.\nfatal: repository 'https://code.example.com/a/b.git/' not found": "GIT_REPOSITORY_UNAVAILABLE", "fatal: unable to access 'https://x/a/b.git/': The requested URL returned error: 404": "GIT_REPOSITORY_UNAVAILABLE", - "error: 404 Not Found": "GIT_REPOSITORY_UNAVAILABLE", - "fatal: Authentication failed for 'https://x'": "GIT_AUTH_FAILED", - "error: 403 Forbidden": "GIT_ACCESS_DENIED", - "fatal: unable to connect": "GIT_FETCH_FAILED", + "error: 404 Not Found": "GIT_REPOSITORY_UNAVAILABLE", + "fatal: could not read Username for 'https://github.com': terminal prompts disabled": "GIT_REPOSITORY_UNAVAILABLE", + "fatal: Authentication failed for 'https://x'": "GIT_AUTH_FAILED", + "error: 403 Forbidden": "GIT_ACCESS_DENIED", + "fatal: unable to connect": "GIT_FETCH_FAILED", } { var ce *contract.Error if err := remoteFailure(diagnostic, "GIT_FETCH_FAILED", "fetch failed"); !errors.As(err, &ce) || ce.Code != want {