Skip to content

Commit

Permalink
gogit: rename CloneOptions to CloneConfig for consistency
Browse files Browse the repository at this point in the history
Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
  • Loading branch information
aryan9600 committed May 11, 2023
1 parent ec81681 commit 09a63be
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion git/gogit/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (g *Client) Init(ctx context.Context, url, branch string) error {
return nil
}

func (g *Client) Clone(ctx context.Context, url string, cloneOpts repository.CloneOptions) (*git.Commit, error) {
func (g *Client) Clone(ctx context.Context, url string, cloneOpts repository.CloneConfig) (*git.Commit, error) {
if err := g.validateUrl(url); err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions git/gogit/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
"github.com/fluxcd/pkg/version"
)

func (g *Client) cloneBranch(ctx context.Context, url, branch string, opts repository.CloneOptions) (*git.Commit, error) {
func (g *Client) cloneBranch(ctx context.Context, url, branch string, opts repository.CloneConfig) (*git.Commit, error) {
if g.authOpts == nil {
return nil, fmt.Errorf("unable to checkout repo with an empty set of auth options")
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func (g *Client) cloneBranch(ctx context.Context, url, branch string, opts repos
return buildCommitWithRef(cc, ref)
}

func (g *Client) cloneTag(ctx context.Context, url, tag string, opts repository.CloneOptions) (*git.Commit, error) {
func (g *Client) cloneTag(ctx context.Context, url, tag string, opts repository.CloneConfig) (*git.Commit, error) {
if g.authOpts == nil {
return nil, fmt.Errorf("unable to checkout repo with an empty set of auth options")
}
Expand Down Expand Up @@ -189,7 +189,7 @@ func (g *Client) cloneTag(ctx context.Context, url, tag string, opts repository.
return buildCommitWithRef(cc, ref)
}

func (g *Client) cloneCommit(ctx context.Context, url, commit string, opts repository.CloneOptions) (*git.Commit, error) {
func (g *Client) cloneCommit(ctx context.Context, url, commit string, opts repository.CloneConfig) (*git.Commit, error) {
authMethod, err := transportAuth(g.authOpts, g.useDefaultKnownHosts)
if err != nil {
return nil, fmt.Errorf("unable to construct auth method with options: %w", err)
Expand Down Expand Up @@ -244,7 +244,7 @@ func (g *Client) cloneCommit(ctx context.Context, url, commit string, opts repos
return buildCommitWithRef(cc, cloneOpts.ReferenceName)
}

func (g *Client) cloneSemVer(ctx context.Context, url, semverTag string, opts repository.CloneOptions) (*git.Commit, error) {
func (g *Client) cloneSemVer(ctx context.Context, url, semverTag string, opts repository.CloneConfig) (*git.Commit, error) {
verConstraint, err := semver.NewConstraint(semverTag)
if err != nil {
return nil, fmt.Errorf("semver parse error: %w", err)
Expand Down Expand Up @@ -363,7 +363,7 @@ func (g *Client) cloneSemVer(ctx context.Context, url, semverTag string, opts re
return buildCommitWithRef(cc, ref)
}

func (g *Client) cloneRefName(ctx context.Context, url string, refName string, cloneOpts repository.CloneOptions) (*git.Commit, error) {
func (g *Client) cloneRefName(ctx context.Context, url string, refName string, cloneOpts repository.CloneConfig) (*git.Commit, error) {
if g.authOpts == nil {
return nil, fmt.Errorf("unable to checkout repo with an empty set of auth options")
}
Expand Down
20 changes: 10 additions & 10 deletions git/gogit/clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestClone_cloneBranch(t *testing.T) {
upstreamPath = repoPath
}

cc, err := ggc.Clone(context.TODO(), upstreamPath, repository.CloneOptions{
cc, err := ggc.Clone(context.TODO(), upstreamPath, repository.CloneConfig{
CheckoutStrategy: repository.CheckoutStrategy{
Branch: tt.branch,
},
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestClone_cloneTag(t *testing.T) {
ggc, err := NewClient(tmpDir, &git.AuthOptions{Transport: git.HTTP})
g.Expect(err).ToNot(HaveOccurred())

opts := repository.CloneOptions{
opts := repository.CloneConfig{
CheckoutStrategy: repository.CheckoutStrategy{
Tag: tt.checkoutTag,
},
Expand Down Expand Up @@ -358,7 +358,7 @@ func TestClone_cloneCommit(t *testing.T) {
g := NewWithT(t)

tmpDir := t.TempDir()
opts := repository.CloneOptions{
opts := repository.CloneConfig{
CheckoutStrategy: repository.CheckoutStrategy{
Branch: tt.branch,
Commit: tt.commit,
Expand Down Expand Up @@ -472,7 +472,7 @@ func TestClone_cloneSemVer(t *testing.T) {
ggc, err := NewClient(tmpDir, nil)
g.Expect(err).ToNot(HaveOccurred())

opts := repository.CloneOptions{
opts := repository.CloneConfig{
CheckoutStrategy: repository.CheckoutStrategy{
SemVer: tt.constraint,
},
Expand Down Expand Up @@ -607,7 +607,7 @@ func TestClone_cloneRefName(t *testing.T) {
ggc, err := NewClient(tmpDir, &git.AuthOptions{Transport: git.HTTP})
g.Expect(err).ToNot(HaveOccurred())

cc, err := ggc.Clone(context.TODO(), repoURL, repository.CloneOptions{
cc, err := ggc.Clone(context.TODO(), repoURL, repository.CloneConfig{
CheckoutStrategy: repository.CheckoutStrategy{
RefName: tt.refName,
},
Expand Down Expand Up @@ -686,7 +686,7 @@ func Test_cloneSubmodule(t *testing.T) {
})
g.Expect(err).ToNot(HaveOccurred())

_, err = ggc.Clone(context.TODO(), server.HTTPAddress()+"/"+icingRepoPath, repository.CloneOptions{
_, err = ggc.Clone(context.TODO(), server.HTTPAddress()+"/"+icingRepoPath, repository.CloneConfig{
CheckoutStrategy: repository.CheckoutStrategy{
Branch: "master",
},
Expand Down Expand Up @@ -802,7 +802,7 @@ func Test_ssh_KeyTypes(t *testing.T) {
ggc, err := NewClient(tmpDir, &authOpts)
g.Expect(err).ToNot(HaveOccurred())

cc, err := ggc.Clone(ctx, repoURL, repository.CloneOptions{
cc, err := ggc.Clone(ctx, repoURL, repository.CloneConfig{
CheckoutStrategy: repository.CheckoutStrategy{
Branch: git.DefaultBranch,
},
Expand Down Expand Up @@ -933,7 +933,7 @@ func Test_ssh_KeyExchangeAlgos(t *testing.T) {
ggc, err := NewClient(tmpDir, &authOpts)
g.Expect(err).ToNot(HaveOccurred())

_, err = ggc.Clone(ctx, repoURL, repository.CloneOptions{
_, err = ggc.Clone(ctx, repoURL, repository.CloneConfig{
CheckoutStrategy: repository.CheckoutStrategy{
Branch: git.DefaultBranch,
},
Expand Down Expand Up @@ -1105,7 +1105,7 @@ func Test_ssh_HostKeyAlgos(t *testing.T) {
ggc, err := NewClient(tmpDir, &authOpts)
g.Expect(err).ToNot(HaveOccurred())

_, err = ggc.Clone(ctx, repoURL, repository.CloneOptions{
_, err = ggc.Clone(ctx, repoURL, repository.CloneConfig{
CheckoutStrategy: repository.CheckoutStrategy{
Branch: git.DefaultBranch,
},
Expand Down Expand Up @@ -1323,7 +1323,7 @@ func TestClone_CredentialsOverHttp(t *testing.T) {
repoURL = tt.transformURL(ts.URL)
}

_, err = ggc.Clone(context.TODO(), repoURL, repository.CloneOptions{})
_, err = ggc.Clone(context.TODO(), repoURL, repository.CloneConfig{})

if tt.expectCloneErr != "" {
g.Expect(err).To(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion git/gogit/internal/test/http_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func Test_HTTP_proxy(t *testing.T) {
ggc, err := gogit.NewClient(tmpDir, authOpts)
g.Expect(err).ToNot(HaveOccurred())

_, err = ggc.Clone(context.TODO(), tt.url, repository.CloneOptions{
_, err = ggc.Clone(context.TODO(), tt.url, repository.CloneConfig{
CheckoutStrategy: repository.CheckoutStrategy{
Branch: "main",
},
Expand Down
2 changes: 1 addition & 1 deletion git/gogit/internal/test/socks_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func Test_SOCKS5_proxy(t *testing.T) {
ggc, err := gogit.NewClient(tmpDir, authOpts)
g.Expect(err).ToNot(HaveOccurred())

_, err = ggc.Clone(context.TODO(), repoURL, repository.CloneOptions{
_, err = ggc.Clone(context.TODO(), repoURL, repository.CloneConfig{
CheckoutStrategy: repository.CheckoutStrategy{
Branch: "main",
},
Expand Down
2 changes: 1 addition & 1 deletion git/internal/e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz1234567890")

func testUsingClone(g *WithT, client repository.Client, repoURL *url.URL, upstreamRepo upstreamRepoInfo) {
// clone repo
_, err := client.Clone(context.TODO(), repoURL.String(), repository.CloneOptions{
_, err := client.Clone(context.TODO(), repoURL.String(), repository.CloneConfig{
CheckoutStrategy: repository.CheckoutStrategy{
Branch: "main",
},
Expand Down
2 changes: 1 addition & 1 deletion git/repository/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Reader interface {
// Clone clones a repository from the provided url using the options provided.
// It returns a Commit object describing the Git commit that the repository
// HEAD points to. If the repository is empty, it returns a nil Commit.
Clone(ctx context.Context, url string, cloneOpts CloneOptions) (*git.Commit, error)
Clone(ctx context.Context, url string, cloneOpts CloneConfig) (*git.Commit, error)
// IsClean returns whether the working tree is clean.
IsClean() (bool, error)
// Head returns the hash of the current HEAD of the repo.
Expand Down
4 changes: 2 additions & 2 deletions git/repository/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const (
DefaultPublicKeyAuthUser = "git"
)

// CloneOptions are the options used for a Git clone.
type CloneOptions struct {
// CloneConfig provides configuration options for a Git clone.
type CloneConfig struct {
// CheckoutStrategy defines a strategy to use while checking out
// the cloned repository to a specific target.
CheckoutStrategy
Expand Down

0 comments on commit 09a63be

Please sign in to comment.