gitutil

package
v0.0.0-...-53353bc Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package gitutil provides Go wrappers for various Git commands.

Index

Constants

View Source
const (
	RemoteType = "remote"
	LocalType  = "local"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AllOpt

type AllOpt bool

type AuthorDateOpt

type AuthorDateOpt string

type BareOpt

type BareOpt bool

type Branch

type Branch struct {
	*Reference
	Tracking *Reference
}

type BranchName

type BranchName string

type CheckoutOpt

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

type CloneOpt

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

type CommitOpt

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

type Committer

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

Committer encapsulates the process of create a commit.

func (*Committer) Commit

func (c *Committer) Commit(message string) error

Commit creates a commit.

type CommitterDateOpt

type CommitterDateOpt string

type DeleteBranchOpt

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

type DepthOpt

type DepthOpt int

type DetachOpt

type DetachOpt bool

type FetchOpt

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

type FetchTagOpt

type FetchTagOpt string

type FfOnlyOpt

type FfOnlyOpt bool

type FollowTagsOpt

type FollowTagsOpt bool

type ForceOpt

type ForceOpt bool

type Git

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

func New

func New(jirix *jiri.X, opts ...gitOpt) *Git

New is the Git factory.

func (*Git) Add

func (g *Git) Add(file string) error

Add adds a file to staging.

func (*Git) AddOrReplaceRemote

func (g *Git) AddOrReplaceRemote(name, path string) error

AddOrReplaceRemote adds a new remote with given name and path. If the name already exists, it replaces the named remote with new path.

func (*Git) AddRemote

func (g *Git) AddRemote(name, path string) error

AddRemote adds a new remote with the given name and path.

func (*Git) AddUpdatedFiles

func (g *Git) AddUpdatedFiles() error

Add adds a file to staging.

func (*Git) BranchExists

func (g *Git) BranchExists(branch string) (bool, error)

BranchExists tests whether a branch with the given name exists in the local repository.

func (*Git) BranchesDiffer

func (g *Git) BranchesDiffer(branch1, branch2 string) (bool, error)

BranchesDiffer tests whether two branches have any changes between them.

func (*Git) CheckoutBranch

func (g *Git) CheckoutBranch(branch string, opts ...CheckoutOpt) error

CheckoutBranch checks out the given branch.

func (*Git) CherryPick

func (g *Git) CherryPick(rev string) error

func (*Git) CherryPickAbort

func (g *Git) CherryPickAbort() error

CherryPickAbort aborts an in-progress cherry-pick operation.

func (*Git) Clone

func (g *Git) Clone(repo, path string, opts ...CloneOpt) error

Clone clones the given repository to the given local path. If reference is not empty it uses the given path as a reference/shared repo.

func (*Git) CloneMirror

func (g *Git) CloneMirror(repo, path string, depth int) error

CloneMirror clones the given repository using mirror flag.

func (*Git) CloneRecursive

func (g *Git) CloneRecursive(repo, path string) error

CloneRecursive clones the given repository recursively to the given local path.

func (*Git) Commit

func (g *Git) Commit() error

Commit commits all files in staging with an empty message.

func (*Git) CommitAmend

func (g *Git) CommitAmend() error

CommitAmend amends the previous commit with the currently staged changes. Empty commits are allowed.

func (*Git) CommitAmendWithMessage

func (g *Git) CommitAmendWithMessage(message string) error

CommitAmendWithMessage amends the previous commit with the currently staged changes, and the given message. Empty commits are allowed.

func (*Git) CommitAndEdit

func (g *Git) CommitAndEdit() error

CommitAndEdit commits all files in staging and allows the user to edit the commit message.

func (*Git) CommitFile

func (g *Git) CommitFile(fileName, message string) error

CommitFile commits the given file with the given commit message.

func (*Git) CommitMessages

func (g *Git) CommitMessages(branch, baseBranch string) (string, error)

CommitMessages returns the concatenation of all commit messages on <branch> that are not also on <baseBranch>.

func (*Git) CommitMsg

func (g *Git) CommitMsg(ref string) (string, error)

func (*Git) CommitNoVerify

func (g *Git) CommitNoVerify(message string) error

CommitNoVerify commits all files in staging with the given message and skips all git-hooks.

func (*Git) CommitWithMessage

func (g *Git) CommitWithMessage(message string) error

CommitWithMessage commits all files in staging with the given message.

func (*Git) CommitWithMessageAndEdit

func (g *Git) CommitWithMessageAndEdit(message string) error

CommitWithMessage commits all files in staging and allows the user to edit the commit message. The given message will be used as the default.

func (*Git) Committers

func (g *Git) Committers() ([]string, error)

Committers returns a list of committers for the current repository along with the number of their commits.

func (*Git) Config

func (g *Git) Config(configArgs ...string) error

func (*Git) ConfigGetKey

func (g *Git) ConfigGetKey(key string) (string, error)

func (*Git) CountCommits

func (g *Git) CountCommits(branch, base string) (int, error)

CountCommits returns the number of commits on <branch> that are not on <base>.

func (*Git) CreateAndCheckoutBranch

func (g *Git) CreateAndCheckoutBranch(branch string) error

CreateAndCheckoutBranch creates a new branch with the given name and checks it out.

func (*Git) CreateBranch

func (g *Git) CreateBranch(branch string) error

CreateBranch creates a new branch with the given name.

func (*Git) CreateBranchFromRef

func (g *Git) CreateBranchFromRef(branch, ref string) error

CreateBranchFromRef creates a new branch from an existing reference.

func (*Git) CreateBranchWithUpstream

func (g *Git) CreateBranchWithUpstream(branch, upstream string) error

CreateBranchWithUpstream creates a new branch and sets the upstream repository to the given upstream.

func (*Git) CreateLightweightTag

func (g *Git) CreateLightweightTag(name string) error

CreateLightweightTag creates a lightweight tag with a given name.

func (*Git) CurrentBranchName

func (g *Git) CurrentBranchName() (string, error)

CurrentBranchName returns the name of the current branch.

func (*Git) CurrentRevision

func (g *Git) CurrentRevision() (string, error)

CurrentRevision returns the current revision.

func (*Git) CurrentRevisionForRef

func (g *Git) CurrentRevisionForRef(ref string) (string, error)

CurrentRevisionForRef gets current rev for ref/branch/tags

func (*Git) CurrentRevisionOfBranch

func (g *Git) CurrentRevisionOfBranch(branch string) (string, error)

CurrentRevisionOfBranch returns the current revision of the given branch.

func (*Git) DeleteBranch

func (g *Git) DeleteBranch(branch string, opts ...DeleteBranchOpt) error

DeleteBranch deletes the given branch.

func (*Git) DeleteRemote

func (g *Git) DeleteRemote(name string) error

DeleteRemote deletes the named remote

func (*Git) DirExistsOnBranch

func (g *Git) DirExistsOnBranch(dir, branch string) bool

DirExistsOnBranch returns true if a directory with the given name exists on the branch. If branch is empty it defaults to "master".

func (*Git) ExtraCommits

func (g *Git) ExtraCommits(rev, base string) ([]string, error)

Provides list of commits reachable from rev but not from base rev can be a branch/tag or revision name.

func (*Git) Fetch

func (g *Git) Fetch(remote string, opts ...FetchOpt) error

Fetch fetches refs and tags from the given remote.

func (*Git) FetchRefspec

func (g *Git) FetchRefspec(remote, refspec string, opts ...FetchOpt) error

FetchRefspec fetches refs and tags from the given remote for a particular refspec.

func (*Git) FilesWithUncommittedChanges

func (g *Git) FilesWithUncommittedChanges() ([]string, error)

FilesWithUncommittedChanges returns the list of files that have uncommitted changes.

func (*Git) GetAllBranchesInfo

func (g *Git) GetAllBranchesInfo() ([]Branch, error)

GetAllBranchesInfo returns information about all branches.

func (*Git) GetBranches

func (g *Git) GetBranches(args ...string) ([]string, string, error)

GetBranches returns a slice of the local branches of the current repository, followed by the name of the current branch. The behavior can be customized by providing optional arguments (e.g. --merged).

func (*Git) GetRemoteBranchesContaining

func (g *Git) GetRemoteBranchesContaining(commit string) ([]string, error)

GetRemoteBranchesContaining returns a slice of the remote branches which contains the given commit

func (*Git) GetSymbolicRef

func (g *Git) GetSymbolicRef() (string, error)

func (*Git) Grep

func (g *Git) Grep(query string, pathSpecs []string, flags ...string) ([]string, error)

Grep searches for matching text and returns a list of lines from `git grep`.

func (*Git) HasUncommittedChanges

func (g *Git) HasUncommittedChanges() (bool, error)

HasUncommittedChanges checks whether the current branch contains any uncommitted changes.

func (*Git) HasUntrackedFiles

func (g *Git) HasUntrackedFiles() (bool, error)

HasUntrackedFiles checks whether the current branch contains any untracked files.

func (*Git) Init

func (g *Git) Init(path string, opts ...CloneOpt) error

Init initializes a new git repository.

func (*Git) IsFileCommitted

func (g *Git) IsFileCommitted(file string) bool

IsFileCommitted tests whether the given file has been committed to the repository.

func (*Git) IsOnBranch

func (g *Git) IsOnBranch() bool

func (*Git) IsRevAvailable

func (g *Git) IsRevAvailable(rev string) bool

IsRevAvailable runs cat-file on a commit hash is available locally.

func (*Git) LatestCommitMessage

func (g *Git) LatestCommitMessage() (string, error)

LatestCommitMessage returns the latest commit message on the current branch.

func (*Git) ListBranchesContainingRef

func (g *Git) ListBranchesContainingRef(commit string) (map[string]bool, error)

ListBranchesContainingRef returns a slice of the local branches which contains the given commit

func (*Git) ListRemoteBranchesContainingRef

func (g *Git) ListRemoteBranchesContainingRef(commit string) (map[string]bool, error)

ListRemoteBranchesContainingRef returns a slice of the remote branches which contains the given commit

func (*Git) Log

func (g *Git) Log(branch, base, format string) ([][]string, error)

Log returns a list of commits on <branch> that are not on <base>, using the specified format.

func (*Git) LsRemote

func (g *Git) LsRemote(args ...string) (string, error)

LsRemote lists referneces in a remote repository.

func (*Git) Merge

func (g *Git) Merge(branch string, opts ...MergeOpt) error

Merge merges all commits from <branch> to the current branch. If <squash> is set, then all merged commits are squashed into a single commit.

func (*Git) MergedBranches

func (g *Git) MergedBranches(ref string) ([]string, error)

MergedBranches returns the list of all branches that were already merged.

func (*Git) ModifiedFiles

func (g *Git) ModifiedFiles(baseBranch, currentBranch string) ([]string, error)

ModifiedFiles returns a slice of filenames that have changed between <baseBranch> and <currentBranch>.

func (*Git) NewCommitter

func (g *Git) NewCommitter(edit bool) *Committer

NewCommitter is the Committer factory. The boolean <edit> flag determines whether the commit commands should prompt users to edit the commit message. This flag enables automated testing.

func (*Git) OneLineLog

func (g *Git) OneLineLog(rev string) (string, error)

Get one line log

func (*Git) Pull

func (g *Git) Pull(remote, branch string) error

Pull pulls the given branch from the given remote.

func (*Git) Push

func (g *Git) Push(remote, branch string, opts ...PushOpt) error

Push pushes the given branch to the given remote.

func (*Git) Rebase

func (g *Git) Rebase(upstream string, opts ...RebaseOpt) error

Rebase rebases to a particular upstream branch.

func (*Git) RebaseAbort

func (g *Git) RebaseAbort() error

RebaseAbort aborts an in-progress rebase operation.

func (*Git) RemoteBranchName

func (g *Git) RemoteBranchName() (string, error)

RemoteBranchName returns the name of the tracking branch stripping remote name from it. It will search recursively if current branch tracks a local branch.

func (*Git) RemoteUrl

func (g *Git) RemoteUrl(name string) (string, error)

RemoteUrl gets the url of the remote with the given name.

func (*Git) Remove

func (g *Git) Remove(fileNames ...string) error

Remove removes the given files.

func (*Git) RemoveUntrackedFiles

func (g *Git) RemoveUntrackedFiles() error

RemoveUntrackedFiles removes untracked files and directories.

func (*Git) Reset

func (g *Git) Reset(target string, opts ...ResetOpt) error

Reset resets the current branch to the target, discarding any uncommitted changes.

func (*Git) SetRemoteUrl

func (g *Git) SetRemoteUrl(name, url string) error

SetRemoteUrl sets the url of the remote with given name to the given url.

func (*Git) SetUpstream

func (g *Git) SetUpstream(branch, upstream string) error

SetUpstream sets the upstream branch to the given one.

func (*Git) ShortHash

func (g *Git) ShortHash(ref string) (string, error)

ShortHash returns the short hash for a given reference.

func (*Git) ShortStatus

func (g *Git) ShortStatus() (string, error)

func (*Git) Show

func (g *Git) Show(ref, file string) (string, error)

func (*Git) Stash

func (g *Git) Stash() (bool, error)

Stash attempts to stash any unsaved changes. It returns true if anything was actually stashed, otherwise false. An error is returned if the stash command fails.

func (*Git) StashPop

func (g *Git) StashPop() error

StashPop pops the stash into the current working tree.

func (*Git) StashSize

func (g *Git) StashSize() (int, error)

StashSize returns the size of the stash stack.

func (*Git) TopLevel

func (g *Git) TopLevel() (string, error)

TopLevel returns the top level path of the current repository.

func (*Git) TrackedFiles

func (g *Git) TrackedFiles() ([]string, error)

TrackedFiles returns the list of files that are tracked.

func (*Git) TrackingBranchFromSymbolicRef

func (g *Git) TrackingBranchFromSymbolicRef(ref string) (string, error)

TrackingBranchFromSymbolicRef returns the name of the tracking branch for provided ref

func (*Git) TrackingBranchName

func (g *Git) TrackingBranchName() (string, error)

TrackingBranchName returns the name of the tracking branch.

func (*Git) UntrackedFiles

func (g *Git) UntrackedFiles() ([]string, error)

UntrackedFiles returns the list of files that are not tracked.

func (*Git) UserInfoForCommit

func (g *Git) UserInfoForCommit(ref string) (string, string, error)

UserInfoForCommit returns user name and email for a given reference.

func (*Git) Version

func (g *Git) Version() (int, int, error)

Version returns the major and minor git version.

type GitError

type GitError struct {
	Root        string
	Args        []string
	Output      string
	ErrorOutput string
	// contains filtered or unexported fields
}

func Error

func Error(output, errorOutput string, err error, root string, args ...string) GitError

func (GitError) Error

func (ge GitError) Error() string

type MergeOpt

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

type MessageOpt

type MessageOpt string

type ModeOpt

type ModeOpt string

type NoCheckoutOpt

type NoCheckoutOpt bool

type OmitBlobsOpt

type OmitBlobsOpt bool

type PruneOpt

type PruneOpt bool

type PushOpt

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

type RebaseMerges

type RebaseMerges bool

type RebaseOpt

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

type Reference

type Reference struct {
	Name     string
	Revision string
	IsHead   bool
}

type ReferenceOpt

type ReferenceOpt string

type ResetOnFailureOpt

type ResetOnFailureOpt bool

type ResetOpt

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

type Revision

type Revision string

type RootDirOpt

type RootDirOpt string

type SharedOpt

type SharedOpt bool

type SquashOpt

type SquashOpt bool

type StrategyOpt

type StrategyOpt string

type TagsOpt

type TagsOpt bool

type UpdateShallowOpt

type UpdateShallowOpt bool

type UserEmailOpt

type UserEmailOpt string

type UserNameOpt

type UserNameOpt string

type VerifyOpt

type VerifyOpt bool

Jump to

Keyboard shortcuts

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