git

package
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2022 License: Apache-2.0 Imports: 46 Imported by: 4

Documentation

Overview

Git Repository Adapter

This component implements integration of git into package orchestration. A local clone of a registered git repository is created in a cache, and periodically refreshed. All package operations happen on the local copy; on completion of an operation (create, update, delete package revision or its resources) any new changes (in one or more commits) are pushed to the remote repository.

Branching Strategy

Porch doesn't create tracking branches for remotes. This indirection would add a layer of complexity where branches can become out of sync and in need of reconciliation and conflict resolution. Instead, Porch analyzes the remote references (refs/remotes/origin/branch...) to discover packges. These refs are never directly updated by Porch other than by push or fetch to/from remote. Any intermediate commits Porch makes are either in 'detached HEAD' mode, or using temporary branches (these will become relevant if/when Porch implements repository garbage collection).

Porch uses the default convention for naming remote branches (refs/remotes/origin/branch...) in order to make direct introspection of the repositories aligned with traditional git repositories.

Index

Constants

View Source
const (
	DefaultMainReferenceName plumbing.ReferenceName = "refs/heads/main"
	OriginName               string                 = "origin"
)

Variables

This section is empty.

Functions

func AnnotateCommitMessage

func AnnotateCommitMessage(message string, annotation *gitAnnotation) (string, error)

AnnotateCommitMessage adds the gitAnnotation to the commit message.

func CreateEmptyCommit added in v0.0.10

func CreateEmptyCommit(repo *gogit.Repository) error

func ExtractGitAnnotations

func ExtractGitAnnotations(commit *object.Commit) ([]*gitAnnotation, error)

ExtractGitAnnotations reads the gitAnnotations from the given commit. If no annotation are found, it returns [], nil If an invalid annotation is found, it returns an error.

func InitEmptyRepositoryWithWorktree

func InitEmptyRepositoryWithWorktree(t *testing.T, path string) *gogit.Repository

func InitializeBranch

func InitializeBranch(t *testing.T, git *gogit.Repository, branch string)

func OpenGitRepositoryFromArchive

func OpenGitRepositoryFromArchive(t *testing.T, tarfile, tempdir string) *gogit.Repository

func OpenGitRepositoryFromArchiveWithWorktree

func OpenGitRepositoryFromArchiveWithWorktree(t *testing.T, tarfile, path string) *gogit.Repository

func ServeExistingRepository

func ServeExistingRepository(t *testing.T, git *gogit.Repository) string

func ServeGitRepository

func ServeGitRepository(t *testing.T, tarfile, tempdir string) (*gogit.Repository, string)

func ServeGitRepositoryWithBranch

func ServeGitRepositoryWithBranch(t *testing.T, tarfile, tempdir, branch string) (*gogit.Repository, string)

Types

type BranchName

type BranchName string

BranchName represents a relative branch name (i.e. 'main', 'drafts/bucket/v1') and supports transformation to the ReferenceName in local (cached) repository (those references are in the form 'refs/remotes/origin/...') or in the remote repository (those references are in the form 'refs/heads/...').

const (
	MainBranch BranchName = "main"
)

func (BranchName) ForceFetchSpec

func (b BranchName) ForceFetchSpec() config.RefSpec

func (BranchName) RefInLocal

func (b BranchName) RefInLocal() plumbing.ReferenceName

func (BranchName) RefInRemote

func (b BranchName) RefInRemote() plumbing.ReferenceName

type DiscoverPackagesOptions

type DiscoverPackagesOptions struct {
	// FilterPrefix restricts package discovery to a particular subdirectory.
	// The subdirectory is not required to exist (we will return an empty list of packages).
	FilterPrefix string

	// Recurse enables recursive traversal of the git tree.
	Recurse bool
}

DiscoveryPackagesOptions holds the configuration for walking a git tree

type DynamicRepos added in v0.0.10

type DynamicRepos struct {
	// contains filtered or unexported fields
}

func NewDynamicRepos added in v0.0.10

func NewDynamicRepos(baseDir string, gitRepoOptions []GitRepoOption) *DynamicRepos

func (*DynamicRepos) FindRepo added in v0.0.10

func (r *DynamicRepos) FindRepo(ctx context.Context, id string) (*Repo, error)

type GitHash

type GitHash = plumbing.Hash

type GitRepoOption added in v0.0.10

type GitRepoOption interface {
	// contains filtered or unexported methods
}

GitRepoOption is implemented by configuration settings for git repository.

func WithBasicAuth

func WithBasicAuth(username, password string) GitRepoOption

type GitRepository

type GitRepository interface {
	repository.Repository
	GetPackageRevision(ctx context.Context, ref, path string) (repository.PackageRevision, kptfilev1.GitLock, error)
}

func OpenRepository

func OpenRepository(ctx context.Context, name, namespace string, spec *configapi.GitRepository, root string, opts GitRepositoryOptions) (GitRepository, error)

type GitRepositoryOptions

type GitRepositoryOptions struct {
	CredentialResolver repository.CredentialResolver
	UserInfoProvider   repository.UserInfoProvider
	MainBranchStrategy MainBranchStrategy
}

type GitServer

type GitServer struct {
	// contains filtered or unexported fields
}

GitServer is a mock git server implementing "just enough" of the git protocol

func NewGitServer

func NewGitServer(repos Repos, opts ...GitServerOption) (*GitServer, error)

NewGitServer constructs a GitServer backed by the specified repo.

func (*GitServer) ListenAndServe

func (s *GitServer) ListenAndServe(ctx context.Context, listen string, addressChannel chan<- net.Addr) error

ListenAndServe starts the git server on "listen". The address we actually start listening on will be posted to addressChannel

func (*GitServer) ServeHTTP

func (s *GitServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP is the entrypoint for http requests.

type GitServerOption

type GitServerOption interface {
	// contains filtered or unexported methods
}

type MainBranchStrategy added in v0.0.9

type MainBranchStrategy int
const (
	ErrorIfMissing   MainBranchStrategy = iota // ErrorIsMissing
	CreateIfMissing                            // CreateIfMissing
	SkipVerification                           // SkipVerification
)

func (MainBranchStrategy) String added in v0.0.9

func (i MainBranchStrategy) String() string

type PacketLineWriter

type PacketLineWriter struct {
	// contains filtered or unexported fields
}

PacketLineWriter implements the git protocol line framing, with deferred error handling.

func NewPacketLineWriter

func NewPacketLineWriter(w io.Writer) *PacketLineWriter

NewPackageLineWriter constructs a PacketLineWriter

func (*PacketLineWriter) Flush

func (w *PacketLineWriter) Flush() error

Flush writes any buffered data, and returns an error if one has accumulated.

func (*PacketLineWriter) WriteLine

func (w *PacketLineWriter) WriteLine(s string)

WriteLine frames and writes a line, accumulating errors until Flush is called.

func (*PacketLineWriter) WriteZeroPacketLine

func (w *PacketLineWriter) WriteZeroPacketLine()

WriteZeroPacketLine writes a special "0000" line - often used to indicate the end of a block in the git protocol

type RefUpdate

type RefUpdate struct {
	From GitHash
	To   GitHash
	Ref  string
}

RefUpdate stores requested tag/branch updates

type Repo added in v0.0.10

type Repo struct {
	// contains filtered or unexported fields
}

Repo manages a single git repository

func NewRepo added in v0.0.10

func NewRepo(gogit *gogit.Repository, options ...GitRepoOption) (*Repo, error)

NewRepo constructs an instance of Repo

type Repos added in v0.0.10

type Repos interface {
	FindRepo(ctx context.Context, id string) (*Repo, error)
}

type StaticRepos added in v0.0.10

type StaticRepos struct {
	// contains filtered or unexported fields
}

StaticRepos holds multiple registered git repositories

func NewStaticRepos added in v0.0.10

func NewStaticRepos() *StaticRepos

NewRepos constructs an instance of Repos

func (*StaticRepos) Add added in v0.0.10

func (r *StaticRepos) Add(id string, repo *Repo) error

Add registers a git repository under the specified id

func (*StaticRepos) FindRepo added in v0.0.10

func (r *StaticRepos) FindRepo(ctx context.Context, id string) (*Repo, error)

FindRepo returns a repo registered under the specified id, or nil if none is registered.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL