Skip to content

Commit f2dfad0

Browse files
fix(server): recognize Git diagnostic lines precisely
1 parent 3230a6b commit f2dfad0

2 files changed

Lines changed: 33 additions & 16 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,18 @@ for (const scenario of [
867867
stderr: "fatal: Unable to create '/repo/.git/FETCH_HEAD.lock': File exists.",
868868
expected: "could not update a local reference",
869869
},
870+
{
871+
name: "unrelated remote chatter",
872+
stderr:
873+
"remote: Help: authentication failed, connection refused, cannot lock ref\nremote: unrelated service error",
874+
expected: "git fetch origin failed",
875+
},
876+
{
877+
name: "HTTPS DNS failure",
878+
stderr:
879+
"fatal: unable to access 'https://example.com/repo.git/': Could not resolve host: example.com",
880+
expected: "could not reach the remote",
881+
},
870882
{
871883
name: "unknown failure",
872884
stderr: "fatal: unexpected remote failure",

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -472,35 +472,40 @@ function isMissingWorktreeStderr(stderr: string): boolean {
472472
// Fetch stderr can contain remote credentials. Only fixed diagnoses may enter
473473
// persisted errors; unrecognized output keeps the generic failure message.
474474
function fetchFailureDetail(stderr: string): string | undefined {
475-
const normalized = stderr.toLowerCase();
475+
const lines = stderr.split(/\r?\n/).map((line) => line.trim());
476476
if (
477-
normalized.includes("authentication failed") ||
478-
normalized.includes("permission denied (publickey") ||
479-
normalized.includes("could not read username") ||
480-
normalized.includes("could not read password") ||
481-
normalized.includes("terminal prompts disabled")
477+
lines.some((line) =>
478+
/^(?:fatal: (?:Authentication failed|could not read (?:Username|Password))\b|\S+: Permission denied \(publickey)/i.test(
479+
line,
480+
),
481+
)
482482
) {
483483
return "Git could not authenticate with the remote. Check Git credentials or SSH access on the server, then retry.";
484484
}
485485
if (
486-
normalized.includes("could not resolve host") ||
487-
normalized.includes("could not resolve hostname") ||
488-
normalized.includes("failed to connect") ||
489-
normalized.includes("connection timed out") ||
490-
normalized.includes("connection refused") ||
491-
normalized.includes("network is unreachable")
486+
lines.some((line) =>
487+
/^(?:(?:fatal: |ssh: )?Could not resolve host(?:name)?\b|fatal: unable to access .+: (?:Could not resolve host|Failed to connect)\b|ssh: connect to host \S+ port \d+: (?:Connection timed out|Connection refused|Network is unreachable)\b)/i.test(
488+
line,
489+
),
490+
)
492491
) {
493492
return "Git could not reach the remote. Check the server's network connection and remote host, then retry.";
494493
}
495494
if (
496-
normalized.includes("repository not found") ||
497-
normalized.includes("does not appear to be a git repository")
495+
lines.some((line) =>
496+
/^(?:remote: Repository not found\.?$|fatal: repository .+ not found$|fatal: .+ does not appear to be a git repository$)/i.test(
497+
line,
498+
),
499+
)
498500
) {
499501
return "Git could not access the remote repository. Check the remote URL and repository permissions on the server.";
500502
}
501503
if (
502-
normalized.includes("cannot lock ref") ||
503-
(normalized.includes("unable to create") && normalized.includes(".lock"))
504+
lines.some((line) =>
505+
/^(?:(?:error|fatal): cannot lock ref\b|fatal: Unable to create ['"].+\.lock['"]:)/i.test(
506+
line,
507+
),
508+
)
504509
) {
505510
return "Git could not update a local reference. Another Git operation or a stale lock may be blocking the fetch; check the repository on the server, then retry.";
506511
}

0 commit comments

Comments
 (0)