diff options
author | Colton J. McCurdy <colton@stockx.com> | 2018-10-25 14:49:54 -0400 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2018-10-25 20:49:54 +0200 |
commit | cde0367919945862cab219228305b59b4b97cd13 (patch) | |
tree | 057ea7eff36b153b9f741ce24220e96a68f7c29a /example_test.go | |
parent | f22a5cb22a50e889b493b97ed98c7062d00e4504 (diff) | |
download | go-git-cde0367919945862cab219228305b59b4b97cd13.tar.gz |
examples & documentation: PlainClone with Basic Authentication (Password & Access Token) (#990)
examples: PlainClone with Basic Authentication (Password & Access Token)
Diffstat (limited to 'example_test.go')
-rw-r--r-- | example_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/example_test.go b/example_test.go index ef7e3d3..691b4ac 100644 --- a/example_test.go +++ b/example_test.go @@ -11,6 +11,7 @@ import ( "gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4/config" "gopkg.in/src-d/go-git.v4/plumbing" + "gopkg.in/src-d/go-git.v4/plumbing/transport/http" "gopkg.in/src-d/go-git.v4/storage/memory" "gopkg.in/src-d/go-billy.v4/memfs" @@ -69,6 +70,52 @@ func ExamplePlainClone() { // Output: Initial changelog } +func ExamplePlainClone_usernamePassword() { + // Tempdir to clone the repository + dir, err := ioutil.TempDir("", "clone-example") + if err != nil { + log.Fatal(err) + } + + defer os.RemoveAll(dir) // clean up + + // Clones the repository into the given dir, just as a normal git clone does + _, err = git.PlainClone(dir, false, &git.CloneOptions{ + URL: "https://github.com/git-fixtures/basic.git", + Auth: &http.BasicAuth{ + Username: "username", + Password: "password", + }, + }) + + if err != nil { + log.Fatal(err) + } +} + +func ExamplePlainClone_accessToken() { + // Tempdir to clone the repository + dir, err := ioutil.TempDir("", "clone-example") + if err != nil { + log.Fatal(err) + } + + defer os.RemoveAll(dir) // clean up + + // Clones the repository into the given dir, just as a normal git clone does + _, err = git.PlainClone(dir, false, &git.CloneOptions{ + URL: "https://github.com/git-fixtures/basic.git", + Auth: &http.BasicAuth{ + Username: "abc123", // anything except an empty string + Password: "github_access_token", + }, + }) + + if err != nil { + log.Fatal(err) + } +} + func ExampleRepository_References() { r, _ := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{ URL: "https://github.com/git-fixtures/basic.git", |