From a0fcc46718ca6f80484f4094e803340fd57187ab Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Mon, 26 Sep 2022 14:01:33 -0700 Subject: [PATCH] Add ~depth parameter to git clone options --- download/download.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/download/download.go b/download/download.go index 65e0364..dd58bb7 100644 --- a/download/download.go +++ b/download/download.go @@ -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 }