git

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package git wraps the handful of git commands live-pr needs by shelling out, rather than pulling in a full git library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CurrentBranch

func CurrentBranch() (string, error)

CurrentBranch returns the checked-out branch name (e.g. "main", "feature/x").

func DefaultBase

func DefaultBase() string

DefaultBase returns the branch to compare against: the remote's default (origin/HEAD, e.g. "origin/main") when known, else a local main/master, falling back to "main".

func FetchPull

func FetchPull(number int, base, expectedOID string) (string, error)

FetchPull fetches a GitHub pull ref and its base without changing HEAD, the index, or the worktree. It returns the namespaced local head ref.

func FileDiff

func FileDiff(base string, paths ...string) string

FileDiff returns the colorized base...HEAD patch for the selected paths.

func FileDiffRange

func FileDiffRange(base, head string, paths ...string) string

FileDiffRange returns the colorized base...head patch for selected paths.

func HasChanges

func HasChanges(base, head string) (bool, error)

HasChanges reports whether base...head contains any changed paths.

func HasUncommittedChanges

func HasUncommittedChanges() (bool, error)

HasUncommittedChanges reports whether the index, worktree, or untracked files differ from HEAD.

func MergeBase

func MergeBase(base, head string) (string, error)

MergeBase returns the best common ancestor of two revisions.

func Push

func Push(branch string) error

Push pushes the branch to origin, setting upstream.

func RepoRoot

func RepoRoot() (string, error)

RepoRoot returns the absolute path to the current repository's top level.

func ResolveBase

func ResolveBase(base string) string

ResolveBase turns a GitHub base name into the freshest local Git revision, preferring its origin remote-tracking ref when available.

func Show

func Show(sha string) string

Show returns the full `git show` for a commit (stat + colorized patch), capped to a sane number of lines. Empty string if the sha is unresolvable.

func ShowStat

func ShowStat(sha string) string

ShowStat returns `git show --stat` for a commit, colorized, with a compact author/date header. Empty string if the sha cannot be resolved.

Types

type ChangeStats

type ChangeStats struct {
	Files, Additions, Deletions int
}

ChangeStats summarizes a diff range for PR list metadata.

func DiffStats

func DiffStats(base, head string) (ChangeStats, error)

DiffStats returns file and line counts for base...head. Binary files count toward Files but not line totals.

type ChangedFile

type ChangedFile struct {
	Status  string
	Path    string
	OldPath string
}

ChangedFile is one entry in base...HEAD.

func ChangedFiles

func ChangedFiles(base string) ([]ChangedFile, error)

ChangedFiles returns changed paths in base...HEAD order.

func ChangedFilesRange

func ChangedFilesRange(base, head string) ([]ChangedFile, error)

ChangedFilesRange returns changed paths in base...head order.

type Commit

type Commit struct {
	SHA     string
	Date    string // "2006-01-02T15:04"
	Subject string
	Body    string
}

Commit is a git commit reduced to what the timeline needs.

func Commits

func Commits(base string) ([]Commit, error)

Commits returns the commits in base..HEAD, oldest first.

func CommitsRange

func CommitsRange(base, head string) ([]Commit, error)

CommitsRange returns commits in base..head, oldest first.

type MergeReadiness added in v0.2.0

type MergeReadiness struct {
	Behind        int
	ConflictFiles []string
}

MergeReadiness describes how far head trails base and which paths conflict.

func CheckMergeReadiness added in v0.2.0

func CheckMergeReadiness(base, head string) (MergeReadiness, error)

CheckMergeReadiness simulates merging head into base without touching HEAD, the index, or the worktree.

Jump to

Keyboard shortcuts

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