git

package
v4.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateBranchName

func ValidateBranchName(name string) error

ValidateBranchName checks if a name is valid for a git branch.

Types

type Commit

type Commit struct {
	Hash    string
	Subject string
	Author  string
}

Commit represents a git commit

type Git

type Git struct {
	RepoDir string
}

Git wraps git operations

func New

func New(repoDir string) *Git

New creates a new Git wrapper for the given repo directory

func (*Git) AddRemote

func (g *Git) AddRemote(name, url string) error

AddRemote adds a new git remote

func (*Git) BranchExists

func (g *Git) BranchExists(branch string) bool

BranchExists checks if a local branch exists

func (*Git) CheckoutBranch

func (g *Git) CheckoutBranch(branchName string) error

CheckoutBranch switches to an existing branch

func (*Git) CreateBranchOnly

func (g *Git) CreateBranchOnly(branchName, baseBranch string) error

CreateBranchOnly creates a new branch without a worktree

func (*Git) CreateWorktree

func (g *Git) CreateWorktree(branchName, worktreePath, baseBranch string) error

CreateWorktree creates a new worktree

func (*Git) CreateWorktreeFromRemoteBranch

func (g *Git) CreateWorktreeFromRemoteBranch(localBranch, worktreePath string) error

CreateWorktreeFromRemoteBranch creates a worktree for a remote branch with tracking. If the local branch already exists (and has no worktree), it is force-updated to match the remote. The resulting local branch tracks origin/<localBranch>.

func (*Git) CurrentBranch

func (g *Git) CurrentBranch() (string, error)

CurrentBranch returns the current branch name

func (*Git) DeleteBranch

func (g *Git) DeleteBranch(branchName string, force bool) error

DeleteBranch deletes a local git branch

func (*Git) Fetch

func (g *Git) Fetch() error

Fetch fetches from origin remote

func (*Git) FetchRemote

func (g *Git) FetchRemote(remote string) error

FetchRemote fetches from a specific remote

func (*Git) FindAnyEzstackStash

func (g *Git) FindAnyEzstackStash() (int, bool)

FindAnyEzstackStash returns the most recent stash entry tagged "ezstack-autostash" regardless of branch. Used only in the detached-HEAD fallback path where the current branch is unknown.

func (*Git) FindEzstackStash

func (g *Git) FindEzstackStash(branchName string) (int, bool)

FindEzstackStash finds the stash index of an ezstack autostash entry for a specific branch. Git stash entries look like: "stash@{N}: On <branch>: ezstack-autostash" Returns (index, true) if found, (-1, false) if not found. Matches both branch name and message to avoid touching stashes from other worktrees.

func (*Git) FindRemoteByOwner

func (g *Git) FindRemoteByOwner(owner string) (string, string, error)

FindRemoteByOwner finds a git remote that points to a repo owned by the given GitHub owner. Returns the remote name and URL, or empty strings if not found.

func (*Git) GetBranchCommit

func (g *Git) GetBranchCommit(branch string) (string, error)

GetBranchCommit gets the commit hash of a branch

func (*Git) GetCommitCount

func (g *Git) GetCommitCount(base, head string) (int, error)

GetCommitCount returns the number of commits between base and head This is useful to check if a branch has any commits of its own

func (*Git) GetCommitsAhead

func (g *Git) GetCommitsAhead(branch, target string) (int, error)

GetCommitsAhead returns the number of commits branch is ahead of target

func (*Git) GetCommitsBehind

func (g *Git) GetCommitsBehind(branch, target string) (int, error)

GetCommitsBehind returns the number of commits branch is behind target

func (*Git) GetCommitsBetween

func (g *Git) GetCommitsBetween(base, head string) ([]Commit, error)

GetCommitsBetween returns commits between base and head (exclusive of base)

func (*Git) GetDiffStat

func (g *Git) GetDiffStat(base, head string) (added int, removed int, err error)

GetDiffStat returns the total lines added and removed between base and head. Uses three-dot diff (merge-base) to show only changes introduced by head, not changes on base that head doesn't have.

func (*Git) GetLastCommitMessage

func (g *Git) GetLastCommitMessage() (string, error)

GetLastCommitMessage returns the message of the last commit on the current branch

func (*Git) GetMainWorktree

func (g *Git) GetMainWorktree() (string, error)

GetMainWorktree returns the path to the main worktree

func (*Git) GetMergeBase

func (g *Git) GetMergeBase(branch1, branch2 string) (string, error)

GetMergeBase finds the common ancestor between two branches

func (*Git) GetPRTemplate

func (g *Git) GetPRTemplate() string

GetPRTemplate finds and reads the GitHub PR template from common locations. Returns the template content or empty string if no template is found. GitHub looks for templates in these locations (in order of priority): - .github/pull_request_template.md - .github/PULL_REQUEST_TEMPLATE.md - docs/pull_request_template.md - pull_request_template.md - PULL_REQUEST_TEMPLATE.md

func (*Git) GetRemote

func (g *Git) GetRemote(name string) (string, error)

GetRemote gets the remote URL

func (*Git) GetRepoRoot

func (g *Git) GetRepoRoot() (string, error)

GetRepoRoot returns the root directory of the git repository

func (*Git) HasChanges

func (g *Git) HasChanges() (bool, error)

HasChanges returns true if the working directory has uncommitted changes

func (*Git) HasDivergedFromOrigin

func (g *Git) HasDivergedFromOrigin(branch string) (bool, int, int, error)

HasDivergedFromOrigin checks if local and remote branches have diverged Returns (hasDiverged, localAhead, remoteBehind, error) hasDiverged is true if both local has commits not in remote AND remote has commits not in local

func (*Git) HasUnresolvedConflicts

func (g *Git) HasUnresolvedConflicts() (bool, error)

HasUnresolvedConflicts checks if there are unresolved merge conflicts

func (*Git) IsBranchMerged

func (g *Git) IsBranchMerged(branch, target string) (bool, error)

IsBranchMerged checks if a branch has been merged into target

func (*Git) IsLocalAheadOfOrigin

func (g *Git) IsLocalAheadOfOrigin(branch string) (bool, error)

IsLocalAheadOfOrigin checks if the local branch has commits not in origin. Deprecated: Use IsLocalAheadOfRemote instead.

func (*Git) IsLocalAheadOfRemote

func (g *Git) IsLocalAheadOfRemote(branch string, remote string) (bool, error)

IsLocalAheadOfRemote checks if the local branch has commits not in the remote. If remote is empty, defaults to "origin". Returns true if local is ahead (needs push), false if in sync or behind.

func (*Git) IsMergeInProgress

func (g *Git) IsMergeInProgress() (bool, error)

IsMergeInProgress checks if a merge is in progress

func (*Git) IsRebaseInProgress

func (g *Git) IsRebaseInProgress() (bool, error)

IsRebaseInProgress checks if a rebase is in progress

func (*Git) ListLocalBranches

func (g *Git) ListLocalBranches() ([]string, error)

ListLocalBranches returns all local branch names

func (*Git) ListWorktrees

func (g *Git) ListWorktrees() ([]Worktree, error)

ListWorktrees lists all worktrees

func (*Git) Merge

func (g *Git) Merge(target string) error

Merge merges target into the current branch interactively

func (*Git) MergeContinue

func (g *Git) MergeContinue() error

MergeContinue continues a merge in progress (commits the resolved merge)

func (*Git) MergeNonInteractive

func (g *Git) MergeNonInteractive(target string) RebaseResult

MergeNonInteractive merges target into the current branch without interactive mode Returns structured result for conflict handling, matching RebaseResult for compatibility

func (*Git) PruneWorktrees

func (g *Git) PruneWorktrees() error

PruneWorktrees prunes stale worktree metadata from git

func (*Git) Push

func (g *Git) Push(force bool, remote ...string) error

Push pushes the current branch to the specified remote. If remote is empty, defaults to "origin".

func (*Git) PushBranch

func (g *Git) PushBranch(branch string, force bool, remote ...string) error

PushBranch pushes a specific branch to a remote (not necessarily the current branch). If remote is empty, defaults to "origin".

func (*Git) PushForce

func (g *Git) PushForce(remote ...string) error

PushForce force pushes the current branch with lease (safer than --force). If remote is empty, defaults to "origin".

func (*Git) PushSetUpstream

func (g *Git) PushSetUpstream(remote ...string) error

PushSetUpstream pushes and sets upstream. If remote is empty, defaults to "origin".

func (*Git) Rebase

func (g *Git) Rebase(target string) error

Rebase rebases current branch onto target

func (*Git) RebaseContinue

func (g *Git) RebaseContinue() error

RebaseContinue continues a rebase in progress

func (*Git) RebaseNonInteractive

func (g *Git) RebaseNonInteractive(target string) RebaseResult

RebaseNonInteractive rebases current branch onto target without interactive mode Returns structured result instead of just error for better conflict handling

func (*Git) RebaseOntoNonInteractive

func (g *Git) RebaseOntoNonInteractive(newBase, oldBase string) RebaseResult

RebaseOntoNonInteractive rebases commits from oldBase to current onto newBase Returns structured result for better conflict handling

func (*Git) RemoteBranchExists

func (g *Git) RemoteBranchExists(branch string) bool

RemoteBranchExists checks if a remote branch exists

func (*Git) RemoveWorktree

func (g *Git) RemoveWorktree(worktreePath string, deleteBranch bool, branchName string) error

RemoveWorktree removes a worktree and optionally deletes the branch

func (*Git) ResetHard

func (g *Git) ResetHard(ref string) error

ResetHard performs a hard reset to the given ref This is used to fast-forward a branch that has no commits of its own

func (*Git) RunCapture

func (g *Git) RunCapture(args ...string) (string, error)

run executes a git command and returns the output RunCapture executes a git command and returns stdout.

func (*Git) RunInteractive

func (g *Git) RunInteractive(args ...string) error

RunInteractive runs a git command interactively (for rebase with conflicts)

func (*Git) StashPop

func (g *Git) StashPop() error

StashPop pops the ezstack autostash entry for the current branch. Uses targeted lookup to avoid popping user stashes or stashes from other branches. Returns nil if no ezstack stash is found (nothing to pop).

func (*Git) StashPopIndex

func (g *Git) StashPopIndex(index int) error

StashPopIndex pops a specific stash entry by index.

func (*Git) StashPush

func (g *Git) StashPush() error

StashPush stashes all changes including untracked files

type RebaseResult

type RebaseResult struct {
	Success     bool
	HasConflict bool
	Error       error
}

RebaseResult contains the result of a rebase operation

type Worktree

type Worktree struct {
	Path   string
	Branch string
}

Worktree represents a git worktree

Jump to

Keyboard shortcuts

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