feat: add partial option support to GitBackend

This commit is contained in:
Ray Shirohara 2025-03-09 23:56:09 +09:00
parent ed4b406086
commit a655d1d81f
No known key found for this signature in database
GPG key ID: A0ED68AB35B8627F
3 changed files with 28 additions and 1 deletions

View file

@ -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
},

7
vcs.go
View file

@ -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...)

View file

@ -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 {