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