fix: classify git failures on stderr, restrict migration failure detail (#39010)

Signed-off-by: silverwind <me@silverwind.io>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwind
2026-09-15 10:59:34 +02:00
committed by GitHub
co-authored by wxiaoguang
parent 7b036e96c2
commit 812191c0f9
30 changed files with 136 additions and 137 deletions
+12 -3
View File
@@ -44,6 +44,10 @@ func (r *runStdError) Stderr() string {
return r.stderr
}
func NewRunStdError(err error, stderr string) RunStdError {
return &runStdError{err: err, stderr: util.NormalizeStringEOL(stderr)}
}
func ErrorAsStderr(err error) (string, bool) {
if runErr, ok := errors.AsType[RunStdError](err); ok {
return runErr.Stderr(), true
@@ -93,6 +97,9 @@ const (
StderrNoSuchRemote1 StderrPrefix = "fatal: no such remote" // git < 2.30, exit status 128
StderrNoSuchRemote2 StderrPrefix = "error: no such remote" // git >= 2.30. exit status 2
StderrAuthenticationFailed StderrPrefix = "fatal: Authentication failed for"
StderrCouldNotReadUsername StderrPrefix = "fatal: could not read Username"
StderrUnknownRevisionOrPath StderrRegexp = "^fatal: .*: unknown revision or path not in the working tree"
StderrNoMergeBase StderrRegexp = "^fatal: .*: no merge base"
StderrFileNoEnoughLines StderrRegexp = `^fatal: file .* has only \d+ lines?`
@@ -126,9 +133,11 @@ func IsStderr(err error, checks ...StderrCheck) bool {
return false
}
for _, checkIntf := range checks {
if matchStderrCheck(stderr, checkIntf) {
return true
for line := range strings.SplitSeq(stderr, "\n") { // git can emit multiple-line message in stderr
for _, checkIntf := range checks {
if matchStderrCheck(line, checkIntf) {
return true
}
}
}
return false