git

package
v0.0.0-...-03d6fc4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Branch

type Branch struct {
	// The human-readable name of the branch.
	Name string

	// The commit hash pointed to by this branch.
	Head string
}

Branch describes a Git branch.

type Checkout

type Checkout struct {
	GitDir
}

Checkout is a struct used for managing a local git checkout.

func NewCheckout

func NewCheckout(ctx context.Context, repoUrl, workdir string) (*Checkout, error)

NewCheckout returns a Checkout instance based in the given working directory. Uses any existing checkout in the given directory, or clones one if necessary. In general, servers should use Repo instead of Checkout unless it is absolutely necessary to have a working copy.

func (*Checkout) AddRemote

func (c *Checkout) AddRemote(ctx context.Context, remote, repoUrl string) error

AddRemote checks to see if a remote already exists in the checkout, if it exists then the URL is matched with the repoURL. If the remote does not exist then it is added.

func (*Checkout) Cleanup

func (c *Checkout) Cleanup(ctx context.Context) error

Cleanup forcibly resets all changes and checks out the master branch at origin/master. All local changes will be lost.

func (*Checkout) Fetch

func (c *Checkout) Fetch(ctx context.Context) error

Fetch syncs refs from the remote without modifying the working copy.

func (*Checkout) FetchRefFromRepo

func (c *Checkout) FetchRefFromRepo(ctx context.Context, repo, ref string) error

FetchRefFromRepo syncs the specified ref from the repo without modifying the working copy.

func (*Checkout) Update

func (c *Checkout) Update(ctx context.Context) error

Update syncs the Checkout from its remote. Forcibly resets and checks out the master branch at origin/master. All local changes will be lost. Equivalent to c.Fetch() + c.Cleanup().

type GitDir

type GitDir string

GitDir is a directory in which one may run Git commands.

func (GitDir) Branches

func (g GitDir) Branches(ctx context.Context) ([]*Branch, error)

Branches runs "git branch" and returns a slice of Branch instances.

func (GitDir) Details

func (g GitDir) Details(ctx context.Context, name string) (*vcsinfo.LongCommit, error)

Details returns a vcsinfo.LongCommit instance representing the given commit.

func (GitDir) Dir

func (g GitDir) Dir() string

Dir returns the working directory of the GitDir.

func (GitDir) FullHash

func (g GitDir) FullHash(ctx context.Context, ref string) (string, error)

FullHash gives the full commit hash for the given ref.

func (GitDir) GetBranchHead

func (g GitDir) GetBranchHead(ctx context.Context, branchName string) (string, error)

GetBranchHead returns the commit hash at the HEAD of the given branch.

func (GitDir) GetFile

func (g GitDir) GetFile(ctx context.Context, fileName, commit string) (string, error)

GetFile returns the contents of the given file at the given commit.

func (GitDir) Git

func (g GitDir) Git(ctx context.Context, cmd ...string) (string, error)

Git runs the given git command in the GitDir.

func (GitDir) IsAncestor

func (g GitDir) IsAncestor(ctx context.Context, a, b string) (bool, error)

IsAncestor returns true iff A is an ancestor of B.

func (GitDir) NumCommits

func (g GitDir) NumCommits(ctx context.Context) (int64, error)

NumCommits returns the number of commits in the repo.

func (GitDir) RevList

func (g GitDir) RevList(ctx context.Context, args ...string) ([]string, error)

RevList runs "git rev-list <name>" and returns a slice of commit hashes.

func (GitDir) RevParse

func (g GitDir) RevParse(ctx context.Context, args ...string) (string, error)

RevParse runs "git rev-parse <name>" and returns the result.

func (GitDir) Version

func (g GitDir) Version(ctx context.Context) (int, int, error)

Version returns the Git version.

type Repo

type Repo struct {
	GitDir
}

Repo is a struct used for managing a local git repo.

func NewRepo

func NewRepo(ctx context.Context, repoUrl, workdir string) (*Repo, error)

NewRepo returns a Repo instance based in the given working directory. Uses any existing repo in the given directory, or clones one if necessary. Only creates bare clones; Repo does not maintain a checkout.

func (*Repo) Checkout

func (r *Repo) Checkout(ctx context.Context, workdir string) (*Checkout, error)

Checkout returns a Checkout of the Repo in the given working directory.

func (*Repo) TempCheckout

func (r *Repo) TempCheckout(ctx context.Context) (*TempCheckout, error)

TempCheckout returns a TempCheckout of the repo.

func (*Repo) Update

func (r *Repo) Update(ctx context.Context) error

Update syncs the Repo from its remote.

type TempCheckout

type TempCheckout Checkout

TempCheckout is a temporary Git Checkout.

func NewTempCheckout

func NewTempCheckout(ctx context.Context, repoUrl string) (*TempCheckout, error)

NewTempCheckout returns a TempCheckout instance.

func (*TempCheckout) Delete

func (c *TempCheckout) Delete()

Delete removes the TempCheckout's working directory.

Directories

Path Synopsis
gitinfo enables querying info from a Git repository.
gitinfo enables querying info from a Git repository.

Jump to

Keyboard shortcuts

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