Documentation
¶
Index ¶
- func ResolveConflict(path, side string) error
- func WriteRebaseTodo(todoPath string, entries []RebaseTodoEntry) error
- type BisectStatus
- type BlameLine
- type Branch
- type Client
- func (c *Client) AddRemote(name, url string) error
- func (c *Client) AddWorktree(path, branch string, newBranch bool) error
- func (c *Client) AheadBehind() (ahead, behind int, err error)
- func (c *Client) BisectBad(hash string) error
- func (c *Client) BisectGetStatus() BisectStatus
- func (c *Client) BisectGood(hash string) error
- func (c *Client) BisectInProgress() bool
- func (c *Client) BisectLog() ([]string, error)
- func (c *Client) BisectReset() error
- func (c *Client) BisectSkip() error
- func (c *Client) BisectStart() error
- func (c *Client) Blame(path string) ([]BlameLine, error)
- func (c *Client) BlameAt(hash, path string) ([]BlameLine, error)
- func (c *Client) Branches() ([]Branch, error)
- func (c *Client) BranchesWithTracking() ([]Branch, error)
- func (c *Client) Checkout(name string) error
- func (c *Client) CherryPick(hash string) error
- func (c *Client) CherryPickAbort() error
- func (c *Client) Commit(message string) error
- func (c *Client) CommitAmend(message string) error
- func (c *Client) CommitDetail(hash string) (*Commit, error)
- func (c *Client) ContinueRebase() error
- func (c *Client) CreateAnnotatedTag(name, message string) error
- func (c *Client) CreateBranch(name string) error
- func (c *Client) CreateTag(name string) error
- func (c *Client) CurrentBranch() (string, error)
- func (c *Client) DeleteBranch(name string) error
- func (c *Client) DeleteRemoteBranch(remote, branch string) error
- func (c *Client) DeleteRemoteTag(remote, name string) error
- func (c *Client) DeleteTag(name string) error
- func (c *Client) Diff(path string, staged bool) ([]DiffHunk, error)
- func (c *Client) DiffAll(staged bool) ([]FileDiff, error)
- func (c *Client) DiffCommit(hash string) ([]FileDiff, error)
- func (c *Client) DiscardFile(path string) error
- func (c *Client) Fetch() error
- func (c *Client) FetchRemote(name string) error
- func (c *Client) ForceDeleteBranch(name string) error
- func (c *Client) ForceRemoveWorktree(path string) error
- func (c *Client) ListRemotes() ([]RemoteEntry, error)
- func (c *Client) Log(limit int) ([]Commit, error)
- func (c *Client) LogFile(path string, limit int) ([]Commit, error)
- func (c *Client) LogGraph(limit int) ([]string, error)
- func (c *Client) MarkResolved(path string) error
- func (c *Client) MergeAbort() error
- func (c *Client) MergeBranch(name string) error
- func (c *Client) MergeInProgress() bool
- func (c *Client) OriginURL() string
- func (c *Client) Pull() error
- func (c *Client) Push() error
- func (c *Client) PushForceWithLease(remote, branch string) error
- func (c *Client) PushSetUpstream(remote, branch string) error
- func (c *Client) PushTag(remote, name string) error
- func (c *Client) RebaseAbort() error
- func (c *Client) RebaseBranch(target string) error
- func (c *Client) RebaseContinue() error
- func (c *Client) RebaseInProgress() bool
- func (c *Client) Reflog(limit int) ([]ReflogEntry, error)
- func (c *Client) ReflogUndo(ref string) error
- func (c *Client) RemoteURL(name string) (string, error)
- func (c *Client) Remotes() ([]string, error)
- func (c *Client) RemoveRemote(name string) error
- func (c *Client) RemoveWorktree(path string) error
- func (c *Client) RenameBranch(newName string) error
- func (c *Client) RenameRemote(oldName, newName string) error
- func (c *Client) RepoName() string
- func (c *Client) ResetHard(ref string) error
- func (c *Client) ResetMixed(ref string) error
- func (c *Client) ResetSoft(ref string) error
- func (c *Client) RevertCommit(hash string) error
- func (c *Client) RunPublic(args ...string) (string, error)
- func (c *Client) Stage(paths ...string) error
- func (c *Client) StageAll() error
- func (c *Client) StageHunk(patch string) error
- func (c *Client) StartInteractiveRebase(upstream string) ([]RebaseTodoEntry, string, error)
- func (c *Client) StashApply(ref string) error
- func (c *Client) StashDrop(ref string) error
- func (c *Client) StashList() ([]string, error)
- func (c *Client) StashPop() error
- func (c *Client) StashPush(message string) error
- func (c *Client) StashShow(ref string) ([]FileDiff, error)
- func (c *Client) Stashes() ([]StashEntry, error)
- func (c *Client) Status() ([]FileStatus, error)
- func (c *Client) Tags() ([]Tag, error)
- func (c *Client) Unstage(paths ...string) error
- func (c *Client) UnstageAll() error
- func (c *Client) UnstageHunk(patch string) error
- func (c *Client) Worktrees() ([]Worktree, error)
- type Commit
- type ConflictBlock
- type DiffHunk
- type DiffLine
- type DiffLineType
- type FileDiff
- type FileStatus
- type RebaseTodoAction
- type RebaseTodoEntry
- type ReflogEntry
- type RemoteEntry
- type StashEntry
- type StatusCode
- type Tag
- type Worktree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResolveConflict ¶ added in v0.2.1
ResolveConflict resolves a conflict in a file by choosing "ours" or "theirs". side must be "ours" or "theirs".
func WriteRebaseTodo ¶ added in v0.2.1
func WriteRebaseTodo(todoPath string, entries []RebaseTodoEntry) error
WriteRebaseTodo writes updated entries back to the todo file.
Types ¶
type BisectStatus ¶ added in v0.2.1
type BisectStatus struct {
InProgress bool
CurrentHash string // the commit bisect is currently testing
GoodCount int
BadCount int
Log []string // recent bisect log lines
}
BisectStatus holds the current state of a git bisect session.
type BlameLine ¶
type BlameLine struct {
Hash string
ShortHash string
Author string
Date time.Time
LineNum int
Content string
IsFirst bool // first line attributed to this commit in the block
}
BlameLine is a single line of git blame output.
type Branch ¶
type Branch struct {
Name string
IsCurrent bool
IsRemote bool
Upstream string
Ahead int
Behind int
}
Branch represents a git branch.
type Client ¶
type Client struct {
RepoPath string
}
Client wraps git command execution for a specific repository.
func NewClient ¶
NewClient creates a Client for the repository containing startPath. It walks up the directory tree looking for a .git directory.
func (*Client) AddWorktree ¶
AddWorktree creates a new worktree at path for the given branch.
func (*Client) AheadBehind ¶
AheadBehind returns the number of commits ahead/behind the upstream for HEAD.
func (*Client) BisectBad ¶ added in v0.2.1
BisectBad marks a commit as bad. If hash is "", marks HEAD bad.
func (*Client) BisectGetStatus ¶ added in v0.2.1
func (c *Client) BisectGetStatus() BisectStatus
BisectGetStatus returns a snapshot of the current bisect state.
func (*Client) BisectGood ¶ added in v0.2.1
BisectGood marks a commit as good. If hash is "", marks HEAD good.
func (*Client) BisectInProgress ¶ added in v0.2.1
BisectInProgress returns true if a bisect session is active.
func (*Client) BisectReset ¶ added in v0.2.1
BisectReset ends the bisect session and returns to the original branch.
func (*Client) BisectSkip ¶ added in v0.2.1
BisectSkip skips the current commit.
func (*Client) BisectStart ¶ added in v0.2.1
BisectStart begins a bisect session.
func (*Client) BranchesWithTracking ¶
BranchesWithTracking returns branches with ahead/behind counts vs upstream.
func (*Client) CherryPick ¶ added in v0.2.1
CherryPick applies the commit with the given hash to the current branch.
func (*Client) CherryPickAbort ¶ added in v0.2.1
CherryPickAbort aborts an in-progress cherry-pick.
func (*Client) CommitAmend ¶
CommitAmend amends the last commit with the current index and optional new message.
func (*Client) CommitDetail ¶
CommitDetail returns a single commit's full info including body.
func (*Client) ContinueRebase ¶ added in v0.2.1
ContinueRebase continues an in-progress rebase.
func (*Client) CreateAnnotatedTag ¶ added in v0.2.1
CreateAnnotatedTag creates an annotated tag at HEAD with a message.
func (*Client) CreateBranch ¶
CreateBranch creates and switches to a new branch from HEAD.
func (*Client) CurrentBranch ¶
CurrentBranch returns the name of the currently checked-out branch.
func (*Client) DeleteBranch ¶
DeleteBranch deletes a local branch (must be fully merged).
func (*Client) DeleteRemoteBranch ¶ added in v0.2.1
DeleteRemoteBranch deletes a remote-tracking branch.
func (*Client) DeleteRemoteTag ¶ added in v0.2.1
DeleteRemoteTag deletes a tag from the remote.
func (*Client) Diff ¶
Diff returns the diff for a specific file. If staged is true, shows staged changes (--cached). Otherwise working-tree changes.
func (*Client) DiffCommit ¶
DiffCommit returns the diff introduced by a specific commit.
func (*Client) DiscardFile ¶
DiscardFile discards all unstaged changes in a file (restores from HEAD).
func (*Client) FetchRemote ¶ added in v0.2.1
FetchRemote fetches a specific remote by name.
func (*Client) ForceDeleteBranch ¶
ForceDeleteBranch deletes a local branch regardless of merge status.
func (*Client) ForceRemoveWorktree ¶
ForceRemoveWorktree forcibly removes a worktree (even if dirty).
func (*Client) ListRemotes ¶ added in v0.2.1
func (c *Client) ListRemotes() ([]RemoteEntry, error)
ListRemotes returns all configured remotes with their URLs.
func (*Client) MarkResolved ¶ added in v0.2.1
MarkResolved stages the file (marks it resolved in git index).
func (*Client) MergeAbort ¶ added in v0.2.1
MergeAbort aborts an in-progress merge.
func (*Client) MergeBranch ¶ added in v0.2.1
MergeBranch merges the named branch into the current branch.
func (*Client) MergeInProgress ¶ added in v0.2.1
MergeInProgress returns true if a merge is currently in progress.
func (*Client) PushForceWithLease ¶ added in v0.2.1
PushForceWithLease pushes with --force-with-lease (safe force push for rebased branches).
func (*Client) PushSetUpstream ¶
PushSetUpstream pushes and sets upstream for new branches.
func (*Client) RebaseAbort ¶ added in v0.2.1
RebaseAbort aborts an in-progress rebase.
func (*Client) RebaseBranch ¶ added in v0.2.1
RebaseBranch rebases the current branch onto the named target.
func (*Client) RebaseContinue ¶ added in v0.2.1
RebaseContinue continues an in-progress rebase.
func (*Client) RebaseInProgress ¶ added in v0.2.1
RebaseInProgress returns true if a rebase is currently in progress.
func (*Client) Reflog ¶
func (c *Client) Reflog(limit int) ([]ReflogEntry, error)
Reflog returns the reflog for HEAD.
func (*Client) ReflogUndo ¶
ReflogUndo resets HEAD to the given reflog entry (mixed reset).
func (*Client) RemoveRemote ¶ added in v0.2.1
RemoveRemote removes a remote by name.
func (*Client) RemoveWorktree ¶
RemoveWorktree removes the worktree at the given path.
func (*Client) RenameBranch ¶
RenameBranch renames the current branch.
func (*Client) RenameRemote ¶ added in v0.2.1
RenameRemote renames a remote.
func (*Client) ResetHard ¶ added in v0.2.1
ResetHard moves HEAD to ref, discarding all staged and unstaged changes.
func (*Client) ResetMixed ¶ added in v0.2.1
ResetMixed moves HEAD to ref, unstaging changes but keeping working tree.
func (*Client) ResetSoft ¶ added in v0.2.1
ResetSoft moves HEAD to ref, keeping staged and working-tree changes.
func (*Client) RevertCommit ¶ added in v0.2.1
RevertCommit creates a new commit that undoes the changes from hash.
func (*Client) RunPublic ¶ added in v0.2.1
RunPublic exposes run for use in packages that wrap Client. Use sparingly.
func (*Client) StageHunk ¶
StageHunk applies a specific diff hunk to the index via stdin. patch should be a valid unified diff patch string.
func (*Client) StartInteractiveRebase ¶ added in v0.2.1
func (c *Client) StartInteractiveRebase(upstream string) ([]RebaseTodoEntry, string, error)
StartInteractiveRebase begins an interactive rebase using a passthrough sequence editor, then reads the generated todo file.
func (*Client) StashApply ¶
StashApply applies a stash entry without dropping it.
func (*Client) Stashes ¶
func (c *Client) Stashes() ([]StashEntry, error)
Stashes returns all stash entries.
func (*Client) Status ¶
func (c *Client) Status() ([]FileStatus, error)
Status returns all modified/staged/untracked files using porcelain v1 format.
func (*Client) Tags ¶ added in v0.2.1
Tags returns all local tags sorted by creation date descending.
func (*Client) UnstageAll ¶
UnstageAll removes all staged changes from the index.
func (*Client) UnstageHunk ¶
UnstageHunk reverses a specific diff hunk from the index.
type Commit ¶
type Commit struct {
Hash string
ShortHash string
Author string
AuthorEmail string
Date time.Time
Subject string
Body string
Refs []string // branch names and tags pointing here
}
Commit represents a single git commit.
type ConflictBlock ¶ added in v0.2.1
type ConflictBlock struct {
OursLines []string
TheirsLines []string
Start int // line index of <<<<<<< marker
End int // line index of >>>>>>> marker
}
ConflictBlock represents a single conflict hunk in a file.
func ConflictedFile ¶ added in v0.2.1
func ConflictedFile(path string) ([]ConflictBlock, []string, error)
ConflictedFile reads a file and returns its conflict blocks.
type DiffHunk ¶
type DiffHunk struct {
Header string // e.g. "@@ -1,5 +1,7 @@ func foo()"
OldStart int
OldCount int
NewStart int
NewCount int
Lines []DiffLine
}
DiffHunk is a contiguous block of changes in a diff.
type DiffLine ¶
type DiffLine struct {
Type DiffLineType
Content string
OldLine int // line number in original file (0 = not applicable)
NewLine int // line number in new file (0 = not applicable)
}
DiffLine is a single line in a diff.
type DiffLineType ¶
type DiffLineType int
DiffLineType describes the kind of change a diff line represents.
const ( DiffContext DiffLineType = iota DiffAdded DiffRemoved DiffHunkHeader DiffFileHeader )
type FileDiff ¶
type FileDiff struct {
OldPath string
NewPath string
Hunks []DiffHunk
IsNew bool
IsDeleted bool
IsBinary bool
}
FileDiff contains all hunks for a single file.
type FileStatus ¶
type FileStatus struct {
Staged StatusCode // X - index status
Unstaged StatusCode // Y - worktree status
Path string
OldPath string // populated for renamed files
}
FileStatus represents a file's status in the working tree.
func (FileStatus) IsConflicted ¶
func (f FileStatus) IsConflicted() bool
IsConflicted returns true if the file has merge conflicts.
func (FileStatus) IsStaged ¶
func (f FileStatus) IsStaged() bool
IsStaged returns true if the file has staged changes.
func (FileStatus) IsUnstaged ¶
func (f FileStatus) IsUnstaged() bool
IsUnstaged returns true if the file has unstaged changes.
func (FileStatus) IsUntracked ¶
func (f FileStatus) IsUntracked() bool
IsUntracked returns true if the file is untracked.
type RebaseTodoAction ¶ added in v0.2.1
type RebaseTodoAction string
RebaseTodoAction represents an action in a rebase todo list.
const ( RebasePick RebaseTodoAction = "pick" RebaseReword RebaseTodoAction = "reword" RebaseSquash RebaseTodoAction = "squash" RebaseFixup RebaseTodoAction = "fixup" RebaseDrop RebaseTodoAction = "drop" )
type RebaseTodoEntry ¶ added in v0.2.1
type RebaseTodoEntry struct {
Action RebaseTodoAction
Hash string
Subject string
}
RebaseTodoEntry is one line in the interactive rebase todo file.
func (*RebaseTodoEntry) CycleAction ¶ added in v0.2.1
func (e *RebaseTodoEntry) CycleAction()
CycleAction cycles through rebase actions in order.
type ReflogEntry ¶
type ReflogEntry struct {
Hash string
ShortHash string
Ref string // e.g. "HEAD@{0}"
Action string // e.g. "commit", "checkout", "rebase"
Subject string
Date time.Time
}
ReflogEntry represents a single reflog entry.
type RemoteEntry ¶ added in v0.2.1
RemoteEntry holds full details for a single git remote.
type StashEntry ¶
type StashEntry struct {
Index int
Ref string // e.g. "stash@{0}"
Branch string // branch stash was created from
Message string
Date time.Time
}
StashEntry represents a single stash.
type StatusCode ¶
type StatusCode rune
StatusCode represents a single-character git status code.
const ( Modified StatusCode = 'M' Added StatusCode = 'A' Deleted StatusCode = 'D' Renamed StatusCode = 'R' Copied StatusCode = 'C' Untracked StatusCode = '?' Unmerged StatusCode = 'U' Ignored StatusCode = '!' None StatusCode = ' ' )