#php editor Baicao introduced that when using the Plainclone function of go-git, when you provide the git repo url, /git-upload-pack will be automatically appended. This is because git-upload-pack is the command used by the git protocol to clone and pull remote repositories. With this feature, you can easily clone and pull remote repositories without adding /git-upload-pack manually. In this way, you can use go-git to perform git operations more conveniently and improve work efficiency.
Try to clone the repository from Azure Devops.
func (gitopt *GitOptions) clone() (*git.Repository, error) { r, err := git.PlainClone(gitopt.RepoDir, false, &git.CloneOptions{ Progress: os.Stdout, URL: "https://<path to repo>", Auth: &http.BasicAuth{ Username: "gituser", Password: gitopt.PAT, }, }) if err != nil { log.Info(err.Error()) return nil, err } return r, nil }
Running this code adds /git-upload-pack ("https://
The HTTP-based Git protocol consists of two steps, depending on the protocol version used. In v0 and v1, the first request is to /info/refs
and reads the refs in use, then the second request is to /git-upload-pack
(for get and clone) or /git-receive-pack
(for pushing). In v2, the endpoints are the same, but the first is the feature request, and then the ref request and data transfer to the second endpoint.
In all these cases, the URL you provide is just the basis for appending the path. Different paths make it easier to control access to a simple Git server behind something like nginx or Apache, which is why there isn't just a single URL component.
So the generated URL is actually correct. The reason you're seeing a 400 is because There's a problem Azure DevOps requires the client to support the multi_ack
feature, which go-git doesn't support. While technically servers don't have to provide support for any clients they don't want to, the Git Smart HTTP protocol is generally designed to degrade gracefully, so it's not a safe assumption that clients necessarily support any particular set. functionality, and Azure DevOps should avoid making this assumption.
Linked issues have a link to a pull request that fixes the issue in some (but not all) cases. However, you may need to update to a higher version to take advantage of this.
The above is the detailed content of When using go-git's Plainclone feature, the git repo url will have /git-upload-pack appended. For more information, please follow other related articles on the PHP Chinese website!