Skip to content

Commit

Permalink
Support clones from Azure DevOps
Browse files Browse the repository at this point in the history
In general, go-git can't clone from Azure DevOps, because the latter
requires the capabilities multi_ack and multi_ack_detailed, which aren't
implemented. However, there's now a workaround, which boils down to
this: pretend, for the initial clone, that those capabilities _are_
supported, and expect them not to be used.

(See go-git/go-git#613 for more on this
workaround.)

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
  • Loading branch information
squaremo committed Jan 26, 2023
1 parent 7bcc9e8 commit 81402c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sdk/go.mod
Expand Up @@ -40,7 +40,7 @@ require (
)

require (
github.com/go-git/go-git/v5 v5.4.2
github.com/go-git/go-git/v5 v5.5.1
github.com/pkg/term v1.1.0
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
Expand Down
16 changes: 16 additions & 0 deletions sdk/go/auto/git.go
Expand Up @@ -23,6 +23,8 @@ import (

git "github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"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"
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
)
Expand Down Expand Up @@ -111,12 +113,26 @@ func setupGitRepo(ctx context.Context, workDir string, repoArgs *GitRepo) (strin
cloneOptions.ReferenceName = refName
}

// Azure DevOps requires multi_ack and multi_ack_detailed capabilities, which go-git doesn't
// implement. But: it's possible to do a full clone by saying it's _not_ _un_supported, in which
// case the library happily functions so long as it doesn't _actually_ get a multi_ack packet. See
// https://github.com/go-git/go-git/blob/v5.5.1/_examples/azure_devops/main.go.
oldUnsupportedCaps := transport.UnsupportedCapabilities
// This check is crude, but avoids having another dependency to parse the git URL.
if strings.Contains(repoArgs.URL, "dev.azure.com") {
transport.UnsupportedCapabilities = []capability.Capability{
capability.ThinPack,
}
}

// clone
repo, err := git.PlainCloneContext(ctx, workDir, false, cloneOptions)
if err != nil {
return "", fmt.Errorf("unable to clone repo: %w", err)
}

transport.UnsupportedCapabilities = oldUnsupportedCaps

if repoArgs.CommitHash != "" {
// checkout commit if specified
w, err := repo.Worktree()
Expand Down

0 comments on commit 81402c1

Please sign in to comment.