-
-
Save roscopecoltran/4f8009e974c646e06f26e24344aa13d5 to your computer and use it in GitHub Desktop.
Demonstrate go-git race
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package clone | |
import ( | |
"os" | |
"golang.org/x/crypto/ssh" | |
"gopkg.in/src-d/go-git.v4" | |
gitssh "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh" | |
"io/ioutil" | |
"testing" | |
) | |
var TestSSHKey = ` | |
your ssh key here | |
` | |
// Race can be reproduced with this repo | |
var Repo = "[email protected]:kimh/trusty-test.git" | |
// But not with this repo | |
//var Repo = "[email protected]:octocat/hello-worId.git" | |
func Clone() error { | |
url := Repo | |
directory, _ := ioutil.TempDir("", "") | |
defer os.RemoveAll(directory) | |
buffer := []byte(TestSSHKey) | |
signer, err := ssh.ParsePrivateKey(buffer) | |
if err != nil { | |
return err | |
} | |
_, err = git.PlainClone(directory, false, &git.CloneOptions{ | |
URL: url, | |
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