6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 20:19:42 +00:00

Add cobra commands and update project folder structure

This commit is contained in:
Grzegorz Dlugoszewski
2020-05-20 11:37:16 +02:00
parent 4b8b1d52f0
commit ac765c9c06
12 changed files with 196 additions and 30 deletions

41
pkg/repo.go Normal file
View File

@@ -0,0 +1,41 @@
package pkg
import (
"github.com/pkg/errors"
git "github.com/libgit2/git2go/v30"
)
func CloneRepo(url string, path string) (*git.Repository, error) {
options := &git.CloneOptions{
CheckoutOpts: nil,
FetchOptions: nil,
Bare: false,
CheckoutBranch: "",
RemoteCreateCallback: nil,
}
repo, err := git.Clone(url, path, options)
return repo, errors.Wrap(err, "Failed cloning repo")
}
func Fetch(repo *git.Repository) error {
remotes, err := repo.Remotes.List()
if err != nil {
return errors.Wrap(err, "Failed listing remotes")
}
for _, r := range remotes {
remote, err := repo.Remotes.Lookup(r)
if err != nil {
return errors.Wrap(err, "Failed looking up remote")
}
err = remote.Fetch(nil, nil, "")
if err != nil {
return errors.Wrap(err, "Failed fetching remote")
}
}
return nil
}