6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-07 04:55:38 +00:00
Files
git-get/new/repo.go
2020-05-27 13:02:06 +02:00

54 lines
1.0 KiB
Go

package new
import (
"io"
"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, quiet bool) (r *Repo, err error) {
var output io.Writer
if !quiet {
output = os.Stdout
}
opts := &git.CloneOptions{
URL: url,
Auth: nil,
RemoteName: git.DefaultRemoteName,
ReferenceName: "",
SingleBranch: false,
NoCheckout: false,
Depth: 0,
RecurseSubmodules: git.NoRecurseSubmodules,
Progress: output,
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
}