git

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: ISC Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectGit

func DetectGit(path string) (string, error)

DetectGit determines if a given path or any of its parents has a .git directory.

Types

type Commit

type Commit struct {
	Hash      string
	Author    Signature
	Committer Signature
	Message   string
	Parents   []string
}

Commit represents a Git commit.

func (Commit) After

func (c Commit) After(d Commit) bool

After determines if a given commit is chronologically after another commit.

func (Commit) Before

func (c Commit) Before(d Commit) bool

Before determines if a given commit is chronologically before another commit.

func (Commit) Equal

func (c Commit) Equal(d Commit) bool

Equal determines if two commits are the same. Two commits are the same if they both have the same hash.

func (Commit) ShortMessage

func (c Commit) ShortMessage() string

ShortMessage returns a one-line truncated commit message.

func (Commit) String

func (c Commit) String() string

func (Commit) Text

func (c Commit) Text() string

Text returns a multi-line commit string.

type Commits

type Commits []Commit

Commits is a map of Git commits.

type Git

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

Git provides Git functionalities.

func Init

func Init(path string) (*Git, error)

Init creates a new git repository and returns a Git service for it.

func Open

func Open(path string) (*Git, error)

Open creates a new Git service for an existing git repository.

func (*Git) AddRemote

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

AddRemote creates a new remote.

func (*Git) CheckoutBranch

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

CheckoutBranch checks out to a git branch.

func (*Git) CommitsIn

func (g *Git) CommitsIn(rev string) (Commits, error)

CommitsIn returns all commits reachable from a revision.

func (*Git) CreateBranch

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

CreateBranch creates a new git branch.

func (*Git) HEAD

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

HEAD returns the hash and name (branch) of the HEAD reference.

func (*Git) IsClean

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

IsClean determines whether or not the working directory is clean.

func (*Git) MoveBranch

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

MoveBranch moves/renames the current branch.

func (*Git) Path

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

Path returns the root path of the Git repository.

func (*Git) Pull

func (g *Git) Pull(ctx context.Context) error

Pull is same as git pull. It brings the changes from a remote repository into the current branch.

func (*Git) Push

func (g *Git) Push(ctx context.Context, remoteName string) error

Push performs a push to a remote repository.

func (*Git) PushTag

func (g *Git) PushTag(ctx context.Context, remoteName, tagName string) error

PushTag pushes a tag to a remote repository.

func (*Git) Remote

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

Remote returns the domain part and path part of a Git remote repository URL. It assumes the remote repository is named origin.

func (*Git) Submodule

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

Submodule looks up a git submodule by its name.

func (*Git) Tag

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

Tag resolves a tag by its name.

func (*Git) Tags

func (g *Git) Tags() (Tags, error)

Tags returns the list of all tags.

func (*Git) UpdateSubmodules

func (g *Git) UpdateSubmodules() error

UpdateSubmodules pulls down and updates all git submodules.

type Signature

type Signature struct {
	Name  string
	Email string
	Time  time.Time
}

Signature determines who and when created a commit or tag.

func (Signature) After

func (s Signature) After(t Signature) bool

After determines if a given signature is chronologically after another signature.

func (Signature) Before

func (s Signature) Before(t Signature) bool

Before determines if a given signature is chronologically before another signature.

func (Signature) String

func (s Signature) String() string

type Submodule

type Submodule struct {
	Name   string
	Path   string
	URL    string
	Branch string
}

Submodule represents a git submodule.

type Tag

type Tag struct {
	Type    TagType
	Hash    string
	Name    string
	Tagger  *Signature
	Message *string
	Commit  Commit
}

Tag represents a Git tag.

func (Tag) After

func (t Tag) After(u Tag) bool

After determines if a given tag is chronologically after another tag. Two tags are compared using the commits they refer to.

func (Tag) Before

func (t Tag) Before(u Tag) bool

Before determines if a given tag is chronologically before another tag. Two tags are compared using the commits they refer to.

func (Tag) Equal

func (t Tag) Equal(u Tag) bool

Equal determines if two tags are the same. Two tags are the same if they both have the same name.

func (Tag) IsZero

func (t Tag) IsZero() bool

IsZero determines if a tag is a zero tag instance.

func (Tag) String

func (t Tag) String() string

type TagType

type TagType int

TagType determines type a Git tag.

const (
	// Lightweight is a lightweight Git tag.
	Lightweight TagType = iota
	// Annotated is an annotated Git tag.
	Annotated
)

func (TagType) String

func (t TagType) String() string

type Tags

type Tags []Tag

Tags is a list of Git tags.

func (Tags) First

func (t Tags) First(f func(Tag) bool) (Tag, bool)

First returns the first tag that satisifies the given predicate. If you pass a nil function, the first tag will be returned.

func (Tags) Last

func (t Tags) Last(f func(Tag) bool) (Tag, bool)

Last returns the last tag that satisifies the given predicate. If you pass a nil function, the last tag will be returned.

func (Tags) Select

func (t Tags) Select(f func(Tag) bool) (Tags, Tags)

Select partitions a list of tags by a given predicate. The first return value is the collection of selected tags (satisfying the predicate). The second return value is the collection of unselected tags (not satisfying the predicate).

Jump to

Keyboard shortcuts

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