mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-16 18:03:24 +09:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user