From a655d1d81f76cf652d3fb739834b85414f766ba6 Mon Sep 17 00:00:00 2001 From: Ray Shirohara Date: Sun, 9 Mar 2025 23:56:09 +0900 Subject: [PATCH] feat: add `partial` option support to `GitBackend` --- commands_test.go | 2 ++ vcs.go | 7 ++++++- vcs_test.go | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/commands_test.go b/commands_test.go index 7c4315f..062a7ab 100644 --- a/commands_test.go +++ b/commands_test.go @@ -15,6 +15,7 @@ type _cloneArgs struct { recursive bool bare bool silent bool + partial string } type _updateArgs struct { @@ -41,6 +42,7 @@ func withFakeGitBackend(t *testing.T, block func(*testing.T, string, *_cloneArgs recursive: vg.recursive, bare: vg.bare, silent: vg.silent, + partial: vg.partial, } return nil }, diff --git a/vcs.go b/vcs.go index c075c92..dd2a1a2 100644 --- a/vcs.go +++ b/vcs.go @@ -44,7 +44,7 @@ type vcsGetOption struct { url *url.URL dir string recursive, shallow, silent, bare bool - branch string + branch, partial string } // GitBackend is the VCSBackend of git @@ -70,6 +70,11 @@ var GitBackend = &VCSBackend{ if vg.bare { args = append(args, "--bare") } + if vg.partial == "blobless" { + args = append(args, "--filter=blob:none") + } else if vg.partial == "treeless" { + args = append(args, "--filter=tree:0") + } args = append(args, vg.url.String(), vg.dir) return run(vg.silent)("git", args...) diff --git a/vcs_test.go b/vcs_test.go index 72e1c1d..00080dc 100644 --- a/vcs_test.go +++ b/vcs_test.go @@ -136,6 +136,26 @@ func TestVCSBackend(t *testing.T) { }) }, expect: []string{"git", "clone", "--bare", remoteDummyURL.String(), localDir}, + }, { + name: "[git] (partial) blobless clone", + f: func() error { + return GitBackend.Clone(&vcsGetOption{ + url: remoteDummyURL, + dir: localDir, + partial: "blobless", + }) + }, + expect: []string{"git", "clone", "--filter=blob:none", remoteDummyURL.String(), localDir}, + }, { + name: "[git] (partial) treeless clone", + f: func() error { + return GitBackend.Clone(&vcsGetOption{ + url: remoteDummyURL, + dir: localDir, + partial: "treeless", + }) + }, + expect: []string{"git", "clone", "--filter=tree:0", remoteDummyURL.String(), localDir}, }, { name: "[git] switch git-svn on update", f: func() error {