git

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalRepoURL

func CanonicalRepoURL(repoURL string) (string, error)

CanonicalRepoURL returns a canonicalised Git repository URL. It accepts input URLs using the protocols ssh, git, https, possibly including credentials, and possibly ending with ".git", and returns a clean path of the form: <hostname>/<repo-path>.

Types

type Client

type Client struct {
	// Sh is the *shell.Sh instance this client uses for all shell interaction.
	Sh *shell.Sh
	// Bin is the path to the git binary. This defaults to "git", therefore
	// relying that git is in the path.
	Bin string
	// Version is the version of git at Bin.
	Version semv.Version
}

Client is a git client that shells out to locally installed git. It requires that git is in the path by default, although you can override that by setting the Bin field to a path to a different Git. Client is used to perform git commands within a particular directory, determined by its shell.Sh instance.

func NewClient

func NewClient(sh *shell.Sh) (*Client, error)

NewClient returns a git client, as long as `git --version` succeeds. The *shell.Sh is used for all commands. The client created by this func uses git in your path.

func NewClientInVersionRange

func NewClientInVersionRange(sh *shell.Sh, r semv.Range) (*Client, error)

NewClientInVersionRange is similar to NewClient, but returns nil and and error if the version of the installed git client is not in the specified range.

func (*Client) CloneClient added in v0.0.3

func (c *Client) CloneClient() *Client

CloneClient produces a clone of the client.

func (*Client) CloneRepo added in v0.0.3

func (c *Client) CloneRepo(repo, localPath string) error

CloneRepo clones repo into localPath.

func (*Client) CurrentBranch

func (c *Client) CurrentBranch() (string, error)

CurrentBranch returns the currently checked out branch name.

func (*Client) Dir

func (c *Client) Dir() string

Dir returns the current directory.

func (*Client) ListFiles

func (c *Client) ListFiles() ([]string, error)

ListFiles lists all files that are tracked in the repo.

func (*Client) ListRemotes

func (c *Client) ListRemotes() (Remotes, error)

ListRemotes lists all configured remotes.

func (*Client) ListTags

func (c *Client) ListTags() ([]sous.Tag, error)

ListTags lists the tags in this repo.

func (*Client) ListUnpushedCommits

func (c *Client) ListUnpushedCommits() ([]string, error)

ListUnpushedCommits returns a list of commit sha1s for commits that haven't been pushed to any remote

func (*Client) ModifiedFiles

func (c *Client) ModifiedFiles() ([]string, error)

ModifiedFiles returns the list of tracked, modified files.

func (*Client) NearestTag

func (c *Client) NearestTag() (string, error)

NearestTag returns the nearest tag contained in the HEAD revision.

func (*Client) NewFiles

func (c *Client) NewFiles() ([]string, error)

NewFiles returns the list of untracked files.

func (*Client) OpenRepo

func (c *Client) OpenRepo(dirpath string) (*Repo, error)

OpenRepo opens a repo.

func (*Client) RepoRoot

func (c *Client) RepoRoot() (string, error)

RepoRoot returns the absolute root directory of the current repo.

func (*Client) Revision

func (c *Client) Revision() (string, error)

Revision returns the revision at HEAD.

func (*Client) RevisionAt

func (c *Client) RevisionAt(ref string) (string, error)

RevisionAt returns the revision at ref.

type Remote

type Remote struct {
	Name, PushURL, FetchURL string
}

Remote represents a Git remote.

type Remotes

type Remotes map[string]Remote

Remotes is a map of Git remote name to Remote.

func (Remotes) AddFetch

func (rs Remotes) AddFetch(name, url string)

AddFetch adds a fetch URL to the named remote, creating it if it does not exist.

func (Remotes) AddPush

func (rs Remotes) AddPush(name, url string)

AddPush adds a push URL to the named remote, creating it if it does not exist.

type Repo

type Repo struct {
	// Root is the root dir of this repo
	Root string
	// Client is a git client inside this repo.
	Client *Client
}

Repo is a git repository.

func NewRepo

func NewRepo(c *Client) (*Repo, error)

NewRepo takes a client, which it expects to already be inside a repo directory. It returns an error if the client is not inside a repository or if it fails to determine that fact. Note that it can be anywhere in a repository, it doesn't need to be in the root.

func (*Repo) SourceContext

func (r *Repo) SourceContext() (*sous.SourceContext, error)

SourceContext gathers together a number of bits of information about the repository such as its current branch, revision, nearest tag, nearest semver tag, etc.

Jump to

Keyboard shortcuts

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