Add ~depth parameter to git clone options
This commit is contained in:
parent
b910fe826e
commit
a0fcc46718
|
@ -29,6 +29,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
|
@ -69,12 +70,15 @@ func Get(ctx context.Context, opts GetOptions) error {
|
||||||
tag := query.Get("~tag")
|
tag := query.Get("~tag")
|
||||||
query.Del("~tag")
|
query.Del("~tag")
|
||||||
|
|
||||||
branch := src.Query().Get("~branch")
|
branch := query.Get("~branch")
|
||||||
query.Del("~branch")
|
query.Del("~branch")
|
||||||
|
|
||||||
commit := src.Query().Get("~commit")
|
commit := query.Get("~commit")
|
||||||
query.Del("~commit")
|
query.Del("~commit")
|
||||||
|
|
||||||
|
depth := query.Get("~depth")
|
||||||
|
query.Del("~depth")
|
||||||
|
|
||||||
var refName plumbing.ReferenceName
|
var refName plumbing.ReferenceName
|
||||||
if tag != "" {
|
if tag != "" {
|
||||||
refName = plumbing.NewTagReferenceName(tag)
|
refName = plumbing.NewTagReferenceName(tag)
|
||||||
|
@ -94,10 +98,21 @@ func Get(ctx context.Context, opts GetOptions) error {
|
||||||
dstDir = filepath.Join(opts.Destination, name)
|
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(),
|
URL: src.String(),
|
||||||
Progress: os.Stderr,
|
Progress: os.Stderr,
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if depth != 0 {
|
||||||
|
cloneOpts.Depth = depth
|
||||||
|
}
|
||||||
|
|
||||||
|
repo, err := git.PlainCloneContext(ctx, dstDir, false, cloneOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue