6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-11 19:18:58 +00:00

Refactor Clone method to use go-git

This commit is contained in:
Grzegorz Dlugoszewski
2020-05-27 12:54:49 +02:00
parent 616b476ce1
commit b94e655d4a
5 changed files with 99 additions and 19 deletions

View File

@@ -1,8 +1,47 @@
package new
import "github.com/go-git/go-git/v5"
import (
"os"
"github.com/go-git/go-git/v5/plumbing/cache"
"github.com/go-git/go-git/v5/storage/filesystem"
"github.com/pkg/errors"
"github.com/go-git/go-billy/v5"
"github.com/go-git/go-git/v5"
)
type Repo struct {
repo *git.Repository
Status *RepoStatus
}
func CloneRepo(url string, path billy.Filesystem) (r *Repo, err error) {
opts := &git.CloneOptions{
URL: url,
Auth: nil,
RemoteName: git.DefaultRemoteName,
ReferenceName: "",
SingleBranch: false,
NoCheckout: false,
Depth: 0,
RecurseSubmodules: git.NoRecurseSubmodules,
Progress: os.Stdout,
Tags: git.AllTags,
}
dotgit, _ := path.Chroot(git.GitDirName)
s := filesystem.NewStorage(dotgit, cache.NewObjectLRUDefault())
repo, err := git.Clone(s, path, opts)
if err != nil {
return nil, errors.Wrap(err, "Failed cloning repo")
}
r = &Repo{
repo: repo,
}
return r, nil
}