Skip to content

Instantly share code, notes, and snippets.

@kimh
Last active November 16, 2018 00:19
Show Gist options
  • Select an option

  • Save kimh/21aee8751007780517249f8f09acb262 to your computer and use it in GitHub Desktop.

Select an option

Save kimh/21aee8751007780517249f8f09acb262 to your computer and use it in GitHub Desktop.
Demonstrate go-git race
package clone
import (
"fmt"
"os"
"golang.org/x/crypto/ssh"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
gitssh "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
"io/ioutil"
"testing"
)
var TestSSHKey = `
PASTE YOUR SSH KEY HERE
`
var Repo = "git@github.com:kimh/trusty-test.git"
func Clone() error {
url := Repo
directory, _ := ioutil.TempDir("", "")
defer os.RemoveAll(directory)
branchRef := plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", "master"))
buffer := []byte(TestSSHKey)
signer, err := ssh.ParsePrivateKey(buffer)
if err != nil {
return err
}
_, err = git.PlainClone(directory, false, &git.CloneOptions{
URL: url,
// This will automatically checkout to the branch
ReferenceName: branchRef,
Auth: &gitssh.PublicKeys{
User: "git",
Signer: signer,
},
Progress: os.Stdout,
})
if err != nil {
return err
}
return nil
}
func TestClone(t *testing.T) {
err := Clone()
if err != nil {
t.Fatalf("Get error: %v", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment