Help us shape the future of Go! Take the 2026 Go Developer Survey

git

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveConflict added in v0.2.1

func ResolveConflict(path, side string) error

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

func NewClient(startPath string) (*Client, error)

NewClient creates a Client for the repository containing startPath. It walks up the directory tree looking for a .git directory.

func (*Client) AddRemote added in v0.2.1

func (c *Client) AddRemote(name, url string) error

AddRemote adds a new named remote.

func (*Client) AddWorktree

func (c *Client) AddWorktree(path, branch string, newBranch bool) error

AddWorktree creates a new worktree at path for the given branch.

func (*Client) AheadBehind

func (c *Client) AheadBehind() (ahead, behind int, err error)

AheadBehind returns the number of commits ahead/behind the upstream for HEAD.

func (*Client) BisectBad added in v0.2.1

func (c *Client) BisectBad(hash string) error

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

func (c *Client) BisectGood(hash string) error

BisectGood marks a commit as good. If hash is "", marks HEAD good.

func (*Client) BisectInProgress added in v0.2.1

func (c *Client) BisectInProgress() bool

BisectInProgress returns true if a bisect session is active.

func (*Client) BisectLog added in v0.2.1

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

BisectLog returns the bisect log lines.

func (*Client) BisectReset added in v0.2.1

func (c *Client) BisectReset() error

BisectReset ends the bisect session and returns to the original branch.

func (*Client) BisectSkip added in v0.2.1

func (c *Client) BisectSkip() error

BisectSkip skips the current commit.

func (*Client) BisectStart added in v0.2.1

func (c *Client) BisectStart() error

BisectStart begins a bisect session.

func (*Client) Blame

func (c *Client) Blame(path string) ([]BlameLine, error)

Blame returns annotated blame information for a file.

func (*Client) BlameAt

func (c *Client) BlameAt(hash, path string) ([]BlameLine, error)

BlameAt returns blame for a specific commit version of a file.

func (*Client) Branches

func (c *Client) Branches() ([]Branch, error)

Branches returns all local branches.

func (*Client) BranchesWithTracking

func (c *Client) BranchesWithTracking() ([]Branch, error)

BranchesWithTracking returns branches with ahead/behind counts vs upstream.

func (*Client) Checkout

func (c *Client) Checkout(name string) error

Checkout switches to the named branch.

func (*Client) CherryPick added in v0.2.1

func (c *Client) CherryPick(hash string) error

CherryPick applies the commit with the given hash to the current branch.

func (*Client) CherryPickAbort added in v0.2.1

func (c *Client) CherryPickAbort() error

CherryPickAbort aborts an in-progress cherry-pick.

func (*Client) Commit

func (c *Client) Commit(message string) error

Commit creates a commit with the given message.

func (*Client) CommitAmend

func (c *Client) CommitAmend(message string) error

CommitAmend amends the last commit with the current index and optional new message.

func (*Client) CommitDetail

func (c *Client) CommitDetail(hash string) (*Commit, error)

CommitDetail returns a single commit's full info including body.

func (*Client) ContinueRebase added in v0.2.1

func (c *Client) ContinueRebase() error

ContinueRebase continues an in-progress rebase.

func (*Client) CreateAnnotatedTag added in v0.2.1

func (c *Client) CreateAnnotatedTag(name, message string) error

CreateAnnotatedTag creates an annotated tag at HEAD with a message.

func (*Client) CreateBranch

func (c *Client) CreateBranch(name string) error

CreateBranch creates and switches to a new branch from HEAD.

func (*Client) CreateTag added in v0.2.1

func (c *Client) CreateTag(name string) error

CreateTag creates a lightweight tag at HEAD.

func (*Client) CurrentBranch

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

CurrentBranch returns the name of the currently checked-out branch.

func (*Client) DeleteBranch

func (c *Client) DeleteBranch(name string) error

DeleteBranch deletes a local branch (must be fully merged).

func (*Client) DeleteRemoteBranch added in v0.2.1

func (c *Client) DeleteRemoteBranch(remote, branch string) error

DeleteRemoteBranch deletes a remote-tracking branch.

func (*Client) DeleteRemoteTag added in v0.2.1

func (c *Client) DeleteRemoteTag(remote, name string) error

DeleteRemoteTag deletes a tag from the remote.

func (*Client) DeleteTag added in v0.2.1

func (c *Client) DeleteTag(name string) error

DeleteTag deletes a local tag.

func (*Client) Diff

func (c *Client) Diff(path string, staged bool) ([]DiffHunk, error)

Diff returns the diff for a specific file. If staged is true, shows staged changes (--cached). Otherwise working-tree changes.

func (*Client) DiffAll

func (c *Client) DiffAll(staged bool) ([]FileDiff, error)

DiffAll returns the full diff for all changed files.

func (*Client) DiffCommit

func (c *Client) DiffCommit(hash string) ([]FileDiff, error)

DiffCommit returns the diff introduced by a specific commit.

func (*Client) DiscardFile

func (c *Client) DiscardFile(path string) error

DiscardFile discards all unstaged changes in a file (restores from HEAD).

func (*Client) Fetch

func (c *Client) Fetch() error

Fetch fetches from all remotes.

func (*Client) FetchRemote added in v0.2.1

func (c *Client) FetchRemote(name string) error

FetchRemote fetches a specific remote by name.

func (*Client) ForceDeleteBranch

func (c *Client) ForceDeleteBranch(name string) error

ForceDeleteBranch deletes a local branch regardless of merge status.

func (*Client) ForceRemoveWorktree

func (c *Client) ForceRemoveWorktree(path string) error

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) Log

func (c *Client) Log(limit int) ([]Commit, error)

Log returns the commit history for the current branch.

func (*Client) LogFile added in v0.2.1

func (c *Client) LogFile(path string, limit int) ([]Commit, error)

LogFile returns commits that touched a specific file path.

func (*Client) LogGraph

func (c *Client) LogGraph(limit int) ([]string, error)

LogGraph returns formatted commit graph output for rendering.

func (*Client) MarkResolved added in v0.2.1

func (c *Client) MarkResolved(path string) error

MarkResolved stages the file (marks it resolved in git index).

func (*Client) MergeAbort added in v0.2.1

func (c *Client) MergeAbort() error

MergeAbort aborts an in-progress merge.

func (*Client) MergeBranch added in v0.2.1

func (c *Client) MergeBranch(name string) error

MergeBranch merges the named branch into the current branch.

func (*Client) MergeInProgress added in v0.2.1

func (c *Client) MergeInProgress() bool

MergeInProgress returns true if a merge is currently in progress.

func (*Client) OriginURL

func (c *Client) OriginURL() string

OriginURL returns the URL of the "origin" remote, or "" if none.

func (*Client) Pull

func (c *Client) Pull() error

Pull fetches and merges the upstream branch.

func (*Client) Push

func (c *Client) Push() error

Push pushes the current branch to its upstream remote.

func (*Client) PushForceWithLease added in v0.2.1

func (c *Client) PushForceWithLease(remote, branch string) error

PushForceWithLease pushes with --force-with-lease (safe force push for rebased branches).

func (*Client) PushSetUpstream

func (c *Client) PushSetUpstream(remote, branch string) error

PushSetUpstream pushes and sets upstream for new branches.

func (*Client) PushTag added in v0.2.1

func (c *Client) PushTag(remote, name string) error

PushTag pushes a tag to the remote.

func (*Client) RebaseAbort added in v0.2.1

func (c *Client) RebaseAbort() error

RebaseAbort aborts an in-progress rebase.

func (*Client) RebaseBranch added in v0.2.1

func (c *Client) RebaseBranch(target string) error

RebaseBranch rebases the current branch onto the named target.

func (*Client) RebaseContinue added in v0.2.1

func (c *Client) RebaseContinue() error

RebaseContinue continues an in-progress rebase.

func (*Client) RebaseInProgress added in v0.2.1

func (c *Client) RebaseInProgress() bool

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

func (c *Client) ReflogUndo(ref string) error

ReflogUndo resets HEAD to the given reflog entry (mixed reset).

func (*Client) RemoteURL

func (c *Client) RemoteURL(name string) (string, error)

RemoteURL returns the URL for the named remote (e.g. "origin").

func (*Client) Remotes

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

Remotes returns a list of configured remotes.

func (*Client) RemoveRemote added in v0.2.1

func (c *Client) RemoveRemote(name string) error

RemoveRemote removes a remote by name.

func (*Client) RemoveWorktree

func (c *Client) RemoveWorktree(path string) error

RemoveWorktree removes the worktree at the given path.

func (*Client) RenameBranch

func (c *Client) RenameBranch(newName string) error

RenameBranch renames the current branch.

func (*Client) RenameRemote added in v0.2.1

func (c *Client) RenameRemote(oldName, newName string) error

RenameRemote renames a remote.

func (*Client) RepoName

func (c *Client) RepoName() string

RepoName returns the base directory name of the repository.

func (*Client) ResetHard added in v0.2.1

func (c *Client) ResetHard(ref string) error

ResetHard moves HEAD to ref, discarding all staged and unstaged changes.

func (*Client) ResetMixed added in v0.2.1

func (c *Client) ResetMixed(ref string) error

ResetMixed moves HEAD to ref, unstaging changes but keeping working tree.

func (*Client) ResetSoft added in v0.2.1

func (c *Client) ResetSoft(ref string) error

ResetSoft moves HEAD to ref, keeping staged and working-tree changes.

func (*Client) RevertCommit added in v0.2.1

func (c *Client) RevertCommit(hash string) error

RevertCommit creates a new commit that undoes the changes from hash.

func (*Client) RunPublic added in v0.2.1

func (c *Client) RunPublic(args ...string) (string, error)

RunPublic exposes run for use in packages that wrap Client. Use sparingly.

func (*Client) Stage

func (c *Client) Stage(paths ...string) error

Stage adds the given file paths to the index.

func (*Client) StageAll

func (c *Client) StageAll() error

StageAll stages all changes including untracked files.

func (*Client) StageHunk

func (c *Client) StageHunk(patch string) error

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

func (c *Client) StashApply(ref string) error

StashApply applies a stash entry without dropping it.

func (*Client) StashDrop

func (c *Client) StashDrop(ref string) error

StashDrop drops a stash entry by ref.

func (*Client) StashList

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

StashList returns all stash entries.

func (*Client) StashPop

func (c *Client) StashPop() error

StashPop applies and drops the top stash entry.

func (*Client) StashPush

func (c *Client) StashPush(message string) error

StashPush creates a new stash entry with an optional message.

func (*Client) StashShow

func (c *Client) StashShow(ref string) ([]FileDiff, error)

StashShow returns the diff for a stash entry.

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

func (c *Client) Tags() ([]Tag, error)

Tags returns all local tags sorted by creation date descending.

func (*Client) Unstage

func (c *Client) Unstage(paths ...string) error

Unstage removes the given file paths from the index (keeps working tree).

func (*Client) UnstageAll

func (c *Client) UnstageAll() error

UnstageAll removes all staged changes from the index.

func (*Client) UnstageHunk

func (c *Client) UnstageHunk(patch string) error

UnstageHunk reverses a specific diff hunk from the index.

func (*Client) Worktrees

func (c *Client) Worktrees() ([]Worktree, error)

Worktrees returns all worktrees for this repository.

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

type RemoteEntry struct {
	Name     string
	FetchURL string
	PushURL  string
}

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 = ' '
)

type Tag added in v0.2.1

type Tag struct {
	Name        string
	Hash        string
	ShortHash   string
	Date        time.Time
	Message     string // for annotated tags
	IsAnnotated bool
}

Tag represents a git tag.

type Worktree

type Worktree struct {
	Path     string
	Branch   string
	Head     string
	IsBare   bool
	IsMain   bool
	IsLocked bool
}

Worktree represents a git worktree.

Jump to

Keyboard shortcuts

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