diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2022-11-16 12:07:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-16 12:07:28 +0100 |
commit | 71f6540e90b9a8cd3d4e3455b7d1d53c60a39d16 (patch) | |
tree | ca3c69cd0b49501450e68dc196cd81403caeaf90 /_examples | |
parent | 452df976faca7193b275bd31a0d76027a2a9df5c (diff) | |
parent | 9c7d2df0f3b85745bea4d764e51ab9e811bf644d (diff) | |
download | go-git-71f6540e90b9a8cd3d4e3455b7d1d53c60a39d16.tar.gz |
Merge pull request #613 from fluxcd/unsupported
Allow unsupported `multi_ack` capability
Diffstat (limited to '_examples')
-rw-r--r-- | _examples/azure_devops/main.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/_examples/azure_devops/main.go b/_examples/azure_devops/main.go new file mode 100644 index 0000000..9c02ca0 --- /dev/null +++ b/_examples/azure_devops/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "fmt" + "os" + + git "github.com/go-git/go-git/v5" + . "github.com/go-git/go-git/v5/_examples" + "github.com/go-git/go-git/v5/plumbing/protocol/packp/capability" + "github.com/go-git/go-git/v5/plumbing/transport" + "github.com/go-git/go-git/v5/plumbing/transport/http" +) + +func main() { + CheckArgs("<url>", "<directory>", "<azuredevops_username>", "<azuredevops_password>") + url, directory, username, password := os.Args[1], os.Args[2], os.Args[3], os.Args[4] + + // Clone the given repository to the given directory + Info("git clone %s %s", url, directory) + + // Azure DevOps requires capabilities multi_ack / multi_ack_detailed, + // which are not fully implemented and by default are included in + // transport.UnsupportedCapabilities. + // + // The initial clone operations require a full download of the repository, + // and therefore those unsupported capabilities are not as crucial, so + // by removing them from that list allows for the first clone to work + // successfully. + // + // Additional fetches will yield issues, therefore work always from a clean + // clone until those capabilities are fully supported. + // + // New commits and pushes against a remote worked without any issues. + transport.UnsupportedCapabilities = []capability.Capability{ + capability.ThinPack, + } + + r, err := git.PlainClone(directory, false, &git.CloneOptions{ + Auth: &http.BasicAuth{ + Username: username, + Password: password, + }, + URL: url, + Progress: os.Stdout, + }) + CheckIfError(err) + + // ... retrieving the branch being pointed by HEAD + ref, err := r.Head() + CheckIfError(err) + // ... retrieving the commit object + commit, err := r.CommitObject(ref.Hash()) + CheckIfError(err) + + fmt.Println(commit) +} |