1
0
Fork 0
mirror of https://github.com/Luzifer/ansible-role-version.git synced 2024-12-25 12:01:21 +00:00
ansible-role-version/vendor/gopkg.in/src-d/go-git.v4/_examples/pull/main.go

37 lines
785 B
Go
Raw Normal View History

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)
}