@@ -222,13 +222,14 @@ func TestSourceManager_CheckoutSource(t *testing.T) {
222222
223223func test_sourceManager_CheckoutSource (t * testing.T , proto string ) {
224224 tests := []struct {
225- name string
226- autoGitSpec * imagev1.GitSpec
227- gitRepoRef * sourcev1.GitRepositoryRef
228- shallowClone bool
229- lastObserved bool
230- wantErr bool
231- wantRef string
225+ name string
226+ autoGitSpec * imagev1.GitSpec
227+ gitRepoRef * sourcev1.GitRepositoryRef
228+ shallowClone bool
229+ sparseCheckoutDirectory string
230+ lastObserved bool
231+ wantErr bool
232+ wantRef string
232233 }{
233234 {
234235 name : "checkout for single branch" ,
@@ -275,6 +276,42 @@ func test_sourceManager_CheckoutSource(t *testing.T, proto string) {
275276 wantErr : false ,
276277 wantRef : "main" ,
277278 },
279+ {
280+ name : "with sparse checkout" ,
281+ autoGitSpec : & imagev1.GitSpec {
282+ Push : & imagev1.PushSpec {Branch : "main" },
283+ Checkout : & imagev1.GitCheckoutSpec {
284+ Reference : sourcev1.GitRepositoryRef {Branch : "main" },
285+ },
286+ },
287+ sparseCheckoutDirectory : "testdata/appconfig/deploy.yaml" ,
288+ wantErr : false ,
289+ wantRef : "main" ,
290+ },
291+ {
292+ name : "with sparse checkout for current directory" ,
293+ autoGitSpec : & imagev1.GitSpec {
294+ Push : & imagev1.PushSpec {Branch : "main" },
295+ Checkout : & imagev1.GitCheckoutSpec {
296+ Reference : sourcev1.GitRepositoryRef {Branch : "main" },
297+ },
298+ },
299+ sparseCheckoutDirectory : "./" ,
300+ wantErr : false ,
301+ wantRef : "main" ,
302+ },
303+ {
304+ name : "with sparse checkout for different push branch" ,
305+ autoGitSpec : & imagev1.GitSpec {
306+ Push : & imagev1.PushSpec {Branch : "foo" },
307+ Checkout : & imagev1.GitCheckoutSpec {
308+ Reference : sourcev1.GitRepositoryRef {Branch : "main" },
309+ },
310+ },
311+ sparseCheckoutDirectory : "testdata/appconfig/deploy.yaml" ,
312+ wantErr : false ,
313+ wantRef : "foo" ,
314+ },
278315 {
279316 name : "with last observed commit" ,
280317 autoGitSpec : & imagev1.GitSpec {
@@ -386,6 +423,9 @@ func test_sourceManager_CheckoutSource(t *testing.T, proto string) {
386423 if tt .shallowClone {
387424 opts = append (opts , WithCheckoutOptionShallowClone ())
388425 }
426+ if tt .sparseCheckoutDirectory != "" {
427+ opts = append (opts , WithCheckoutOptionSparseCheckoutDirectories (tt .sparseCheckoutDirectory ))
428+ }
389429 if tt .lastObserved {
390430 opts = append (opts , WithCheckoutOptionLastObserved (headRev ))
391431 }
0 commit comments