From 7e63ef841caf400801eff28698e740fccb5016d9 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Thu, 28 Jan 2021 11:55:45 +0100 Subject: [PATCH] Rename Git packages to implementations Signed-off-by: Hidde Beydals --- api/v1beta1/gitrepository_types.go | 5 +++-- pkg/git/git.go | 16 ++++++---------- pkg/git/{v1 => gogit}/checkout.go | 3 ++- pkg/git/{v1 => gogit}/checkout_test.go | 2 +- pkg/git/{v1 => gogit}/commit.go | 2 +- pkg/git/{v1 => gogit}/transport.go | 3 ++- pkg/git/{v1 => gogit}/transport_test.go | 2 +- pkg/git/{v2 => libgit2}/checkout.go | 2 +- pkg/git/{v2 => libgit2}/checkout_test.go | 2 +- pkg/git/{v2 => libgit2}/commit.go | 5 +++-- pkg/git/{v2 => libgit2}/transport.go | 5 +++-- pkg/git/{v2 => libgit2}/transport_test.go | 2 +- 12 files changed, 25 insertions(+), 24 deletions(-) rename pkg/git/{v1 => gogit}/checkout.go (99%) rename pkg/git/{v1 => gogit}/checkout_test.go (99%) rename pkg/git/{v1 => gogit}/commit.go (98%) rename pkg/git/{v1 => gogit}/transport.go (99%) rename pkg/git/{v1 => gogit}/transport_test.go (99%) rename pkg/git/{v2 => libgit2}/checkout.go (99%) rename pkg/git/{v2 => libgit2}/checkout_test.go (98%) rename pkg/git/{v2 => libgit2}/commit.go (98%) rename pkg/git/{v2 => libgit2}/transport.go (99%) rename pkg/git/{v2 => libgit2}/transport_test.go (99%) diff --git a/api/v1beta1/gitrepository_types.go b/api/v1beta1/gitrepository_types.go index 8bc69ff2..1b0689cb 100644 --- a/api/v1beta1/gitrepository_types.go +++ b/api/v1beta1/gitrepository_types.go @@ -25,9 +25,10 @@ import ( const ( // GitRepositoryKind is the string representation of a GitRepository. GitRepositoryKind = "GitRepository" - // GoGitImplementation represents the go-git git implementation kind. + + // GoGitImplementation represents the go-git Git implementation kind. GoGitImplementation = "go-git" - // LibGit2Implementation represents the gi2go git implementation kind. + // LibGit2Implementation represents the git2go Git implementation kind. LibGit2Implementation = "libgit2" ) diff --git a/pkg/git/git.go b/pkg/git/git.go index 623a6cca..bb9c470d 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -21,20 +21,16 @@ import ( sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" "github.com/fluxcd/source-controller/pkg/git/common" - gitv1 "github.com/fluxcd/source-controller/pkg/git/v1" - gitv2 "github.com/fluxcd/source-controller/pkg/git/v2" -) - -const ( - defaultBranch = "master" + "github.com/fluxcd/source-controller/pkg/git/gogit" + "github.com/fluxcd/source-controller/pkg/git/libgit2" ) func CheckoutStrategyForRef(ref *sourcev1.GitRepositoryRef, gitImplementation string) (common.CheckoutStrategy, error) { switch gitImplementation { case sourcev1.GoGitImplementation: - return gitv1.CheckoutStrategyForRef(ref), nil + return gogit.CheckoutStrategyForRef(ref), nil case sourcev1.LibGit2Implementation: - return gitv2.CheckoutStrategyForRef(ref), nil + return libgit2.CheckoutStrategyForRef(ref), nil default: return nil, fmt.Errorf("invalid git implementation %s", gitImplementation) } @@ -43,9 +39,9 @@ func CheckoutStrategyForRef(ref *sourcev1.GitRepositoryRef, gitImplementation st func AuthSecretStrategyForURL(url string, gitImplementation string) (common.AuthSecretStrategy, error) { switch gitImplementation { case sourcev1.GoGitImplementation: - return gitv1.AuthSecretStrategyForURL(url) + return gogit.AuthSecretStrategyForURL(url) case sourcev1.LibGit2Implementation: - return gitv2.AuthSecretStrategyForURL(url) + return libgit2.AuthSecretStrategyForURL(url) default: return nil, fmt.Errorf("invalid git implementation %s", gitImplementation) } diff --git a/pkg/git/v1/checkout.go b/pkg/git/gogit/checkout.go similarity index 99% rename from pkg/git/v1/checkout.go rename to pkg/git/gogit/checkout.go index 64e952b0..0c82d477 100644 --- a/pkg/git/v1/checkout.go +++ b/pkg/git/gogit/checkout.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package gogit import ( "context" @@ -27,6 +27,7 @@ import ( "github.com/go-git/go-git/v5/plumbing" "github.com/fluxcd/pkg/version" + sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" "github.com/fluxcd/source-controller/pkg/git/common" ) diff --git a/pkg/git/v1/checkout_test.go b/pkg/git/gogit/checkout_test.go similarity index 99% rename from pkg/git/v1/checkout_test.go rename to pkg/git/gogit/checkout_test.go index df7781d7..bd0e665a 100644 --- a/pkg/git/v1/checkout_test.go +++ b/pkg/git/gogit/checkout_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package gogit import ( "context" diff --git a/pkg/git/v1/commit.go b/pkg/git/gogit/commit.go similarity index 98% rename from pkg/git/v1/commit.go rename to pkg/git/gogit/commit.go index ac1c2b78..8c14fea4 100644 --- a/pkg/git/v1/commit.go +++ b/pkg/git/gogit/commit.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package gogit import ( "fmt" diff --git a/pkg/git/v1/transport.go b/pkg/git/gogit/transport.go similarity index 99% rename from pkg/git/v1/transport.go rename to pkg/git/gogit/transport.go index 45f5c6cf..a51ab3ce 100644 --- a/pkg/git/v1/transport.go +++ b/pkg/git/gogit/transport.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package gogit import ( "fmt" @@ -25,6 +25,7 @@ import ( corev1 "k8s.io/api/core/v1" "github.com/fluxcd/pkg/ssh/knownhosts" + "github.com/fluxcd/source-controller/pkg/git/common" ) diff --git a/pkg/git/v1/transport_test.go b/pkg/git/gogit/transport_test.go similarity index 99% rename from pkg/git/v1/transport_test.go rename to pkg/git/gogit/transport_test.go index 8e27033e..0a5c0c90 100644 --- a/pkg/git/v1/transport_test.go +++ b/pkg/git/gogit/transport_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1 +package gogit import ( "reflect" diff --git a/pkg/git/v2/checkout.go b/pkg/git/libgit2/checkout.go similarity index 99% rename from pkg/git/v2/checkout.go rename to pkg/git/libgit2/checkout.go index 78dc7c17..e0604c8c 100644 --- a/pkg/git/v2/checkout.go +++ b/pkg/git/libgit2/checkout.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v2 +package libgit2 import ( "context" diff --git a/pkg/git/v2/checkout_test.go b/pkg/git/libgit2/checkout_test.go similarity index 98% rename from pkg/git/v2/checkout_test.go rename to pkg/git/libgit2/checkout_test.go index fd4494b6..559854c3 100644 --- a/pkg/git/v2/checkout_test.go +++ b/pkg/git/libgit2/checkout_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v2 +package libgit2 import ( "context" diff --git a/pkg/git/v2/commit.go b/pkg/git/libgit2/commit.go similarity index 98% rename from pkg/git/v2/commit.go rename to pkg/git/libgit2/commit.go index 62c7c6d8..1e459f31 100644 --- a/pkg/git/v2/commit.go +++ b/pkg/git/libgit2/commit.go @@ -14,14 +14,15 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v2 +package libgit2 import ( "bytes" "fmt" - "golang.org/x/crypto/openpgp" "strings" + "golang.org/x/crypto/openpgp" + git2go "github.com/libgit2/git2go/v31" corev1 "k8s.io/api/core/v1" ) diff --git a/pkg/git/v2/transport.go b/pkg/git/libgit2/transport.go similarity index 99% rename from pkg/git/v2/transport.go rename to pkg/git/libgit2/transport.go index 1ee78ba0..6097b52e 100644 --- a/pkg/git/v2/transport.go +++ b/pkg/git/libgit2/transport.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v2 +package libgit2 import ( "bufio" @@ -27,9 +27,10 @@ import ( "golang.org/x/crypto/ssh" - "github.com/fluxcd/source-controller/pkg/git/common" git2go "github.com/libgit2/git2go/v31" corev1 "k8s.io/api/core/v1" + + "github.com/fluxcd/source-controller/pkg/git/common" ) func AuthSecretStrategyForURL(URL string) (common.AuthSecretStrategy, error) { diff --git a/pkg/git/v2/transport_test.go b/pkg/git/libgit2/transport_test.go similarity index 99% rename from pkg/git/v2/transport_test.go rename to pkg/git/libgit2/transport_test.go index db1612a6..88786bf1 100644 --- a/pkg/git/v2/transport_test.go +++ b/pkg/git/libgit2/transport_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v2 +package libgit2 import ( "reflect"