Skip to content

Commit

Permalink
git: Rename git.RepositoryClient to repository.Client
Browse files Browse the repository at this point in the history
Left over changes from the initial PR, which aims at
making the pkg/git packages more Go idiomatic.

xref:
#300 (comment)

Signed-off-by: Paulo Gomes <paulo.gomes@weave.works>
  • Loading branch information
Paulo Gomes committed Nov 15, 2022
1 parent aec27af commit 4d71f21
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
7 changes: 4 additions & 3 deletions git/gogit/repository_client.go → git/gogit/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ import (

"github.com/fluxcd/pkg/git"
"github.com/fluxcd/pkg/git/gogit/fs"
"github.com/fluxcd/pkg/git/repository"
)

// ClientName is the string representation of Client.
const ClientName = "go-git"

// Client implements git.RepositoryClient.
// Client implements repository.Client.
type Client struct {
*git.DiscardRepositoryCloser
*repository.DiscardCloser
path string
repository *extgogit.Repository
authOpts *git.AuthOptions
Expand All @@ -55,7 +56,7 @@ type Client struct {
credentialsOverHTTP bool
}

var _ git.RepositoryClient = &Client{}
var _ repository.Client = &Client{}

type ClientOption func(*Client) error

Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions git/internal/e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ import (
. "github.com/onsi/gomega"

"github.com/fluxcd/pkg/git"
"github.com/fluxcd/pkg/git/repository"
"github.com/fluxcd/pkg/ssh"
)

var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz1234567890")

func testUsingClone(g *WithT, client git.RepositoryClient, repoURL *url.URL, upstreamRepo upstreamRepoInfo) {
func testUsingClone(g *WithT, client repository.Client, repoURL *url.URL, upstreamRepo upstreamRepoInfo) {
// clone repo
_, err := client.Clone(context.TODO(), repoURL.String(), git.CloneOptions{
CheckoutStrategy: git.CheckoutStrategy{
Expand Down Expand Up @@ -105,7 +106,7 @@ func testUsingClone(g *WithT, client git.RepositoryClient, repoURL *url.URL, ups
g.Expect(headCommit).To(Equal(cc))
}

func testUsingInit(g *WithT, client git.RepositoryClient, repoURL *url.URL, upstreamRepo upstreamRepoInfo) {
func testUsingInit(g *WithT, client repository.Client, repoURL *url.URL, upstreamRepo upstreamRepoInfo) {
// Create a new repository
err := client.Init(context.TODO(), repoURL.String(), "main")
g.Expect(err).ToNot(HaveOccurred())
Expand Down
3 changes: 2 additions & 1 deletion git/libgit2/repository_client.go → git/libgit2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (

"github.com/fluxcd/pkg/git"
"github.com/fluxcd/pkg/git/libgit2/transport"
"github.com/fluxcd/pkg/git/repository"
"github.com/fluxcd/pkg/gitutil"
)

Expand All @@ -62,7 +63,7 @@ type Client struct {
credentialsOverHTTP bool
}

var _ git.RepositoryClient = &Client{}
var _ repository.Client = &Client{}

type ClientOption func(*Client) error

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion git/libgit2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
replace (
github.com/fluxcd/pkg/git => ../../git
// Enables the use of pkg/git/gogit/fs.
github.com/fluxcd/pkg/git/gogit => ../../git/gogit
github.com/fluxcd/pkg/git/gogit => ../gogit
github.com/fluxcd/pkg/gittestserver => ../../gittestserver
github.com/fluxcd/pkg/gitutil => ../../gitutil
github.com/fluxcd/pkg/http/transport => ../../http/transport
Expand Down
42 changes: 22 additions & 20 deletions git/client.go → git/repository/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,33 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package git
package repository

import (
"context"

"github.com/fluxcd/pkg/git"
)

// RepositoryReader knows how to perform local and remote read operations
// Reader knows how to perform local and remote read operations
// on a Git repository.
type RepositoryReader interface {
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) (*Commit, error)
Clone(ctx context.Context, url string, cloneOpts git.CloneOptions) (*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.
Head() (string, error)
// Path returns the path of the repository.
Path() string
RepositoryCloser
Closer
}

// RepositoryWriter knows how to perform local and remote write operations
// Writer knows how to perform local and remote write operations
// on a Git repository.
type RepositoryWriter interface {
type Writer interface {
// Init initializes a repository at the configured path with the remote
// origin set to url on the provided branch.
Init(ctx context.Context, url, branch string) error
Expand All @@ -49,28 +51,28 @@ type RepositoryWriter interface {
SwitchBranch(ctx context.Context, branch string) error
// Commit commits any changes made to the repository. commitOpts is an
// optional argument which can be provided to configure the commit.
Commit(info Commit, commitOpts ...CommitOption) (string, error)
RepositoryCloser
Commit(info git.Commit, commitOpts ...git.CommitOption) (string, error)
Closer
}

// RepositoryCloser knows how to perform any operations that need to happen
// at the end of the lifecycle of a RepositoryWriter/RepositoryReader.
// Closer knows how to perform any operations that need to happen
// at the end of the lifecycle of a Writer/Reader.
// When this is not required by the implementation, it can simply embed an
// anonymous pointer to DiscardRepositoryCloser.
type RepositoryCloser interface {
// anonymous pointer to DiscardCloser.
type Closer interface {
// Close closes any resources that need to be closed at the end of
// a Git repository client's lifecycle.
Close()
}

// RepositoryClient knows how to perform local and remote operations on
// Client knows how to perform local and remote operations on
// a Git repository.
type RepositoryClient interface {
RepositoryReader
RepositoryWriter
type Client interface {
Reader
Writer
}

// DiscardRepositoryCloser is a RepositoryCloser which discards calls to Close().
type DiscardRepositoryCloser struct{}
// DiscardCloser is a Closer which discards calls to Close().
type DiscardCloser struct{}

func (c *DiscardRepositoryCloser) Close() {}
func (c *DiscardCloser) Close() {}

0 comments on commit 4d71f21

Please sign in to comment.