diff options
author | Colton McCurdy <mccurdyc22@gmail.com> | 2018-11-01 08:01:34 -0400 |
---|---|---|
committer | Colton McCurdy <mccurdyc22@gmail.com> | 2018-11-01 08:01:34 -0400 |
commit | 3fe6f65a9955d25d51d195d5d4ce43339c813534 (patch) | |
tree | 5b1f0168b856665a1fb2a9eabab3af4bb056e28f /example_test.go | |
parent | 43d4551b4b6e49af1a1402047b3a81fbcd6a85e9 (diff) | |
parent | 959dc01faa3352c0b41ff0fa257239f5f00165db (diff) | |
download | go-git-3fe6f65a9955d25d51d195d5d4ce43339c813534.tar.gz |
Merge branch 'master' of github.com:src-d/go-git into mccurdyc/Issue#969/fix-flaky-ssh-test
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", |