fix: Fix the panic when ssh remote lfs endpoint parsing failure (#38026) (#38158)

Fix #38016
Backport #38026
This commit is contained in:
Lunny Xiao
2026-06-18 01:34:58 -07:00
committed by GitHub
parent 6fb96fcfdf
commit 0b9623e188
7 changed files with 74 additions and 12 deletions
+18 -2
View File
@@ -5,9 +5,12 @@ package lfs
import (
"context"
"fmt"
"io"
"net/http"
"net/url"
"code.gitea.io/gitea/modules/util"
)
// DownloadCallback gets called for every requested LFS object to process its content
@@ -23,10 +26,23 @@ type Client interface {
Upload(ctx context.Context, objects []Pointer, callback UploadCallback) error
}
// NewClient creates a LFS client
func NewClient(endpoint *url.URL, httpTransport *http.Transport) Client {
// newClient creates a LFS client
func newClient(endpoint *url.URL, httpTransport *http.Transport) Client {
if endpoint.Scheme == "file" {
return newFilesystemClient(endpoint)
}
return newHTTPClient(endpoint, httpTransport)
}
// NewClientFromEndpoint creates a LFS client after resolving its endpoint.
func NewClientFromEndpoint(cloneurl, lfsurl string, httpTransport *http.Transport) (Client, error) {
endpoint := DetermineEndpoint(cloneurl, lfsurl)
if endpoint == nil {
source := cloneurl
if lfsurl != "" {
source = lfsurl
}
return nil, fmt.Errorf("unable to determine LFS endpoint from %q", util.SanitizeCredentialURLs(source))
}
return newClient(endpoint, httpTransport), nil
}