Improve error messaging for git submodule push failures (#5226)

Detect when git push operations fail due to un-pushed or out-of-sync
submodules, and extract the specific submodule name to provide clear,
actionable guidance to the user.

Additionally, update the Source Control error UI to allow better text
wrapping and word-breaking for detailed error alerts.
This commit is contained in:
Jinjing
2026-06-11 17:32:49 -07:00
committed by GitHub
parent 08456103cb
commit 1f6bfe0503
6 changed files with 197 additions and 5 deletions
+43 -1
View File
@@ -1,5 +1,47 @@
import { describe, expect, it } from 'vitest'
import { isNoUpstreamError } from './git-remote-error'
import {
formatSubmodulePushFailureDetail,
isNoUpstreamError,
normalizeGitErrorMessage
} from './git-remote-error'
describe('normalizeGitErrorMessage', () => {
it('keeps the submodule name when a recursive push is rejected', () => {
const error = new Error(
"Command failed: git push\nPushing submodule 'find-cmux-followers'\n" +
'To https://github.com/stablyai/orca-internal\n' +
' ! [rejected] master -> master (fetch first)\n' +
"Unable to push submodule 'find-cmux-followers'\n" +
'fatal: failed to push all needed submodules'
)
expect(normalizeGitErrorMessage(error, 'push')).toBe(
"Submodule 'find-cmux-followers' has remote changes. Pull inside the submodule, then try again."
)
})
})
describe('formatSubmodulePushFailureDetail', () => {
it('keeps normalized guidance when transport layers prefix the error', () => {
expect(
formatSubmodulePushFailureDetail(
"Error invoking remote method 'git:push': Error: Submodule 'vendor/tools' has remote changes. Pull inside the submodule, then try again."
)
).toBe(
"Submodule 'vendor/tools' has remote changes. Pull inside the submodule, then try again."
)
})
it('falls back to submodule-specific guidance when git omits the nested reason', () => {
expect(
formatSubmodulePushFailureDetail(
"Unable to push submodule 'vendor/tools'\nfatal: failed to push all needed submodules"
)
).toBe(
"Submodule 'vendor/tools' could not be pushed. Resolve the submodule push error, then try again."
)
})
})
describe('isNoUpstreamError', () => {
it('treats a missing HEAD@{u} tracking ref as no upstream', () => {