diff options
author | Max Jonas Werner <mail@makk.es> | 2023-10-07 00:02:01 +0200 |
---|---|---|
committer | Max Jonas Werner <mail@makk.es> | 2023-10-12 11:26:36 +0200 |
commit | 129b709887b4528ced42c8d74f4c2609800a8942 (patch) | |
tree | df965cf99f0ae91b3ea662690fb17c8f672fd58d /plumbing/transport/internal/common/common.go | |
parent | 19fe126d8889134e6224717a756745eed9985e22 (diff) | |
download | go-git-129b709887b4528ced42c8d74f4c2609800a8942.tar.gz |
plumbing: transport/common, Improve handling of remote errors
Instead of simply returning the first line that the remote returned,
go-git now actively searches all of stderr for lines that may contain
a more actionable error message and returns that.
In addition, this change adds a case to map the GitLab-specific error
message to an ErrRepositoryNotFound error.
Signed-off-by: Max Jonas Werner <mail@makk.es>
Diffstat (limited to 'plumbing/transport/internal/common/common.go')
-rw-r--r-- | plumbing/transport/internal/common/common.go | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/plumbing/transport/internal/common/common.go b/plumbing/transport/internal/common/common.go index 5fdf425..6574116 100644 --- a/plumbing/transport/internal/common/common.go +++ b/plumbing/transport/internal/common/common.go @@ -11,6 +11,7 @@ import ( "errors" "fmt" "io" + "regexp" "strings" "time" @@ -28,6 +29,10 @@ const ( var ( ErrTimeoutExceeded = errors.New("timeout exceeded") + // stdErrSkipPattern is used for skipping lines from a command's stderr output. + // Any line matching this pattern will be skipped from further + // processing and not be returned to calling code. + stdErrSkipPattern = regexp.MustCompile("^remote:( =*){0,1}$") ) // Commander creates Command instances. This is the main entry point for @@ -149,10 +154,17 @@ func (c *client) listenFirstError(r io.Reader) chan string { errLine := make(chan string, 1) go func() { s := bufio.NewScanner(r) - if s.Scan() { - errLine <- s.Text() - } else { - close(errLine) + for { + if s.Scan() { + line := s.Text() + if !stdErrSkipPattern.MatchString(line) { + errLine <- line + break + } + } else { + close(errLine) + break + } } _, _ = io.Copy(io.Discard, r) @@ -393,6 +405,7 @@ var ( gitProtocolNoSuchErr = "ERR no such repository" gitProtocolAccessDeniedErr = "ERR access denied" gogsAccessDeniedErr = "Gogs: Repository does not exist or you do not have access" + gitlabRepoNotFoundErr = "remote: ERROR: The project you were looking for could not be found" ) func isRepoNotFoundError(s string) bool { @@ -424,6 +437,10 @@ func isRepoNotFoundError(s string) bool { return true } + if strings.HasPrefix(s, gitlabRepoNotFoundErr) { + return true + } + return false } |