Skip to content

Commit e0ab141

Browse files
committed
Add partial clone test
1 parent 3ecbf01 commit e0ab141

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

integrations/git_helper_for_declarative_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
122122
}
123123
}
124124

125+
func doPartialGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
126+
return func(t *testing.T) {
127+
assert.NoError(t, git.CloneWithArgs(context.Background(), u.String(), dstLocalPath, allowLFSFilters(), git.CloneRepoOptions{
128+
Filter: "blob:none",
129+
}))
130+
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
131+
assert.NoError(t, err)
132+
assert.True(t, exist)
133+
}
134+
}
135+
125136
func doGitCloneFail(u *url.URL) func(*testing.T) {
126137
return func(t *testing.T) {
127138
tmpDir, err := os.MkdirTemp("", "doGitCloneFail")

integrations/git_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ func testGit(t *testing.T, u *url.URL) {
6969

7070
t.Run("Clone", doGitClone(dstPath, u))
7171

72+
dstPath2, err := os.MkdirTemp("", httpContext.Reponame)
73+
assert.NoError(t, err)
74+
defer util.RemoveAll(dstPath2)
75+
76+
t.Run("Partial Clone", doPartialGitClone(dstPath2, u))
77+
7278
little, big := standardCommitAndPushTest(t, dstPath)
7379
littleLFS, bigLFS := lfsCommitAndPushTest(t, dstPath)
7480
rawTest(t, &httpContext, little, big, littleLFS, bigLFS)

modules/git/repo.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ type CloneRepoOptions struct {
101101
Shared bool
102102
NoCheckout bool
103103
Depth int
104+
Filter string
104105
}
105106

106107
// Clone clones original repository to target path.
@@ -136,7 +137,9 @@ func CloneWithArgs(ctx context.Context, from, to string, args []string, opts Clo
136137
if opts.Depth > 0 {
137138
cmd.AddArguments("--depth", strconv.Itoa(opts.Depth))
138139
}
139-
140+
if opts.Filter != "" {
141+
cmd.AddArguments("--filter", opts.Filter)
142+
}
140143
if len(opts.Branch) > 0 {
141144
cmd.AddArguments("-b", opts.Branch)
142145
}

0 commit comments

Comments
 (0)