model

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package model defines the internal value types shared across the git packages.

Types such as Oid, Reference, Signature, and Commit model core git objects independently of any backend so the higher-level git API and its adapters exchange a single representation.

Index

Constants

View Source
const DefaultBranch = "main"

DefaultBranch is the short branch name used for newly initialized repositories.

Variables

This section is empty.

Functions

func WithLogExtraArgs

func WithLogExtraArgs(args ...string) func(*LogOptions)

WithLogExtraArgs appends backend-specific raw log args.

Types

type BlameLine

type BlameLine struct {
	Line      int
	CommitOID Oid
	Author    Signature
	Content   string
}

BlameLine holds line-level attribution.

type BlameOption

type BlameOption func(*BlameOptions)

BlameOption configures blame behavior.

func WithBlameExtraArgs

func WithBlameExtraArgs(args ...string) BlameOption

WithBlameExtraArgs appends backend-specific raw blame args.

func WithIgnoreWhitespace

func WithIgnoreWhitespace(ignore bool) BlameOption

WithIgnoreWhitespace requests whitespace-insensitive blame when supported.

func WithLineRange

func WithLineRange(start, end int) BlameOption

WithLineRange limits blame results to the inclusive range [start, end].

type BlameOptions

type BlameOptions struct {
	StartLine        int
	EndLine          int
	IgnoreWhitespace bool
	ExtraArgs        []string
}

BlameOptions controls blame output.

type Branch

type Branch struct {
	Name     string
	Target   Oid
	Upstream string
}

Branch holds branch metadata.

type BranchFilter

type BranchFilter int

BranchFilter controls which branches to list.

const (
	LocalBranches BranchFilter = iota
	RemoteBranches
	AllBranches
)

type CheckoutOption

type CheckoutOption func(*CheckoutOptions)

CheckoutOption configures checkout behavior.

func WithCheckoutCreateBranch

func WithCheckoutCreateBranch(name string) CheckoutOption

WithCheckoutCreateBranch creates a new branch while checking out.

func WithCheckoutDetach

func WithCheckoutDetach(detach bool) CheckoutOption

WithCheckoutDetach detaches HEAD at the target revision.

func WithCheckoutExtraArgs

func WithCheckoutExtraArgs(args ...string) CheckoutOption

WithCheckoutExtraArgs appends backend-specific raw checkout args.

func WithCheckoutForce

func WithCheckoutForce(force bool) CheckoutOption

WithCheckoutForce forces checkout.

type CheckoutOptions

type CheckoutOptions struct {
	CreateBranch string
	Force        bool
	Detach       bool
	ExtraArgs    []string
}

CheckoutOptions controls checkout behavior.

type CherryPickOption

type CherryPickOption func(*CherryPickOptions)

CherryPickOption configures cherry-pick behavior.

func WithCherryPickExtraArgs

func WithCherryPickExtraArgs(args ...string) CherryPickOption

WithCherryPickExtraArgs appends backend-specific raw cherry-pick args.

func WithCherryPickMainline

func WithCherryPickMainline(mainline int) CherryPickOption

WithCherryPickMainline selects the mainline parent for merge commits.

func WithCherryPickNoCommit

func WithCherryPickNoCommit(noCommit bool) CherryPickOption

WithCherryPickNoCommit applies changes without creating a commit.

type CherryPickOptions

type CherryPickOptions struct {
	Mainline  int
	NoCommit  bool
	ExtraArgs []string
}

CherryPickOptions controls cherry-pick behavior.

type CleanOption

type CleanOption func(*CleanOptions)

CleanOption configures clean behavior.

func WithCleanDirectories

func WithCleanDirectories(directories bool) CleanOption

WithCleanDirectories includes untracked directories in clean operations.

func WithCleanExtraArgs

func WithCleanExtraArgs(args ...string) CleanOption

WithCleanExtraArgs appends backend-specific raw clean args.

func WithCleanForce

func WithCleanForce(force bool) CleanOption

WithCleanForce toggles destructive clean mode.

func WithCleanIgnored

func WithCleanIgnored(ignored bool) CleanOption

WithCleanIgnored includes ignored files in clean operations.

type CleanOptions

type CleanOptions struct {
	Directories bool
	Ignored     bool
	Force       bool
	ExtraArgs   []string
}

CleanOptions controls git clean behavior.

type Commit

type Commit struct {
	OID       Oid
	Author    Signature
	Committer Signature
	Message   string
	Parents   []Oid
}

Commit holds metadata for a git commit object.

type CommitOption

type CommitOption func(*CommitOptions)

CommitOption configures commit behavior.

func WithCommitAmend

func WithCommitAmend(amend bool) CommitOption

WithCommitAmend requests amending the current HEAD commit.

func WithCommitAuthor

func WithCommitAuthor(sig Signature) CommitOption

WithCommitAuthor sets the author signature for a commit.

func WithCommitCommitter

func WithCommitCommitter(sig Signature) CommitOption

WithCommitCommitter sets the committer signature for a commit.

func WithCommitExtraArgs

func WithCommitExtraArgs(args ...string) CommitOption

WithCommitExtraArgs appends backend-specific raw commit args.

func WithCommitSign

func WithCommitSign(sign bool) CommitOption

WithCommitSign requests commit signing.

type CommitOptions

type CommitOptions struct {
	Author    *Signature
	Committer *Signature
	Sign      bool
	Amend     bool
	ExtraArgs []string
}

CommitOptions controls commit creation.

type DescribeOption

type DescribeOption func(*DescribeOptions)

DescribeOption configures describe behavior.

func WithDescribeAbbreviated

func WithDescribeAbbreviated(abbreviated bool) DescribeOption

WithDescribeAbbreviated controls abbreviated fallback output.

func WithDescribeAlways

func WithDescribeAlways(always bool) DescribeOption

WithDescribeAlways requests fallback to an object name.

func WithDescribeAnnotatedTagsOnly

func WithDescribeAnnotatedTagsOnly(only bool) DescribeOption

WithDescribeAnnotatedTagsOnly limits describe to annotated tags.

func WithDescribeExtraArgs

func WithDescribeExtraArgs(args ...string) DescribeOption

WithDescribeExtraArgs appends backend-specific raw describe args.

func WithDescribeLong

func WithDescribeLong(long bool) DescribeOption

WithDescribeLong requests long describe output.

func WithDescribeMatch

func WithDescribeMatch(match string) DescribeOption

WithDescribeMatch restricts matching tags.

type DescribeOptions

type DescribeOptions struct {
	Match             string
	AnnotatedTagsOnly bool
	Long              bool
	Abbreviated       bool
	Always            bool
	ExtraArgs         []string
}

DescribeOptions controls git describe output.

type DiffEntry

type DiffEntry struct {
	Path    string
	OldPath string
	OldOID  Oid
	NewOID  Oid
	Status  FileStatus
}

DiffEntry represents a single file change between two refs.

type DiffOption

type DiffOption func(*DiffOptions)

DiffOption configures diff generation.

func WithDiffContext

func WithDiffContext(lines int) DiffOption

WithDiffContext sets the requested number of context lines.

func WithDiffExtraArgs

func WithDiffExtraArgs(args ...string) DiffOption

WithDiffExtraArgs appends backend-specific raw diff args.

func WithDiffNameOnly

func WithDiffNameOnly(nameOnly bool) DiffOption

WithDiffNameOnly requests name-only diff output when supported.

type DiffOptions

type DiffOptions struct {
	ContextLines int
	NameOnly     bool
	ExtraArgs    []string
}

DiffOptions controls diff generation.

type DiffStats

type DiffStats struct {
	Additions    int
	Deletions    int
	FilesChanged int
}

DiffStats aggregates diff statistics.

type EntryKind

type EntryKind int

EntryKind describes the type of a tree entry.

const (
	EntryKindBlob EntryKind = iota
	EntryKindTree
	EntryKindSubmodule
)

func (EntryKind) String

func (k EntryKind) String() string

type EntryState

type EntryState int

EntryState describes a file's state in the working tree or index.

const (
	Staged EntryState = iota
	Unstaged
	Untracked
	Conflicted
)

func (EntryState) String

func (s EntryState) String() string

type FetchOption

type FetchOption func(*FetchOptions)

FetchOption configures fetch behavior.

func WithFetchDepth

func WithFetchDepth(depth int) FetchOption

WithFetchDepth sets fetch depth.

func WithFetchExtraArgs

func WithFetchExtraArgs(args ...string) FetchOption

WithFetchExtraArgs appends backend-specific raw fetch args.

func WithFetchPrune

func WithFetchPrune(prune bool) FetchOption

WithFetchPrune sets whether fetch prunes stale remote-tracking refs.

func WithFetchRefspecs

func WithFetchRefspecs(refspecs ...string) FetchOption

WithFetchRefspecs sets fetch refspecs.

type FetchOptions

type FetchOptions struct {
	Prune     bool
	Depth     int
	Refspecs  []string
	ExtraArgs []string
}

FetchOptions controls fetch behavior.

type FileStatus

type FileStatus int

FileStatus describes how a file changed in a diff.

const (
	FileAdded FileStatus = iota
	FileModified
	FileDeleted
	FileRenamed
	FileCopied
	FileUntracked
	FileIgnored
	FileTypeChanged
	FileConflicted
)

func (FileStatus) String

func (s FileStatus) String() string

type GrepMatch

type GrepMatch struct {
	Path    string
	Line    int
	Content string
}

GrepMatch represents a single grep match.

type GrepOption

type GrepOption func(*GrepOptions)

GrepOption configures grep behavior.

func WithGrepExtraArgs

func WithGrepExtraArgs(args ...string) GrepOption

WithGrepExtraArgs appends backend-specific raw grep args.

func WithGrepIgnoreCase

func WithGrepIgnoreCase(ignore bool) GrepOption

WithGrepIgnoreCase toggles case-insensitive matching.

func WithGrepLineNumbers

func WithGrepLineNumbers(enabled bool) GrepOption

WithGrepLineNumbers toggles line-number output when supported.

func WithGrepPathspecs

func WithGrepPathspecs(pathspecs ...string) GrepOption

WithGrepPathspecs restricts grep to the provided paths.

type GrepOptions

type GrepOptions struct {
	Pathspecs   []string
	IgnoreCase  bool
	LineNumbers bool
	ExtraArgs   []string
}

GrepOptions controls git grep behavior.

type LogOptions

type LogOptions struct {
	MaxCount     int
	PathFilter   string
	AuthorFilter string
	Since        *time.Time
	Until        *time.Time
	ExtraArgs    []string
}

LogOptions controls log traversal.

type MergeOption

type MergeOption func(*MergeOptions)

MergeOption configures merge behavior.

func WithMergeCommit

func WithMergeCommit(commit bool) MergeOption

WithMergeCommit toggles automatic merge commit creation.

func WithMergeExtraArgs

func WithMergeExtraArgs(args ...string) MergeOption

WithMergeExtraArgs appends backend-specific raw merge args.

func WithMergeFFOnly

func WithMergeFFOnly(ffOnly bool) MergeOption

WithMergeFFOnly requests fast-forward-only merges.

func WithMergeMessage

func WithMergeMessage(message string) MergeOption

WithMergeMessage sets the merge commit message.

func WithMergeNoFastForward

func WithMergeNoFastForward(noFF bool) MergeOption

WithMergeNoFastForward requests a merge commit even when fast-forward is possible.

func WithMergeSquash

func WithMergeSquash(squash bool) MergeOption

WithMergeSquash requests squash merge behavior.

type MergeOptions

type MergeOptions struct {
	Commit        bool
	FFOnly        bool
	NoFastForward bool
	Squash        bool
	Message       string
	ExtraArgs     []string
}

MergeOptions controls merge behavior.

type MergeResult

type MergeResult struct {
	Merged      bool
	Head        Oid
	FastForward bool
	Conflicts   []string
}

MergeResult summarizes a merge operation.

type Oid

type Oid [20]byte

Oid represents a Git object ID (SHA-1 hash).

func (Oid) IsZero

func (o Oid) IsZero() bool

IsZero reports whether o is the zero OID.

func (Oid) String

func (o Oid) String() string

String returns the hex-encoded OID.

type OpenOptions

type OpenOptions struct {
	PreferCLI bool
	CLIPath   string
	Transport gitauth.Transport
	Signing   gitauth.Signing
	ExtraArgs []string
}

OpenOptions controls repository construction and backend selection.

func ApplyOptions

func ApplyOptions(opts ...Option) *OpenOptions

ApplyOptions materializes constructor options.

type Option

type Option func(*OpenOptions)

Option configures repository construction behavior.

func WithCLIPath

func WithCLIPath(path string) Option

WithCLIPath sets the git executable path used by the CLI backend.

func WithExtraArgs

func WithExtraArgs(args ...string) Option

WithExtraArgs appends raw CLI args for backends that support them.

func WithPreferCLI

func WithPreferCLI(prefer bool) Option

WithPreferCLI requests CLI-backed operations where available.

func WithSigning

func WithSigning(signing gitauth.Signing) Option

WithSigning sets the signing configuration used by write operations when supported.

func WithTransport

func WithTransport(transport gitauth.Transport) Option

WithTransport sets the transport auth configuration used by clone/fetch/push operations.

type PushOption

type PushOption func(*PushOptions)

PushOption configures push behavior.

func WithPushExtraArgs

func WithPushExtraArgs(args ...string) PushOption

WithPushExtraArgs appends backend-specific raw push args.

func WithPushForce

func WithPushForce(force bool) PushOption

WithPushForce sets whether push is forced.

func WithPushRefspecs

func WithPushRefspecs(refspecs ...string) PushOption

WithPushRefspecs sets push refspecs.

type PushOptions

type PushOptions struct {
	Force     bool
	Refspecs  []string
	ExtraArgs []string
}

PushOptions controls push behavior.

type RebaseOption

type RebaseOption func(*RebaseOptions)

RebaseOption configures rebase behavior.

func WithRebaseAutosquash

func WithRebaseAutosquash(autosquash bool) RebaseOption

WithRebaseAutosquash toggles autosquash behavior.

func WithRebaseExtraArgs

func WithRebaseExtraArgs(args ...string) RebaseOption

WithRebaseExtraArgs appends backend-specific raw rebase args.

func WithRebaseInteractive

func WithRebaseInteractive(interactive bool) RebaseOption

WithRebaseInteractive toggles interactive rebase mode.

type RebaseOptions

type RebaseOptions struct {
	Interactive bool
	Autosquash  bool
	ExtraArgs   []string
}

RebaseOptions controls rebase behavior.

type RebaseResult

type RebaseResult struct {
	Complete  bool
	Head      Oid
	Applied   int
	Conflicts []string
}

RebaseResult summarizes a rebase operation.

type Reference

type Reference struct {
	Name     string
	Target   Oid
	IsBranch bool
	IsTag    bool
}

Reference represents a git ref (branch, tag, or HEAD).

type Remote

type Remote struct {
	Name       string
	URL        string
	FetchSpecs []string
	PushSpecs  []string
}

Remote holds remote repository metadata.

type ResetMode

type ResetMode int

ResetMode describes reset behavior.

const (
	ResetMixed ResetMode = iota
	ResetSoft
	ResetHard
)

func (ResetMode) String

func (m ResetMode) String() string

type SignFormat

type SignFormat int

SignFormat identifies the object-signing backend git should use.

const (
	SignFormatDefault SignFormat = iota
	SignFormatOpenPGP
	SignFormatSSH
	SignFormatX509
)

func (SignFormat) GitConfig

func (f SignFormat) GitConfig() string

GitConfig returns the value accepted by git's gpg.format configuration.

type SignOptions

type SignOptions struct {
	Format SignFormat
	Key    string
}

SignOptions controls signed tag creation.

type Signature

type Signature struct {
	Name  string
	Email string
	When  time.Time
}

Signature holds author or committer identity.

type StashEntry

type StashEntry struct {
	Index   int
	Name    string
	Message string
	Commit  Oid
}

StashEntry represents a stash reference.

type StatusEntry

type StatusEntry struct {
	Path  string
	State EntryState
}

StatusEntry represents a file's status in the working tree.

type Tag

type Tag struct {
	Name    string
	Target  Oid
	Tagger  *Signature
	Message string
}

Tag holds tag metadata.

type TreeEntry

type TreeEntry struct {
	Name     string
	OID      Oid
	Kind     EntryKind
	Filemode uint32
}

TreeEntry represents an entry within a git tree object.

type TreeHash

type TreeHash = Oid

TreeHash is the OID of a tree object for content-addressed comparison.

Jump to

Keyboard shortcuts

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