git

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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

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

BranchExists checks if a local branch exists

func (*Git) CreateWorktree

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

CreateWorktree creates a new worktree

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) 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) 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) 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) 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 Returns true if local is ahead (needs push), false if in sync or behind

func (*Git) IsRebaseInProgress

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

IsRebaseInProgress checks if a rebase is in progress

func (*Git) ListWorktrees

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

ListWorktrees lists all worktrees

func (*Git) PruneWorktrees

func (g *Git) PruneWorktrees() error

PruneWorktrees prunes stale worktree metadata from git

func (*Git) Push

func (g *Git) Push(force bool) error

Push pushes the current branch to remote

func (*Git) PushForce

func (g *Git) PushForce() error

PushForce force pushes the current branch with lease (safer than --force) Explicitly specifies origin and branch name to handle branches without upstream

func (*Git) PushSetUpstream

func (g *Git) PushSetUpstream() error

PushSetUpstream pushes and sets upstream

func (*Git) Rebase

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

Rebase rebases current branch onto target

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

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

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

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