| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"os" |
| 6 |
|
| 7 |
"gopkg.in/src-d/go-git.v4" |
| 8 |
. "gopkg.in/src-d/go-git.v4/_examples" |
| 9 |
) |
| 10 |
|
| 11 |
// Pull changes from a remote repository |
| 12 |
func main() { |
| 13 |
CheckArgs("<path>") |
| 14 |
path := os.Args[1] |
| 15 |
|
| 16 |
// We instance\iate a new repository targeting the given path (the .git folder) |
| 17 |
r, err := git.PlainOpen(path) |
| 18 |
CheckIfError(err) |
| 19 |
|
| 20 |
// Get the working directory for the repository |
| 21 |
w, err := r.Worktree() |
| 22 |
CheckIfError(err) |
| 23 |
|
| 24 |
// Pull the latest changes from the origin remote and merge into the current branch |
| 25 |
Info("git pull origin") |
| 26 |
err = w.Pull(&git.PullOptions{RemoteName: "origin"}) |
| 27 |
CheckIfError(err) |
| 28 |
|
| 29 |
// Print the latest commit that was just pulled |
| 30 |
ref, err := r.Head() |
| 31 |
CheckIfError(err) |
| 32 |
commit, err := r.CommitObject(ref.Hash()) |
| 33 |
CheckIfError(err) |
| 34 |
|
| 35 |
fmt.Println(commit) |
| 36 |
} |