git

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package git shells out to the system git binary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StackParentConfigKey

func StackParentConfigKey(branch string) string

StackParentConfigKey is the git config key for an explicit stack parent.

Types

type RemoteRelation

type RemoteRelation string

RemoteRelation describes local tip vs origin/<branch>.

const (
	RelNone     RemoteRelation = "none"
	RelInSync   RemoteRelation = "in-sync"
	RelBehind   RemoteRelation = "behind"
	RelAhead    RemoteRelation = "ahead"
	RelDiverged RemoteRelation = "diverged"
)

type Repo

type Repo struct {
	// Dir is the working tree path. Empty means current directory.
	Dir string
}

Repo is a git repository working directory.

func (*Repo) Config

func (r *Repo) Config(key, value string) error

Config sets a local git config key.

func (*Repo) ConfigGet

func (r *Repo) ConfigGet(key string) string

ConfigGet returns a local config value, or "" if unset.

func (*Repo) ConfigUnset

func (r *Repo) ConfigUnset(key string) error

ConfigUnset removes a local config key (no error if missing).

func (*Repo) CurrentBranch

func (r *Repo) CurrentBranch() (string, error)

CurrentBranch returns the current branch name (fails on detached HEAD).

func (*Repo) DefaultBranch

func (r *Repo) DefaultBranch() string

DefaultBranch returns the trunk branch name (origin/HEAD, else main/master).

func (*Repo) DeleteBranch

func (r *Repo) DeleteBranch(name string) error

DeleteBranch runs git branch -d (safe; refuses unmerged).

func (*Repo) FFBranch

func (r *Repo) FFBranch(branch string) error

FFBranch fast-forwards local branch to origin/<branch>.

func (*Repo) FetchOrigin

func (r *Repo) FetchOrigin() error

FetchOrigin runs git fetch origin (no-op if no origin).

func (*Repo) ForceDeleteBranch

func (r *Repo) ForceDeleteBranch(name string) error

ForceDeleteBranch runs git branch -D (force local delete).

func (*Repo) GetStackParent

func (r *Repo) GetStackParent(branch string) string

GetStackParent reads branch.<name>.gitstack-parent.

func (*Repo) GitDir

func (r *Repo) GitDir() (string, error)

GitDir returns the absolute path to .git (or common dir).

func (*Repo) HasOrigin

func (r *Repo) HasOrigin() bool

HasOrigin reports whether remote "origin" is configured.

func (*Repo) IsAncestor

func (r *Repo) IsAncestor(ancestor, descendant string) bool

IsAncestor reports whether ancestor is an ancestor of descendant.

func (*Repo) ListRefTips added in v0.1.2

func (r *Repo) ListRefTips(prefix string) (map[string]string, error)

ListRefTips returns ref short-name → full object id for refs under prefix (e.g. "refs/heads/", "refs/remotes/origin/"). One git process.

func (*Repo) ListStackParentConfig added in v0.1.2

func (r *Repo) ListStackParentConfig() (map[string]string, error)

ListStackParentConfig returns branch → gitstack-parent from local config. One git process: git config --get-regexp.

func (*Repo) LocalBranchExists

func (r *Repo) LocalBranchExists(name string) bool

LocalBranchExists checks refs/heads/<name>.

func (*Repo) LocalBranches

func (r *Repo) LocalBranches() ([]string, error)

LocalBranches lists short names under refs/heads/.

func (*Repo) MergeBase

func (r *Repo) MergeBase(a, b string) (string, error)

MergeBase returns the merge-base of two revs.

func (*Repo) MergeBaseForkPoint

func (r *Repo) MergeBaseForkPoint(parentRef, branchRef string) (string, error)

MergeBaseForkPoint returns git merge-base --fork-point result, or error.

func (*Repo) OriginBranchExists

func (r *Repo) OriginBranchExists(name string) bool

OriginBranchExists checks refs/remotes/origin/<name>.

func (*Repo) PushForceWithLease

func (r *Repo) PushForceWithLease(branch string) error

PushForceWithLease pushes branch with --force-with-lease.

func (*Repo) PushUpstream

func (r *Repo) PushUpstream(branch string) error

PushUpstream sets upstream and pushes.

func (*Repo) RebaseOnto

func (r *Repo) RebaseOnto(onto, upstream, branch string) error

RebaseOnto runs: git rebase --onto onto upstream branch

func (*Repo) RebaseOntoOrigin

func (r *Repo) RebaseOntoOrigin(branch string) error

RebaseOntoOrigin rebases branch onto origin/<branch> (pull --rebase). When branch is not HEAD, git checks it out first.

func (*Repo) RebaseOntoQuiet

func (r *Repo) RebaseOntoQuiet(onto, upstream, branch string) error

RebaseOntoQuiet runs rebase without attaching to terminal (for tests).

func (*Repo) RefExists

func (r *Repo) RefExists(name string) bool

RefExists reports whether name resolves.

func (*Repo) RemoteRelationOf

func (r *Repo) RemoteRelationOf(branch string) RemoteRelation

RemoteRelationOf classifies local vs origin for a local branch.

func (*Repo) RequireClean

func (r *Repo) RequireClean() error

RequireClean fails if tracked/staged changes exist (untracked OK).

func (*Repo) RequireNoRebase

func (r *Repo) RequireNoRebase() error

RequireNoRebase fails if a rebase is in progress.

func (*Repo) RequireRepo

func (r *Repo) RequireRepo() error

RequireRepo dies if not inside a git repository.

func (*Repo) ResolveRef

func (r *Repo) ResolveRef(name string) (string, error)

ResolveRef prefers local heads, then origin/, then the name as-is.

func (*Repo) RevListCount

func (r *Repo) RevListCount(revRange string) (int, error)

RevListCount counts commits in range (exclusive..inclusive style args).

func (*Repo) RevListOneline

func (r *Repo) RevListOneline(revRange string) (string, error)

RevListOneline returns oneline log for a range.

func (*Repo) RevParse

func (r *Repo) RevParse(rev string) (string, error)

RevParse returns the full SHA for a rev.

func (*Repo) RunInteractive

func (r *Repo) RunInteractive(args ...string) error

RunInteractive runs git with the caller's stdout/stderr (for rebase UX).

func (*Repo) SetStackParent

func (r *Repo) SetStackParent(branch, parent string) error

SetStackParent writes branch.<name>.gitstack-parent.

func (*Repo) ShortSHA

func (r *Repo) ShortSHA(rev string) (string, error)

ShortSHA returns a short object name.

func (*Repo) StatusPorcelainUno

func (r *Repo) StatusPorcelainUno() (string, error)

StatusPorcelainUno returns porcelain status for tracked files only (-uno).

func (*Repo) Switch

func (r *Repo) Switch(name string) error

Switch checks out an existing branch.

func (*Repo) SwitchCreate

func (r *Repo) SwitchCreate(name, startRef string) error

SwitchCreate creates and checks out a new branch from startRef.

func (*Repo) UnsetStackParent

func (r *Repo) UnsetStackParent(branch string) error

UnsetStackParent clears branch.<name>.gitstack-parent.

Jump to

Keyboard shortcuts

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