Sajith Silva Sajith Silva - 1 year ago 166
Git Question

golang git pulling a repo

I'm very new to golang
Im trying to do a git pull from go program. I have looked in to native libraries and found https://github.com/src-d/go-git/.

I has features to of cloning ect. but not pulling. Looking at the source it seems there is a function for pulling as well

func (r *Repository) Pull(o *PullOptions)


However compiler warns that its undefined. Can anyone point me how can I do this or to an alternative library which supports both clone and pull ?

Answer Source

You should create a Repository struct by cloning a repo:

import {
  git "github.com/src-d/go-git"
}

repo, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
    URL: "https://github.com/src-d/go-siva",
})

And then on the repo struct call Pull.

err := repo.Pull(&git.PullOptions{
    RemoteName: "origin"
})

You cannot call git.Pull directly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download