gitgeneric

package
v0.77.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRemoteReferenceName = "origin"
)

Variables

This section is empty.

Functions

func ReadFileFromRevision added in v0.59.0

func ReadFileFromRevision(repoPath, revision, filePath string) ([]byte, error)

ReadFileFromRevision reads a file from a git repository at a given revision.

Types

type DatedTag added in v0.49.0

type DatedTag struct {
	When time.Time
	Name string
	Hash string
}

type GitHandler added in v0.28.0

type GitHandler interface {
	Add(files []string, workingDir string) error
	Checkout(username, password, branch, remoteBranch, workingDir string, forceReset bool) error
	Clone(username, password, URL, workingDir string, withSubmodules *bool) error
	Commit(user, email, message, workingDir string, signingKey string, passphrase string) error
	GetChangedFiles(workingDir string) ([]string, error)
	GetLatestCommitHash(workingDir string) (string, error)
	IsSimilarBranch(a, b, workingDir string) (bool, error)
	IsLocalBranchPublished(baseBranch, workingBranch, username, password, workingDir string) (bool, error)
	NewTag(tag, message, workingDir string) (bool, error)
	NewBranch(branch, workingDir string) (bool, error)
	Push(username string, password string, workingDir string, force bool) (bool, error)
	PushTag(tag string, username string, password string, workingDir string, force bool) error
	PushBranch(branch string, username string, password string, workingDir string, force bool) error
	RemoteURLs(workingDir string) (map[string]string, error)
	SanitizeBranchName(branch string) string
	Tags(workingDir string) (tags []string, err error)
	TagHashes(workingDir string) (hashes []string, err error)
	TagRefs(workingDir string) (refs []DatedTag, err error)
	Branches(workingDir string) (branches []string, err error)
}

type GoGit added in v0.28.0

type GoGit struct {
}

func (GoGit) Add added in v0.28.0

func (g GoGit) Add(files []string, workingDir string) error

Add run `git add`.

func (GoGit) Branches added in v0.44.0

func (g GoGit) Branches(workingDir string) (branches []string, err error)

Tags return a list of git tags ordered by latest commit time

func (GoGit) Checkout added in v0.28.0

func (g GoGit) Checkout(username, password, basedBranch, newBranch, gitRepositoryPath string, forceReset bool) error

Checkout create and then uses a temporary git branch.

func (GoGit) Clone added in v0.28.0

func (g GoGit) Clone(username, password, URL, workingDir string, withSubmodules *bool) error

Clone run `git clone`.

func (GoGit) Commit added in v0.28.0

func (g GoGit) Commit(user, email, message, workingDir string, signingKey string, passphrase string) error

Commit run `git commit`.

func (GoGit) GetChangedFiles added in v0.28.0

func (g GoGit) GetChangedFiles(workingDir string) ([]string, error)

func (GoGit) GetLatestCommitHash added in v0.76.0

func (g GoGit) GetLatestCommitHash(workingDir string) (string, error)

GetLatestCommitHash returns the latest commit hash from the working directory

func (GoGit) IsLocalBranchPublished added in v0.45.0

func (g GoGit) IsLocalBranchPublished(baseBranch, workingBranch, username, password, workingDir string) (bool, error)

IsLocalBranchPublished checks if the local working branch, contains any changes which should be published.

We retrieve:

  • the latest commit from the local working branch
  • the latest commit from the base branch
  • the latest commit from the remote working branch if it exists.

Based on those three information we decide if local changes should be published.

If local working branch == local base branch and no remote working branch => This means that base branch and working are similar so nothing need to be pushed

If local working branch == local base branch != remote working branch => This means that at some point the remote branch diverge from base branch

If local working branch == local base branch == remote working branch => This means that everything is up to date

returns true if both the remote and local reference are similar.

func (GoGit) IsSimilarBranch added in v0.28.0

func (g GoGit) IsSimilarBranch(a, b, workingDir string) (bool, error)

IsSimilarBranch checks that the last commits of the two branches are similar then return true if it's the case

func (GoGit) NewBranch added in v0.44.0

func (g GoGit) NewBranch(branch, workingDir string) (bool, error)

NewBranch create a tag then return a boolean to indicate if the tag was created or not.

func (GoGit) NewTag added in v0.28.0

func (g GoGit) NewTag(tag, message, workingDir string) (bool, error)

NewTag create a tag then return a boolean to indicate if the tag was created or not.

func (GoGit) Push added in v0.28.0

func (g GoGit) Push(username string, password string, workingDir string, force bool) (bool, error)

Push run `git push`. The function returns a boolean to indicate if the push needed a force push or not. and an error if something went wrong.

func (GoGit) PushBranch added in v0.44.0

func (g GoGit) PushBranch(branch string, username string, password string, workingDir string, force bool) error

PushBranch publish a single branch created locally

func (GoGit) PushTag added in v0.28.0

func (g GoGit) PushTag(tag string, username string, password string, workingDir string, force bool) error

PushTag publish a single tag created locally

func (GoGit) RemoteURLs added in v0.28.0

func (g GoGit) RemoteURLs(workingDir string) (map[string]string, error)

RemoteURLs returns the list of remote URLs

func (GoGit) SanitizeBranchName added in v0.28.0

func (g GoGit) SanitizeBranchName(branch string) string

SanitizeBranchName replace wrong character in the branch name

func (GoGit) TagHashes added in v0.49.0

func (g GoGit) TagHashes(workingDir string) (hashes []string, err error)

TagHashes returns a list of the commit hashes for git tags ordered by creation time

func (GoGit) TagRefs added in v0.49.0

func (g GoGit) TagRefs(workingDir string) (tags []DatedTag, err error)

TagRefs returns a list of git tags ordered by creation time

func (GoGit) Tags added in v0.28.0

func (g GoGit) Tags(workingDir string) (names []string, err error)

Tags returns a list of the names for git tags ordered by creation time

type MockGit added in v0.28.0

type MockGit struct {
	GitHandler // Ensure any unspecified method from this interface are still declared
	Remotes    map[string]string
	Err        error
}

MockGit is a stub implementation of the `GitHandler` interface to be used in our unit test suites.

func (MockGit) RemoteURLs added in v0.28.0

func (m MockGit) RemoteURLs(workingDir string) (map[string]string, error)

Jump to

Keyboard shortcuts

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