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:
41
new/repo.go
41
new/repo.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user