git

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRepositories

func NewRepositories(config RepositoriesConfig) (old, new *fs.Repository, err error)

NewRepositories is a factory that knows how to return two fs repositories based on Git.

  1. Loads/clones a git repository (with all its files/worktree) from the fs into memory. twice (one for old repo and one for new repo)
  2. If no before commit passed, it will search the common ancestor of the new repository HEAD against the default branch.
  3. Set the old repo worktree (and its FS) in the `before commit` state.
  4. Create 2 `fs.Repository` using the internal worktree FS of the git repositories.

We end with 2 fs.Repositories that are based on memory and each one has different data based on the commit history that we have been preparing before creating them.

Note: Cloned repos (memory) will have original repo (fs) local branches as remotes because of

the clone, so to use local branch refs, we need to use remote notation, and remote
branches are not supported.

Types

type GoGitRepoClient

type GoGitRepoClient interface {
	Head() (*plumbing.Reference, error)
	Checkout(opts *git.CheckoutOptions) error
	FileSystem() (billy.Filesystem, error)
	CommitObject(h plumbing.Hash) (*object.Commit, error)
	ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, error)
	// Operations independent of the repository.
	MergeBase(current, other *object.Commit) ([]*object.Commit, error)
	Patch(current, other *object.Commit) (*object.Patch, error)
}

GoGitRepoClient helper interface to use go-git and make testable by mocking common operations on a Git repo.

type RepositoriesConfig

type RepositoriesConfig struct {
	ExcludeRegex      []string
	IncludeRegex      []string
	OldRelPath        string
	NewRelPath        string
	KubernetesDecoder fs.K8sObjectDecoder
	AppConfig         *model.AppConfig
	Logger            log.Logger

	// GitBeforeCommitSHA Used to set the Git old repo state.
	// If empty it will use merge-base to get the common ancestor
	// of HEAD.
	// If we are on the default branch this will be neccesary.
	GitBeforeCommitSHA string
	// GitDefaultBranch is the base branch that will be used when no GitBeforeCommitSHA setting is passed.
	// This branch will be the one used against HEAD to get the common parent commit  by using merge-base.
	// Only local branches are support, other refs are not supported (remote branch, tag, hash...)
	GitDefaultBranch string
	// GitDiffIncludeFilter will filter everything except the files modified (edit, create, delete)
	// between the two Git repository states, this is, before-commit and HEAD.
	// This could be translated as: `git diff --name-only before-commit HEAD`.
	GitDiffIncludeFilter bool

	// Don't use these, used for testing purposes. Normally `nil` because are created correctly by the factory.
	// Go-git loaded repositories, if `nil` it will clone them into memory from the current disk path (`.`).
	GoGitOldRepo GoGitRepoClient
	GoGitNewRepo GoGitRepoClient
}

RepositoriesConfig is the configuration for NewRepositories

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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