@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- package v1
17+ package gogit
1818
1919import (
2020 "context"
@@ -23,51 +23,52 @@ import (
2323 "time"
2424
2525 "github.com/Masterminds/semver/v3"
26- "github.com/go-git/go-git/v5"
26+ extgogit "github.com/go-git/go-git/v5"
2727 "github.com/go-git/go-git/v5/plumbing"
2828
2929 "github.com/fluxcd/pkg/version"
30+
3031 sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
31- "github.com/fluxcd/source-controller/pkg/git/common "
32+ "github.com/fluxcd/source-controller/pkg/git"
3233)
3334
34- func CheckoutStrategyForRef (ref * sourcev1.GitRepositoryRef ) common .CheckoutStrategy {
35+ func CheckoutStrategyForRef (ref * sourcev1.GitRepositoryRef ) git .CheckoutStrategy {
3536 switch {
3637 case ref == nil :
37- return & CheckoutBranch {branch : common .DefaultBranch }
38+ return & CheckoutBranch {branch : git .DefaultBranch }
3839 case ref .SemVer != "" :
3940 return & CheckoutSemVer {semVer : ref .SemVer }
4041 case ref .Tag != "" :
4142 return & CheckoutTag {tag : ref .Tag }
4243 case ref .Commit != "" :
4344 strategy := & CheckoutCommit {branch : ref .Branch , commit : ref .Commit }
4445 if strategy .branch == "" {
45- strategy .branch = common .DefaultBranch
46+ strategy .branch = git .DefaultBranch
4647 }
4748 return strategy
4849 case ref .Branch != "" :
4950 return & CheckoutBranch {branch : ref .Branch }
5051 default :
51- return & CheckoutBranch {branch : common .DefaultBranch }
52+ return & CheckoutBranch {branch : git .DefaultBranch }
5253 }
5354}
5455
5556type CheckoutBranch struct {
5657 branch string
5758}
5859
59- func (c * CheckoutBranch ) Checkout (ctx context.Context , path , url string , auth * common .Auth ) (common .Commit , string , error ) {
60- repo , err := git .PlainCloneContext (ctx , path , false , & git .CloneOptions {
60+ func (c * CheckoutBranch ) Checkout (ctx context.Context , path , url string , auth * git .Auth ) (git .Commit , string , error ) {
61+ repo , err := extgogit .PlainCloneContext (ctx , path , false , & extgogit .CloneOptions {
6162 URL : url ,
6263 Auth : auth .AuthMethod ,
63- RemoteName : common .DefaultOrigin ,
64+ RemoteName : git .DefaultOrigin ,
6465 ReferenceName : plumbing .NewBranchReferenceName (c .branch ),
6566 SingleBranch : true ,
6667 NoCheckout : false ,
6768 Depth : 1 ,
6869 RecurseSubmodules : 0 ,
6970 Progress : nil ,
70- Tags : git .NoTags ,
71+ Tags : extgogit .NoTags ,
7172 })
7273 if err != nil {
7374 return nil , "" , fmt .Errorf ("unable to clone '%s', error: %w" , url , err )
@@ -87,18 +88,18 @@ type CheckoutTag struct {
8788 tag string
8889}
8990
90- func (c * CheckoutTag ) Checkout (ctx context.Context , path , url string , auth * common .Auth ) (common .Commit , string , error ) {
91- repo , err := git .PlainCloneContext (ctx , path , false , & git .CloneOptions {
91+ func (c * CheckoutTag ) Checkout (ctx context.Context , path , url string , auth * git .Auth ) (git .Commit , string , error ) {
92+ repo , err := extgogit .PlainCloneContext (ctx , path , false , & extgogit .CloneOptions {
9293 URL : url ,
9394 Auth : auth .AuthMethod ,
94- RemoteName : common .DefaultOrigin ,
95+ RemoteName : git .DefaultOrigin ,
9596 ReferenceName : plumbing .NewTagReferenceName (c .tag ),
9697 SingleBranch : true ,
9798 NoCheckout : false ,
9899 Depth : 1 ,
99100 RecurseSubmodules : 0 ,
100101 Progress : nil ,
101- Tags : git .NoTags ,
102+ Tags : extgogit .NoTags ,
102103 })
103104 if err != nil {
104105 return nil , "" , fmt .Errorf ("unable to clone '%s', error: %w" , url , err )
@@ -119,17 +120,17 @@ type CheckoutCommit struct {
119120 commit string
120121}
121122
122- func (c * CheckoutCommit ) Checkout (ctx context.Context , path , url string , auth * common .Auth ) (common .Commit , string , error ) {
123- repo , err := git .PlainCloneContext (ctx , path , false , & git .CloneOptions {
123+ func (c * CheckoutCommit ) Checkout (ctx context.Context , path , url string , auth * git .Auth ) (git .Commit , string , error ) {
124+ repo , err := extgogit .PlainCloneContext (ctx , path , false , & extgogit .CloneOptions {
124125 URL : url ,
125126 Auth : auth .AuthMethod ,
126- RemoteName : common .DefaultOrigin ,
127+ RemoteName : git .DefaultOrigin ,
127128 ReferenceName : plumbing .NewBranchReferenceName (c .branch ),
128129 SingleBranch : true ,
129130 NoCheckout : false ,
130131 RecurseSubmodules : 0 ,
131132 Progress : nil ,
132- Tags : git .NoTags ,
133+ Tags : extgogit .NoTags ,
133134 })
134135 if err != nil {
135136 return nil , "" , fmt .Errorf ("unable to clone '%s', error: %w" , url , err )
@@ -142,7 +143,7 @@ func (c *CheckoutCommit) Checkout(ctx context.Context, path, url string, auth *c
142143 if err != nil {
143144 return nil , "" , fmt .Errorf ("git commit '%s' not found: %w" , c .commit , err )
144145 }
145- err = w .Checkout (& git .CheckoutOptions {
146+ err = w .Checkout (& extgogit .CheckoutOptions {
146147 Hash : commit .Hash ,
147148 Force : true ,
148149 })
@@ -156,21 +157,21 @@ type CheckoutSemVer struct {
156157 semVer string
157158}
158159
159- func (c * CheckoutSemVer ) Checkout (ctx context.Context , path , url string , auth * common .Auth ) (common .Commit , string , error ) {
160+ func (c * CheckoutSemVer ) Checkout (ctx context.Context , path , url string , auth * git .Auth ) (git .Commit , string , error ) {
160161 verConstraint , err := semver .NewConstraint (c .semVer )
161162 if err != nil {
162163 return nil , "" , fmt .Errorf ("semver parse range error: %w" , err )
163164 }
164165
165- repo , err := git .PlainCloneContext (ctx , path , false , & git .CloneOptions {
166+ repo , err := extgogit .PlainCloneContext (ctx , path , false , & extgogit .CloneOptions {
166167 URL : url ,
167168 Auth : auth .AuthMethod ,
168- RemoteName : common .DefaultOrigin ,
169+ RemoteName : git .DefaultOrigin ,
169170 NoCheckout : false ,
170171 Depth : 1 ,
171172 RecurseSubmodules : 0 ,
172173 Progress : nil ,
173- Tags : git .AllTags ,
174+ Tags : extgogit .AllTags ,
174175 })
175176 if err != nil {
176177 return nil , "" , fmt .Errorf ("unable to clone '%s', error: %w" , url , err )
@@ -237,7 +238,7 @@ func (c *CheckoutSemVer) Checkout(ctx context.Context, path, url string, auth *c
237238 return nil , "" , fmt .Errorf ("git worktree error: %w" , err )
238239 }
239240
240- err = w .Checkout (& git .CheckoutOptions {
241+ err = w .Checkout (& extgogit .CheckoutOptions {
241242 Branch : plumbing .NewTagReferenceName (t ),
242243 })
243244 if err != nil {
0 commit comments