git

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: BlueOak-1.0.0 Imports: 9 Imported by: 0

Documentation

Overview

internal/git/git.go

Index

Constants

This section is empty.

Variables

View Source
var ErrDirtyWorkTree = errors.New("working tree has uncommitted changes")

ErrDirtyWorkTree is returned when the working tree has uncommitted changes.

Functions

This section is empty.

Types

type Commit

type Commit struct {
	Subject string // First line of the commit message
	Body    string // Everything after the first line (may be empty)
}

Commit represents a git commit with its subject and body.

type Git

type Git struct {
	// contains filtered or unexported fields
}

Git provides git operations for a repository.

func New

func New(repoPath string) *Git

New creates a Git instance for the repository at the given path.

func (*Git) BranchExists

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

BranchExists checks if a branch exists.

func (*Git) Checkout

func (g *Git) Checkout(branch string) error

Checkout switches to the specified branch.

func (*Git) Commit

func (g *Git) Commit(message string) error

Commit creates a commit with the given message.

func (*Git) CommitExists

func (g *Git) CommitExists(sha string) bool

CommitExists checks if a commit SHA exists in the repository.

func (*Git) CreateAndCheckout

func (g *Git) CreateAndCheckout(name string) error

CreateAndCheckout creates a new branch and switches to it.

func (*Git) CreateBranch

func (g *Git) CreateBranch(name string) error

CreateBranch creates a new branch at the current HEAD.

func (*Git) CurrentBranch

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

CurrentBranch returns the name of the current branch.

func (*Git) DeleteBranch

func (g *Git) DeleteBranch(branch string) error

DeleteBranch deletes a local branch.

func (*Git) FastForward

func (g *Git) FastForward(branch string) error

FastForward fast-forwards a branch to its remote tracking branch.

func (*Git) Fetch

func (g *Git) Fetch() error

Fetch fetches from origin.

func (*Git) GetCommits

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

GetCommits returns the commits from base..head (commits in head not in base). Returns commits in reverse chronological order (newest first).

func (*Git) GetGitDir

func (g *Git) GetGitDir() string

GetGitDir returns the .git directory path.

func (*Git) GetMergeBase

func (g *Git) GetMergeBase(a, b string) (string, error)

GetMergeBase returns the merge base of two branches.

func (*Git) GetTip

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

GetTip returns the commit SHA at the tip of a branch.

func (*Git) HasStagedChanges

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

HasStagedChanges returns true if there are staged changes.

func (*Git) HasUnmergedCommits

func (g *Git) HasUnmergedCommits(branch, upstream string) (bool, error)

HasUnmergedCommits returns true if the branch has commits not yet in upstream. Uses git cherry to detect by diff content, which works for cherry-picks where the commit SHAs differ but the content is the same. Note: This does NOT detect squash merges where multiple commits are combined. Use IsContentMerged for squash merge detection.

func (*Git) IsContentMerged

func (g *Git) IsContentMerged(branch, upstream string) (bool, error)

IsContentMerged returns true if the branch has no content differences from upstream. This detects squash merges where the tree content is identical even though the commit history differs. Returns true if `git diff upstream branch` is empty.

func (*Git) IsDirty

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

IsDirty returns true if there are uncommitted changes (staged or unstaged).

func (*Git) IsRebaseInProgress

func (g *Git) IsRebaseInProgress() bool

IsRebaseInProgress checks if a rebase is in progress.

func (*Git) NeedsRebase

func (g *Git) NeedsRebase(branch, parent string) (bool, error)

NeedsRebase returns true if branch needs to be rebased onto parent.

func (*Git) Push

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

Push force-pushes a branch to origin with lease.

func (*Git) Rebase

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

Rebase rebases the current branch onto target.

func (*Git) RebaseAbort

func (g *Git) RebaseAbort() error

RebaseAbort aborts an in-progress rebase.

func (*Git) RebaseContinue

func (g *Git) RebaseContinue() error

RebaseContinue continues an in-progress rebase.

func (*Git) RebaseOnto

func (g *Git) RebaseOnto(newBase, oldBase, branch string) error

RebaseOnto rebases a branch onto a new base, replaying only commits after oldBase. Checks out the branch first, then runs: git rebase --onto <newBase> <oldBase> Useful when a parent branch was squash-merged and we need to replay only the commits unique to the child branch.

func (*Git) RemoteBranchExists

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

RemoteBranchExists checks if a branch exists on the remote (origin).

Jump to

Keyboard shortcuts

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