git

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: MIT Imports: 8 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetVersionFromTag

func GetVersionFromTag(tag string) *version.Version

GetVersionFromTag returns the version if the tag is a release tag (e.g. v1.3.4).

Types

type Context

type Context struct {
	*exec.CmdContext
}

func NewCtx

func NewCtx(cwd string, mixin ...func(builder *exec.CmdContextBuilder)) Context

NewCtx returns a new Git command context in the folder `cwd`. Mixin are modifier functions to adapt the ctx to custom needs.

func NewCtxAtRoot

func NewCtxAtRoot(
	cwd string,
	mixin ...func(builder *exec.CmdContextBuilder),
) (Context, string, error)

NewCtxAtRoot returns a new Git command context at the root of the Git repo starting from `cwd`. Returns the `rootDir` as well.

func (*Context) Changes

func (gitx *Context) Changes(dir string, absPath bool) ([]string, error)

Changes returns all changed paths in `dir` (relative to working dir if its a relative path). Staged files are not returned!

func (*Context) ChangesBetweenRevs

func (gitx *Context) ChangesBetweenRevs(
	dir string,
	revA, revB string,
	noRelative bool,
) ([]string, error)

ChangesBetweenRevs computs path changes between two revision specs, as `git diff revA revB`. You can specify `HEAD~1` and `HEAD` for example. To get absolute paths (relative to the repository) use `noRelative`. To convert all to absolute paths use `fs.MakeAllAbsolute`.

func (*Context) CommitContainsTag

func (gitx *Context) CommitContainsTag(ref string, tag string) (bool, error)

CommitContainsTag returns `true` if the commit (ref) `ref` contains the tag `tag`.

func (*Context) CommitIsAMerge

func (gitx *Context) CommitIsAMerge(ref string) (bool, error)

Check if the current commit is a merge commit.

func (*Context) CurrentRef

func (gitx *Context) CurrentRef() (string, error)

CurrentRef returns the current Git symbolic reference (branch). e.g. `feat/bla`.

func (*Context) CurrentRev

func (gitx *Context) CurrentRev() (string, error)

CurrentRev returns the current revision SHA1.

func (*Context) FetchUntilCommit

func (gitx *Context) FetchUntilCommit(
	remote string,
	commitSHA string,
	opts FetchUntilOpts,
) (found bool, err error)

FetchUntilCommit fetches exponentially increasing the shallow boundary of the remote (`*4`) until the `commitSHA` is found in `git rev-list `. Only tries until `maxDepth` has been reached. Meaningful values are: `factor = 4`, `startDepth = 10`, `maxDepth = 1000`.

func (*Context) Files

func (gitx *Context) Files(dir string, noRelative bool) ([]string, error)

Files returns all files managed by Git in dir `dir`.

func (*Context) HasChanges

func (gitx *Context) HasChanges(dir string) (hasChanges bool, err error)

HasChanges reports if there any unstaged changes in repository.

func (*Context) IsIgnored

func (gitx *Context) IsIgnored(path ...string) (ignored bool, err error)

IsIgnored returns true if `path` is ignored by Git.

func (*Context) IsRefAheadOf

func (gitx *Context) IsRefAheadOf(refA string, refB string) (bool, int, error)

IsRefAheadOf checks if ref `refB` is ahead of `refA` and by how many commits. Returns `false` and `0` if `refB` is not ahead of `refA`.

func (*Context) IsRefReachable

func (gitx *Context) IsRefReachable(fromRef string, ref string) (reachable bool, err error)

IsRefReachable reports if `ref` (can be branch/tag/commit) is contained starting from `fromRef`.

func (*Context) LocalRefExists

func (gitx *Context) LocalRefExists(ref string) (sha1 string, err error)

Checks if a local branch `ref` exists and returns the SHA1.

func (*Context) ObjectExists

func (gitx *Context) ObjectExists(sha1 string) (exists bool, err error)

ObjectExists checks if an object in Git addressed by the SHA1 `sha1` exists.

func (*Context) RootDir

func (gitx *Context) RootDir() (string, error)

RootDir returns the top level directory inside `cwd`. If in a submodule it returns the submodule root directory.

func (*Context) VersionTags

func (gitx *Context) VersionTags(remote string) ([]VersionTag, error)

VersionTags returns all versions from existing Git version tags (e.g. `v1.2.3`) in descendin order (sem. version).

type FetchUntilOpts

type FetchUntilOpts struct {
	Factor     int
	StartDepth int
	MaxDepth   int
}

type VersionTag

type VersionTag struct {
	Version *version.Version
	SHA1    string
	Ref     string
}

Jump to

Keyboard shortcuts

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