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 15, 2023
1 parent 88da1a6 commit 39b978a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
14 changes: 7 additions & 7 deletions git/gogit/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,27 +217,27 @@ 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, cfg repository.CloneConfig) (*git.Commit, error) {
if err := g.validateUrl(url); err != nil {
return nil, err
}

checkoutStrat := cloneOpts.CheckoutStrategy
checkoutStrat := cfg.CheckoutStrategy
switch {
case checkoutStrat.Commit != "":
return g.cloneCommit(ctx, url, checkoutStrat.Commit, cloneOpts)
return g.cloneCommit(ctx, url, checkoutStrat.Commit, cfg)
case checkoutStrat.RefName != "":
return g.cloneRefName(ctx, url, checkoutStrat.RefName, cloneOpts)
return g.cloneRefName(ctx, url, checkoutStrat.RefName, cfg)
case checkoutStrat.Tag != "":
return g.cloneTag(ctx, url, checkoutStrat.Tag, cloneOpts)
return g.cloneTag(ctx, url, checkoutStrat.Tag, cfg)
case checkoutStrat.SemVer != "":
return g.cloneSemVer(ctx, url, checkoutStrat.SemVer, cloneOpts)
return g.cloneSemVer(ctx, url, checkoutStrat.SemVer, cfg)
default:
branch := checkoutStrat.Branch
if branch == "" {
branch = git.DefaultBranch
}
return g.cloneBranch(ctx, url, branch, cloneOpts)
return g.cloneBranch(ctx, url, branch, cfg)
}
}

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
4 changes: 2 additions & 2 deletions git/repository/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
// Reader knows how to perform local and remote read operations
// on a Git repository.
type Reader interface {
// Clone clones a repository from the provided url using the options provided.
// Clone clones a repository from the provided url using the config 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, cfg 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 39b978a

Please sign in to comment.