Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 3fe6f65

Browse files
committed
Merge branch 'master' of github.com:src-d/go-git into mccurdyc/Issue#969/fix-flaky-ssh-test
2 parents 43d4551 + 959dc01 commit 3fe6f65

File tree

23 files changed

+421
-28
lines changed

23 files changed

+421
-28
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ This can be done easily using the [`-s`](https://github.com/git/git/blob/b2c150d
2121

2222
The official support channels, for both users and contributors, are:
2323

24-
- GitHub [issues](https://github.com/src-d/go-git/issues)*
24+
- [StackOverflow go-git tag](https://stackoverflow.com/questions/tagged/go-git) for user questions.
25+
- GitHub [Issues](https://github.com/src-d/go-git/issues)* for bug reports and feature requests.
2526
- Slack: #go-git room in the [source{d} Slack](https://join.slack.com/t/sourced-community/shared_invite/enQtMjc4Njk5MzEyNzM2LTFjNzY4NjEwZGEwMzRiNTM4MzRlMzQ4MmIzZjkwZmZlM2NjODUxZmJjNDI1OTcxNDAyMmZlNmFjODZlNTg0YWM)
2627

2728
*Before opening a new issue or submitting a new pull request, it's helpful to

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2017 Sourced Technologies, S.L.
189+
Copyright 2018 Sourced Technologies, S.L.
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.
@@ -198,4 +198,4 @@
198198
distributed under the License is distributed on an "AS IS" BASIS,
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201-
limitations under the License.
201+
limitations under the License.

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
It can be used to manipulate git repositories at low level *(plumbing)* or high level *(porcelain)*, through an idiomatic Go API. It also supports several types of storage, such as in-memory filesystems, or custom implementations thanks to the [`Storer`](https://godoc.org/gopkg.in/src-d/go-git.v4/plumbing/storer) interface.
77

8-
It's being actively develop since 2015 and is being use extensively by [source{d}](https://sourced.tech/) and [Keybase](https://keybase.io/blog/encrypted-git-for-everyone), and by many other libraries and tools.
8+
It's being actively developed since 2015 and is being used extensively by [source{d}](https://sourced.tech/) and [Keybase](https://keybase.io/blog/encrypted-git-for-everyone), and by many other libraries and tools.
99

1010
Comparison with git
1111
-------------------
1212

1313
*go-git* aims to be fully compatible with [git](https://github.com/git/git), all the *porcelain* operations are implemented to work exactly as *git* does.
1414

15-
*git* is a humongous project with years of development by thousands of contributors, making it challenging for *go-git* implement all the features. You can find a comparison of *go-git* vs *git* in the [compatibility documentation](COMPATIBILITY.md).
15+
*git* is a humongous project with years of development by thousands of contributors, making it challenging for *go-git* to implement all the features. You can find a comparison of *go-git* vs *git* in the [compatibility documentation](COMPATIBILITY.md).
1616

1717

1818
Installation
@@ -24,12 +24,12 @@ The recommended way to install *go-git* is:
2424
go get -u gopkg.in/src-d/go-git.v4/...
2525
```
2626

27-
> We use [gopkg.in](http://labix.org/gopkg.in) for having a versioned API, this means that when `go get` clones the package, is the latest tag matching `v4.*` cloned and not the master branch.
27+
> We use [gopkg.in](http://labix.org/gopkg.in) to version the API, this means that when `go get` clones the package, it's the latest tag matching `v4.*` that is cloned and not the master branch.
2828
2929
Examples
3030
--------
3131

32-
> Please note that the functions `CheckIfError` and `Info` used in the examples are from the [examples package](https://github.com/src-d/go-git/blob/master/_examples/common.go#L17) just to be used in the examples.
32+
> Please note that the `CheckIfError` and `Info` functions used in the examples are from the [examples package](https://github.com/src-d/go-git/blob/master/_examples/common.go#L17) just to be used in the examples.
3333
3434

3535
### Basic example
@@ -71,7 +71,7 @@ r, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
7171

7272
CheckIfError(err)
7373

74-
// Gets the HEAD history from HEAD, just like does:
74+
// Gets the HEAD history from HEAD, just like this command:
7575
Info("git log")
7676

7777
// ... retrieves the branch pointed by HEAD
@@ -110,7 +110,7 @@ Date: Fri Nov 11 13:23:22 2016 +0100
110110
...
111111
```
112112

113-
You can find this [example](_examples/log/main.go) and many others at the [examples](_examples) folder
113+
You can find this [example](_examples/log/main.go) and many others in the [examples](_examples) folder.
114114

115115
Contribute
116116
----------

_examples/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Here you can find a list of annotated _go-git_ examples:
66
- [showcase](showcase/main.go) - A small showcase of the capabilities of _go-git_
77
- [open](open/main.go) - Opening a existing repository cloned by _git_
88
- [clone](clone/main.go) - Cloning a repository
9+
- [username and password](clone/auth/basic/username_password/main.go) - Cloning a repository
10+
using a username and password
11+
- [personal access token](clone/auth/basic/access_token/main.go) - Cloning
12+
a repository using a GitHub personal access token
913
- [commit](commit/main.go) - Commit changes to the current branch to an existent repository
1014
- [push](push/main.go) - Push repository to default remote (origin)
1115
- [pull](pull/main.go) - Pull changes from a remote repository

_examples/checkout/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ func main() {
3838
})
3939
CheckIfError(err)
4040

41-
// ... retrieving the commit being pointed by HEAD, it's shows that the
42-
// repository is poiting to the giving commit in detached mode
41+
// ... retrieving the commit being pointed by HEAD, it shows that the
42+
// repository is pointing to the giving commit in detached mode
4343
Info("git show-ref --head HEAD")
4444
ref, err = r.Head()
4545
CheckIfError(err)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
git "gopkg.in/src-d/go-git.v4"
8+
. "gopkg.in/src-d/go-git.v4/_examples"
9+
"gopkg.in/src-d/go-git.v4/plumbing/transport/http"
10+
)
11+
12+
func main() {
13+
CheckArgs("<url>", "<directory>", "<github_access_token>")
14+
url, directory, token := os.Args[1], os.Args[2], os.Args[3]
15+
16+
// Clone the given repository to the given directory
17+
Info("git clone %s %s", url, directory)
18+
19+
r, err := git.PlainClone(directory, false, &git.CloneOptions{
20+
// The intended use of a GitHub personal access token is in replace of your password
21+
// because access tokens can easily be revoked.
22+
// https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
23+
Auth: &http.BasicAuth{
24+
Username: "abc123", // yes, this can be anything except an empty string
25+
Password: token,
26+
},
27+
URL: url,
28+
Progress: os.Stdout,
29+
})
30+
CheckIfError(err)
31+
32+
// ... retrieving the branch being pointed by HEAD
33+
ref, err := r.Head()
34+
CheckIfError(err)
35+
// ... retrieving the commit object
36+
commit, err := r.CommitObject(ref.Hash())
37+
CheckIfError(err)
38+
39+
fmt.Println(commit)
40+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
git "gopkg.in/src-d/go-git.v4"
8+
. "gopkg.in/src-d/go-git.v4/_examples"
9+
"gopkg.in/src-d/go-git.v4/plumbing/transport/http"
10+
)
11+
12+
func main() {
13+
CheckArgs("<url>", "<directory>", "<github_username>", "<github_password>")
14+
url, directory, username, password := os.Args[1], os.Args[2], os.Args[3], os.Args[4]
15+
16+
// Clone the given repository to the given directory
17+
Info("git clone %s %s", url, directory)
18+
19+
r, err := git.PlainClone(directory, false, &git.CloneOptions{
20+
Auth: &http.BasicAuth{
21+
Username: username,
22+
Password: password,
23+
},
24+
URL: url,
25+
Progress: os.Stdout,
26+
})
27+
CheckIfError(err)
28+
29+
// ... retrieving the branch being pointed by HEAD
30+
ref, err := r.Head()
31+
CheckIfError(err)
32+
// ... retrieving the commit object
33+
commit, err := r.CommitObject(ref.Hash())
34+
CheckIfError(err)
35+
36+
fmt.Println(commit)
37+
}

_examples/commit/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import (
1212
"gopkg.in/src-d/go-git.v4/plumbing/object"
1313
)
1414

15-
// Basic example of how to commit changes to the current branch to an existent
15+
// Basic example of how to commit changes to the current branch to an existing
1616
// repository.
1717
func main() {
1818
CheckArgs("<directory>")
1919
directory := os.Args[1]
2020

21-
// Opens an already existent repository.
21+
// Opens an already existing repository.
2222
r, err := git.PlainOpen(directory)
2323
CheckIfError(err)
2424

@@ -44,7 +44,7 @@ func main() {
4444

4545
fmt.Println(status)
4646

47-
// Commits the current staging are to the repository, with the new file
47+
// Commits the current staging area to the repository, with the new file
4848
// just created. We should provide the object.Signature of Author of the
4949
// commit.
5050
Info("git commit -m \"example go-git commit\"")

_examples/log/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func main() {
2323
})
2424
CheckIfError(err)
2525

26-
// Gets the HEAD history from HEAD, just like does:
26+
// Gets the HEAD history from HEAD, just like this command:
2727
Info("git log")
2828

2929
// ... retrieves the branch pointed by HEAD

_examples/open/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func main() {
1414
CheckArgs("<path>")
1515
path := os.Args[1]
1616

17-
// We instance a new repository targeting the given path (the .git folder)
17+
// We instanciate a new repository targeting the given path (the .git folder)
1818
r, err := git.PlainOpen(path)
1919
CheckIfError(err)
2020

0 commit comments

Comments
 (0)