diff options
author | Paulo Gomes <pjbgf@linux.com> | 2023-10-12 11:17:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-12 11:17:36 +0100 |
commit | 623c6df4280e22f88f4aabc3c0a8ae2808d33a1b (patch) | |
tree | 6aa4de1565104fc4e4722721c9e25f10f7f2c76b /plumbing/transport/internal/common/common.go | |
parent | e61537e80cfa474cb1cfe63f7210e3dcca5248fe (diff) | |
parent | 129b709887b4528ced42c8d74f4c2609800a8942 (diff) | |
download | go-git-623c6df4280e22f88f4aabc3c0a8ae2808d33a1b.tar.gz |
Merge pull request #866 from makkes/better-error-handling
Improve handling of remote errors
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 } |