Skip to content

Commit 88a2231

Browse files
committed
ObjectsUrl() can now return an error
1 parent 476657d commit 88a2231

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

lfs/client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,11 @@ func setErrorHeaderContext(err *WrappedError, prefix string, head http.Header) {
505505
}
506506

507507
func request(method, oid string) (*http.Request, Creds, error) {
508-
u := Config.ObjectUrl(oid)
508+
u, err := Config.ObjectUrl(oid)
509+
if err != nil {
510+
return nil, nil, err
511+
}
512+
509513
req, err := http.NewRequest(method, u.String(), nil)
510514
if err != nil {
511515
return req, nil, err

lfs/config.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,14 @@ func (c *Configuration) SetConfig(key, value string) {
9393
c.gitConfig[key] = value
9494
}
9595

96-
func (c *Configuration) ObjectUrl(oid string) *url.URL {
97-
u, _ := url.Parse(c.Endpoint())
96+
func (c *Configuration) ObjectUrl(oid string) (*url.URL, error) {
97+
u, err := url.Parse(c.Endpoint())
98+
if err != nil {
99+
return nil, err
100+
}
101+
98102
u.Path = path.Join(u.Path, "objects", oid)
99-
return u
103+
return u, nil
100104
}
101105

102106
type AltConfig struct {

lfs/config_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ func TestBareHTTPEndpointAddsMediaSuffix(t *testing.T) {
107107
}
108108

109109
func TestObjectUrl(t *testing.T) {
110-
oid := "oid"
111110
tests := map[string]string{
112111
"http://example.com": "http://example.com/objects/oid",
113112
"http://example.com/": "http://example.com/objects/oid",
@@ -117,6 +116,13 @@ func TestObjectUrl(t *testing.T) {
117116

118117
for endpoint, expected := range tests {
119118
Config.SetConfig("lfs.url", endpoint)
120-
assert.Equal(t, expected, Config.ObjectUrl(oid).String())
119+
u, err := Config.ObjectUrl("oid")
120+
if err != nil {
121+
t.Errorf("Error building URL for %s: %s", endpoint, err)
122+
} else {
123+
if actual := u.String(); expected != actual {
124+
t.Errorf("Expected %s, got %s", expected, u.String())
125+
}
126+
}
121127
}
122128
}

0 commit comments

Comments
 (0)