Documentation ¶
Index ¶
- Constants
- func ShortSha(sha string) string
- func StderrMatches(err error, target string) bool
- type CheckoutBranch
- type CommitInfo
- type CommitInfoOpts
- type Diff
- type DiffOpts
- type GetRefs
- type GetRefsItem
- type ListRefs
- type MergeBase
- type Origin
- type Output
- type RebaseOpts
- type RebaseResult
- type RebaseStatus
- type RefInfo
- type Repo
- func (r *Repo) CheckCleanWorkdir() (bool, error)
- func (r *Repo) CheckoutBranch(opts *CheckoutBranch) (string, error)
- func (r *Repo) CommitInfo(opts CommitInfoOpts) (*CommitInfo, error)
- func (r *Repo) CurrentBranchName() (string, error)
- func (r *Repo) DefaultBranch() (string, error)
- func (r *Repo) Diff(d *DiffOpts) (*Diff, error)
- func (r *Repo) Dir() string
- func (r *Repo) GetRefs(opts *GetRefs) ([]*GetRefsItem, error)
- func (r *Repo) Git(args ...string) (string, error)
- func (r *Repo) GitDir() string
- func (r *Repo) GitStdin(args []string, stdin io.Reader) (string, error)
- func (r *Repo) HasChangesToBeCommitted() (bool, error)
- func (r *Repo) ListRefs(showRef *ListRefs) ([]RefInfo, error)
- func (r *Repo) MergeBase(mb *MergeBase) (string, error)
- func (r *Repo) Origin() (*Origin, error)
- func (r *Repo) Rebase(opts RebaseOpts) (*Output, error)
- func (r *Repo) RebaseParse(opts RebaseOpts) (*RebaseResult, error)
- func (r *Repo) RevList(opts RevListOpts) ([]string, error)
- func (r *Repo) RevParse(rp *RevParse) (string, error)
- func (r *Repo) Run(opts *RunOpts) (*Output, error)
- func (r *Repo) UpdateRef(update *UpdateRef) error
- type RevListOpts
- type RevParse
- type RunOpts
- type UpdateRef
- type UpstreamStatus
Constants ¶
const ( TypeCommit = "commit" TypeTree = "tree" TypeBlob = "blob" TypeTag = "tag" )
The various types of objects in git.
const Missing = "0000000000000000000000000000000000000000"
Missing is a sentinel zero-value for object id (aka sha). Git treats this value as "this thing doesn't exist". For example, when updating a ref, if the old value is specified as EmptyOid, Git will refuse to update the ref if already exists.
Variables ¶
This section is empty.
Functions ¶
func StderrMatches ¶ added in v0.0.6
Types ¶
type CheckoutBranch ¶
type CheckoutBranch struct { // The name of the branch to checkout. Name string // Specifies the "-b" flag to git. // The checkout will fail if the branch already exists. NewBranch bool // Specifies the ref that new branch will have HEAD at // Requires the "-b" flag to be specified NewHeadRef string }
type CommitInfo ¶
type CommitInfoOpts ¶
type CommitInfoOpts struct {
Rev string
}
type DiffOpts ¶
type DiffOpts struct { // If specified, generate the diff between the working tree and this commit. // If empty (default), generates the diff between the working tree and the // current index (i.e., the diff containing all unstaged changes). Commit string // If true, don't actually generate the diff, just return whether or not its // empty. If set, Diff.Contents will always be an empty string. Quiet bool }
type GetRefsItem ¶
type RebaseOpts ¶ added in v0.0.4
type RebaseOpts struct { // Required (unless Continue is true) // The upstream branch to rebase onto. Upstream string // Optional (mutually exclusive with all other options) // If set, continue a rebase (all other options are ignored). Continue bool // Optional (mutually exclusive with all other options) Abort bool // Optional // If set, use `git rebase --onto <upstream> ...` Onto string // Optional // If set, this is the branch that will be rebased; otherwise, the current // branch is rebased. Branch string }
type RebaseResult ¶ added in v0.0.8
type RebaseResult struct { Status RebaseStatus Hint string // The "headline" of the error message (if any) ErrorHeadline string }
type RebaseStatus ¶ added in v0.0.8
type RebaseStatus int
const ( RebaseAlreadyUpToDate RebaseStatus = iota RebaseUpdated RebaseStatus = iota RebaseConflict RebaseStatus = iota RebaseNotInProgress RebaseStatus = iota // RebaseAborted indicates that an in-progress rebase was aborted. // Only returned if Rebase was called with Abort: true. RebaseAborted RebaseStatus = iota )
type RefInfo ¶
type RefInfo struct { Name string Type string Oid string // The name of the upstream ref (e.g., refs/remotes/<remote>/<branch>) Upstream string // The status of the ref relative to the upstream. UpstreamStatus UpstreamStatus }
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
func (*Repo) CheckCleanWorkdir ¶ added in v0.0.12
CheckCleanWorkdir returns if the workdir is clean.
func (*Repo) CheckoutBranch ¶
func (r *Repo) CheckoutBranch(opts *CheckoutBranch) (string, error)
CheckoutBranch performs a checkout of the given branch and returns the name of the previous branch, if any (this can be used to restore the previous branch if necessary). The returned previous branch name may be empty if the repo is currently not checked out to a branch (i.e., in detached HEAD state).
func (*Repo) CommitInfo ¶
func (r *Repo) CommitInfo(opts CommitInfoOpts) (*CommitInfo, error)
func (*Repo) CurrentBranchName ¶
CurrentBranchName returns the name of the current branch. The name is return in "short" format -- i.e., without the "refs/heads/" prefix. IMPORTANT: This function will return an error if the repository is currently in a detached-head state (e.g., during a rebase conflict).
func (*Repo) DefaultBranch ¶
func (*Repo) GetRefs ¶
func (r *Repo) GetRefs(opts *GetRefs) ([]*GetRefsItem, error)
GetRefs reads the contents of the specified objects from the repository. This corresponds to the `git cat-file --batch` command.
func (*Repo) HasChangesToBeCommitted ¶ added in v0.0.12
HasChangesToBeCommitted returns if there's a staged changes to be committed.
func (*Repo) ListRefs ¶
ListRefs lists all refs in the repository (optionally matching a specific pattern).
func (*Repo) RebaseParse ¶ added in v0.0.8
func (r *Repo) RebaseParse(opts RebaseOpts) (*RebaseResult, error)
RebaseParse runs a `git rebase` and parses the output into a RebaseResult.
type RevListOpts ¶ added in v0.0.5
type RevListOpts struct { // A list of commit roots, or exclusions if the commit sha starts with a // caret (^). As a special case, "foo..bar" is equivalent to "foo ^bar" // which means every commit reachable from foo but not from bar. // For example, to list all of the commits introduced in a pull request, // the specifier would be "HEAD..master". // See `git rev-list --help`. Specifiers []string // If true, display the commits in chronological order. Reverse bool }
type RunOpts ¶
type RunOpts struct { Args []string Env []string // If true, return a non-nil error if the command exited with a non-zero // exit code. ExitError bool // If true, the standard I/Os are connected to the console, allowing the git command to // interact with the user. Stdout and Stderr will be empty. Interactive bool }
type UpdateRef ¶
type UpdateRef struct { // The name of the ref (e.g., refs/heads/my-branch). Ref string // The Git object ID to set the ref to. New string // Only update the ref if the current value (before the update) is equal to // this object ID. Use Missing to only create the ref if it didn't // already exists (e.g., to avoid overwriting a branch). Old string // Create a reflog for this ref change. CreateReflog bool }
type UpstreamStatus ¶
type UpstreamStatus string
UpstreamStatus is the status of a git ref (usually a branch) relative to its upstream.
const ( Ahead UpstreamStatus = ">" Behind UpstreamStatus = "<" Divergent UpstreamStatus = "<>" InSync UpstreamStatus = "=" )
The possible upstream statuses. These match what is returned by Git's `%(upstream:trackshort)` format directive.