Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 0f1ffaa

Browse files
committed
Fix host redirect handling
If you try to clone from a url that redirects to another host e.g. `example.com/repo` -> `github.com/org/repo.git`, it results in a redirect to `example.com/org/repo.git` because ModifyEndpointIfRedirect only takes into account the scheme and path. Signed-off-by: DisposaBoy <[email protected]>
1 parent 87cc819 commit 0f1ffaa

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

plumbing/transport/http/common.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,14 @@ func (s *session) ModifyEndpointIfRedirect(res *http.Response) {
151151
return
152152
}
153153

154+
host, port, err := net.SplitHostPort(r.URL.Host)
155+
if err != nil {
156+
host = r.URL.Host
157+
}
158+
154159
s.endpoint.Protocol = r.URL.Scheme
160+
s.endpoint.Host = host
161+
s.endpoint.Port, _ = strconv.Atoi(port)
155162
s.endpoint.Path = r.URL.Path[:len(r.URL.Path)-len(infoRefsPath)]
156163
}
157164

0 commit comments

Comments
 (0)