@@ -33,29 +33,30 @@ import (
3333 "github.com/fluxcd/source-controller/pkg/git"
3434)
3535
36- func CheckoutStrategyForRef (ref * sourcev1.GitRepositoryRef ) git.CheckoutStrategy {
36+ func CheckoutStrategyForRef (ref * sourcev1.GitRepositoryRef , opt git. CheckoutOptions ) git.CheckoutStrategy {
3737 switch {
3838 case ref == nil :
3939 return & CheckoutBranch {branch : git .DefaultBranch }
4040 case ref .SemVer != "" :
41- return & CheckoutSemVer {semVer : ref .SemVer }
41+ return & CheckoutSemVer {semVer : ref .SemVer , recurseSubmodules : opt . RecurseSubmodules }
4242 case ref .Tag != "" :
43- return & CheckoutTag {tag : ref .Tag }
43+ return & CheckoutTag {tag : ref .Tag , recurseSubmodules : opt . RecurseSubmodules }
4444 case ref .Commit != "" :
45- strategy := & CheckoutCommit {branch : ref .Branch , commit : ref .Commit }
45+ strategy := & CheckoutCommit {branch : ref .Branch , commit : ref .Commit , recurseSubmodules : opt . RecurseSubmodules }
4646 if strategy .branch == "" {
4747 strategy .branch = git .DefaultBranch
4848 }
4949 return strategy
5050 case ref .Branch != "" :
51- return & CheckoutBranch {branch : ref .Branch }
51+ return & CheckoutBranch {branch : ref .Branch , recurseSubmodules : opt . RecurseSubmodules }
5252 default :
5353 return & CheckoutBranch {branch : git .DefaultBranch }
5454 }
5555}
5656
5757type CheckoutBranch struct {
58- branch string
58+ branch string
59+ recurseSubmodules bool
5960}
6061
6162func (c * CheckoutBranch ) Checkout (ctx context.Context , path , url string , auth * git.Auth ) (git.Commit , string , error ) {
@@ -67,7 +68,7 @@ func (c *CheckoutBranch) Checkout(ctx context.Context, path, url string, auth *g
6768 SingleBranch : true ,
6869 NoCheckout : false ,
6970 Depth : 1 ,
70- RecurseSubmodules : extgogit . DefaultSubmoduleRecursionDepth ,
71+ RecurseSubmodules : recurseSubmodules ( c . recurseSubmodules ) ,
7172 Progress : nil ,
7273 Tags : extgogit .NoTags ,
7374 CABundle : auth .CABundle ,
@@ -87,7 +88,8 @@ func (c *CheckoutBranch) Checkout(ctx context.Context, path, url string, auth *g
8788}
8889
8990type CheckoutTag struct {
90- tag string
91+ tag string
92+ recurseSubmodules bool
9193}
9294
9395func (c * CheckoutTag ) Checkout (ctx context.Context , path , url string , auth * git.Auth ) (git.Commit , string , error ) {
@@ -99,7 +101,7 @@ func (c *CheckoutTag) Checkout(ctx context.Context, path, url string, auth *git.
99101 SingleBranch : true ,
100102 NoCheckout : false ,
101103 Depth : 1 ,
102- RecurseSubmodules : extgogit . DefaultSubmoduleRecursionDepth ,
104+ RecurseSubmodules : recurseSubmodules ( c . recurseSubmodules ) ,
103105 Progress : nil ,
104106 Tags : extgogit .NoTags ,
105107 CABundle : auth .CABundle ,
@@ -119,8 +121,9 @@ func (c *CheckoutTag) Checkout(ctx context.Context, path, url string, auth *git.
119121}
120122
121123type CheckoutCommit struct {
122- branch string
123- commit string
124+ branch string
125+ commit string
126+ recurseSubmodules bool
124127}
125128
126129func (c * CheckoutCommit ) Checkout (ctx context.Context , path , url string , auth * git.Auth ) (git.Commit , string , error ) {
@@ -131,7 +134,7 @@ func (c *CheckoutCommit) Checkout(ctx context.Context, path, url string, auth *g
131134 ReferenceName : plumbing .NewBranchReferenceName (c .branch ),
132135 SingleBranch : true ,
133136 NoCheckout : false ,
134- RecurseSubmodules : extgogit . DefaultSubmoduleRecursionDepth ,
137+ RecurseSubmodules : recurseSubmodules ( c . recurseSubmodules ) ,
135138 Progress : nil ,
136139 Tags : extgogit .NoTags ,
137140 CABundle : auth .CABundle ,
@@ -158,7 +161,8 @@ func (c *CheckoutCommit) Checkout(ctx context.Context, path, url string, auth *g
158161}
159162
160163type CheckoutSemVer struct {
161- semVer string
164+ semVer string
165+ recurseSubmodules bool
162166}
163167
164168func (c * CheckoutSemVer ) Checkout (ctx context.Context , path , url string , auth * git.Auth ) (git.Commit , string , error ) {
@@ -173,7 +177,7 @@ func (c *CheckoutSemVer) Checkout(ctx context.Context, path, url string, auth *g
173177 RemoteName : git .DefaultOrigin ,
174178 NoCheckout : false ,
175179 Depth : 1 ,
176- RecurseSubmodules : extgogit . DefaultSubmoduleRecursionDepth ,
180+ RecurseSubmodules : recurseSubmodules ( c . recurseSubmodules ) ,
177181 Progress : nil ,
178182 Tags : extgogit .AllTags ,
179183 CABundle : auth .CABundle ,
@@ -262,3 +266,10 @@ func (c *CheckoutSemVer) Checkout(ctx context.Context, path, url string, auth *g
262266
263267 return & Commit {commit }, fmt .Sprintf ("%s/%s" , t , head .Hash ().String ()), nil
264268}
269+
270+ func recurseSubmodules (recurse bool ) extgogit.SubmoduleRescursivity {
271+ if recurse {
272+ return extgogit .DefaultSubmoduleRecursionDepth
273+ }
274+ return extgogit .NoRecurseSubmodules
275+ }
0 commit comments