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

Commit

Permalink
Fix host redirect handling
Browse files Browse the repository at this point in the history
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 <disposaboy@kuroku.io>
  • Loading branch information
DisposaBoy committed Apr 27, 2018
1 parent 87cc819 commit 0f1ffaa
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions plumbing/transport/http/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,14 @@ func (s *session) ModifyEndpointIfRedirect(res *http.Response) {
return
}

host, port, err := net.SplitHostPort(r.URL.Host)
if err != nil {
host = r.URL.Host
}

s.endpoint.Protocol = r.URL.Scheme
s.endpoint.Host = host
s.endpoint.Port, _ = strconv.Atoi(port)
s.endpoint.Path = r.URL.Path[:len(r.URL.Path)-len(infoRefsPath)]
}

Expand Down

0 comments on commit 0f1ffaa

Please sign in to comment.