Add ~depth parameter to git clone options

This commit is contained in:
Elara 2022-09-26 14:01:33 -07:00
parent b910fe826e
commit a0fcc46718
1 changed files with 19 additions and 4 deletions

View File

@ -29,6 +29,7 @@ import (
"os"
"path"
"path/filepath"
"strconv"
"strings"
"github.com/go-git/go-git/v5"
@ -69,12 +70,15 @@ func Get(ctx context.Context, opts GetOptions) error {
tag := query.Get("~tag")
query.Del("~tag")
branch := src.Query().Get("~branch")
branch := query.Get("~branch")
query.Del("~branch")
commit := src.Query().Get("~commit")
commit := query.Get("~commit")
query.Del("~commit")
depth := query.Get("~depth")
query.Del("~depth")
var refName plumbing.ReferenceName
if tag != "" {
refName = plumbing.NewTagReferenceName(tag)
@ -94,10 +98,21 @@ func Get(ctx context.Context, opts GetOptions) error {
dstDir = filepath.Join(opts.Destination, name)
}
repo, err := git.PlainCloneContext(ctx, dstDir, false, &git.CloneOptions{
depth, err := strconv.Atoi(depth)
if err != nil {
return err
}
cloneOpts := &git.CloneOptions{
URL: src.String(),
Progress: os.Stderr,
})
}
if depth != 0 {
cloneOpts.Depth = depth
}
repo, err := git.PlainCloneContext(ctx, dstDir, false, cloneOpts)
if err != nil {
return err
}