add lfs.gitprotocol to configure default protocol for git:// lfs server
This commit is contained in:
parent
cc8524fa2a
commit
2282a34704
@ -112,7 +112,6 @@ func (c *Configuration) GetenvBool(key string, def bool) bool {
|
||||
// GitRemoteUrl returns the git clone/push url for a given remote (blank if not found)
|
||||
// the forpush argument is to cater for separate remote.name.pushurl settings
|
||||
func (c *Configuration) GitRemoteUrl(remote string, forpush bool) string {
|
||||
|
||||
if forpush {
|
||||
if u, ok := c.GitConfig("remote." + remote + ".pushurl"); ok {
|
||||
return u
|
||||
@ -128,15 +127,14 @@ func (c *Configuration) GitRemoteUrl(remote string, forpush bool) string {
|
||||
}
|
||||
|
||||
func (c *Configuration) Endpoint(operation string) Endpoint {
|
||||
|
||||
if operation == "upload" {
|
||||
if url, ok := c.GitConfig("lfs.pushurl"); ok {
|
||||
return NewEndpoint(url)
|
||||
return NewEndpointWithConfig(url, c)
|
||||
}
|
||||
}
|
||||
|
||||
if url, ok := c.GitConfig("lfs.url"); ok {
|
||||
return NewEndpoint(url)
|
||||
return NewEndpointWithConfig(url, c)
|
||||
}
|
||||
|
||||
if len(c.CurrentRemote) > 0 && c.CurrentRemote != defaultRemote {
|
||||
@ -252,16 +250,16 @@ func (c *Configuration) RemoteEndpoint(remote, operation string) Endpoint {
|
||||
// Support separate push URL if specified and pushing
|
||||
if operation == "upload" {
|
||||
if url, ok := c.GitConfig("remote." + remote + ".lfspushurl"); ok {
|
||||
return NewEndpoint(url)
|
||||
return NewEndpointWithConfig(url, c)
|
||||
}
|
||||
}
|
||||
if url, ok := c.GitConfig("remote." + remote + ".lfsurl"); ok {
|
||||
return NewEndpoint(url)
|
||||
return NewEndpointWithConfig(url, c)
|
||||
}
|
||||
|
||||
// finally fall back on git remote url (also supports pushurl)
|
||||
if url := c.GitRemoteUrl(remote, operation == "upload"); url != "" {
|
||||
return NewEndpointFromCloneURL(url)
|
||||
return NewEndpointFromCloneURLWithConfig(url, c)
|
||||
}
|
||||
|
||||
return Endpoint{}
|
||||
@ -272,6 +270,15 @@ func (c *Configuration) Remotes() []string {
|
||||
return c.remotes
|
||||
}
|
||||
|
||||
// GitProtocol returns the protocol for the LFS API when converting from a
|
||||
// git:// remote url.
|
||||
func (c *Configuration) GitProtocol() string {
|
||||
if value, ok := c.GitConfig("lfs.gitprotocol"); ok {
|
||||
return value
|
||||
}
|
||||
return "https"
|
||||
}
|
||||
|
||||
func (c *Configuration) Extensions() map[string]Extension {
|
||||
c.loadGitConfig()
|
||||
return c.extensions
|
||||
|
@ -256,6 +256,22 @@ func TestGitEndpointAddsLfsSuffix(t *testing.T) {
|
||||
assert.Equal(t, "", endpoint.SshPort)
|
||||
}
|
||||
|
||||
func TestGitEndpointAddsLfsSuffixWithCustomProtocol(t *testing.T) {
|
||||
config := &Configuration{
|
||||
gitConfig: map[string]string{
|
||||
"remote.origin.url": "git://example.com/foo/bar",
|
||||
"lfs.gitprotocol": "http",
|
||||
},
|
||||
remotes: []string{},
|
||||
}
|
||||
|
||||
endpoint := config.Endpoint("download")
|
||||
assert.Equal(t, "http://example.com/foo/bar.git/info/lfs", endpoint.Url)
|
||||
assert.Equal(t, "", endpoint.SshUserAndHost)
|
||||
assert.Equal(t, "", endpoint.SshPath)
|
||||
assert.Equal(t, "", endpoint.SshPort)
|
||||
}
|
||||
|
||||
func TestBareGitEndpointAddsLfsSuffix(t *testing.T) {
|
||||
config := &Configuration{
|
||||
gitConfig: map[string]string{"remote.origin.url": "git://example.com/foo/bar.git"},
|
||||
|
@ -21,7 +21,18 @@ type Endpoint struct {
|
||||
// NewEndpointFromCloneURL creates an Endpoint from a git clone URL by appending
|
||||
// "[.git]/info/lfs".
|
||||
func NewEndpointFromCloneURL(url string) Endpoint {
|
||||
e := NewEndpoint(url)
|
||||
return NewEndpointFromCloneURLWithConfig(url, NewConfig())
|
||||
}
|
||||
|
||||
// NewEndpoint initializes a new Endpoint for a given URL.
|
||||
func NewEndpoint(rawurl string) Endpoint {
|
||||
return NewEndpointWithConfig(rawurl, NewConfig())
|
||||
}
|
||||
|
||||
// NewEndpointFromCloneURLWithConfig creates an Endpoint from a git clone URL by appending
|
||||
// "[.git]/info/lfs".
|
||||
func NewEndpointFromCloneURLWithConfig(url string, c *Configuration) Endpoint {
|
||||
e := NewEndpointWithConfig(url, c)
|
||||
if e.Url == EndpointUrlUnknown {
|
||||
return e
|
||||
}
|
||||
@ -35,8 +46,8 @@ func NewEndpointFromCloneURL(url string) Endpoint {
|
||||
return e
|
||||
}
|
||||
|
||||
// NewEndpoint initializes a new Endpoint for a given URL.
|
||||
func NewEndpoint(rawurl string) Endpoint {
|
||||
// NewEndpointWithConfig initializes a new Endpoint for a given URL.
|
||||
func NewEndpointWithConfig(rawurl string, c *Configuration) Endpoint {
|
||||
u, err := url.Parse(rawurl)
|
||||
if err != nil {
|
||||
return Endpoint{Url: EndpointUrlUnknown}
|
||||
@ -48,7 +59,7 @@ func NewEndpoint(rawurl string) Endpoint {
|
||||
case "http", "https":
|
||||
return endpointFromHttpUrl(u)
|
||||
case "git":
|
||||
return endpointFromGitUrl(u)
|
||||
return endpointFromGitUrl(u, c)
|
||||
case "":
|
||||
return endpointFromBareSshUrl(u)
|
||||
default:
|
||||
@ -128,8 +139,8 @@ func endpointFromHttpUrl(u *url.URL) Endpoint {
|
||||
return Endpoint{Url: u.String()}
|
||||
}
|
||||
|
||||
func endpointFromGitUrl(u *url.URL) Endpoint {
|
||||
u.Scheme = "https"
|
||||
func endpointFromGitUrl(u *url.URL, c *Configuration) Endpoint {
|
||||
u.Scheme = c.GitProtocol()
|
||||
return Endpoint{Url: u.String()}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user