Documentation
¶
Index ¶
- type CommitInfo
- type FileStatus
- type Git
- func (g *Git) AbsPath(rel string) string
- func (g *Git) Add(paths ...string) error
- func (g *Git) AddAll() error
- func (g *Git) BranchList() ([]string, error)
- func (g *Git) CheckoutBranch(name string, create bool) error
- func (g *Git) Commit(message string) error
- func (g *Git) CommitStaged(message string) (string, error)
- func (g *Git) CommitWithFiles(message string, paths ...string) (string, error)
- func (g *Git) ConfigUser(name, email string) error
- func (g *Git) CountCommits(startHash, endHash string) (int, error)
- func (g *Git) CreateBranch(name string) error
- func (g *Git) CurrentBranch() (string, error)
- func (g *Git) Diff(target ...string) (string, error)
- func (g *Git) DiffFile(path string, status string) (string, error)
- func (g *Git) DiffRefs(ref1, ref2 string) (string, error)
- func (g *Git) DiffStaged() (string, error)
- func (g *Git) DiffStat(target ...string) (string, error)
- func (g *Git) Fetch(remote string) error
- func (g *Git) HasUncommittedChanges() (bool, error)
- func (g *Git) HeadHash() (string, error)
- func (g *Git) Init() error
- func (g *Git) IsDirty() (bool, error)
- func (g *Git) IsRepo() bool
- func (g *Git) Log(lastN int) ([]CommitInfo, error)
- func (g *Git) LogAll() ([]CommitInfo, error)
- func (g *Git) LogSince(since time.Time) ([]CommitInfo, error)
- func (g *Git) Merge(branch string) error
- func (g *Git) Pull(remote, branch string, rebase bool) error
- func (g *Git) Push(remote, branch string) error
- func (g *Git) RemoteTracking() (string, error)
- func (g *Git) ResetHard(commit string) error
- func (g *Git) ResetSoft(commit string) error
- func (g *Git) RevParse(ref string) (string, error)
- func (g *Git) Run(args ...string) (string, error)
- func (g *Git) StashApply(index int) error
- func (g *Git) StashList() ([]string, error)
- func (g *Git) StashPop() error
- func (g *Git) StashPush(message string) error
- func (g *Git) Status() (string, error)
- func (g *Git) StatusPorcelain() ([]FileStatus, error)
- func (g *Git) Tag(name, msg string) error
- func (g *Git) WorkDir() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommitInfo ¶
type CommitInfo = types.CommitInfo
CommitInfo is a type alias for the canonical definition in internal/types.
type FileStatus ¶
type FileStatus struct {
Status string // e.g. "M", "A", "D", "R", "C", "U", "?"
Path string
OldPath string // for renames
Additions int
Deletions int
}
FileStatus represents a single file's git status.
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git wraps git operations for a working directory.
func (*Git) AbsPath ¶
AbsPath returns the absolute path for a relative path within the working directory.
func (*Git) BranchList ¶
BranchList returns a list of local branches.
func (*Git) CheckoutBranch ¶
CheckoutBranch checks out a branch, optionally creating it.
func (*Git) Commit ¶
Commit stages all changes and creates a commit with the given message. WARNING: This stages the entire worktree. Use CommitWithFiles or CommitStaged for scoped commits.
func (*Git) CommitStaged ¶
CommitStaged creates a commit from already-staged changes only. Does not stage any additional files.
func (*Git) CommitWithFiles ¶
CommitWithFiles stages and commits only the given paths with the given message. Returns the commit hash on success.
func (*Git) ConfigUser ¶
ConfigUser sets the git user name and email for the repository.
func (*Git) CountCommits ¶
CountCommits returns the number of commits between two hashes using `git rev-list --count`. startHash is the older commit, endHash the newer.
func (*Git) CreateBranch ¶
CreateBranch creates a new branch with the given name.
func (*Git) CurrentBranch ¶
CurrentBranch returns the name of the current branch.
func (*Git) Diff ¶
Diff returns git diff output based on the number of target refs provided:
- 0 args: unstaged working-tree diff (plain `git diff`)
- 1 arg: diff between target and HEAD
- 2 args: diff between the two refs
func (*Git) DiffFile ¶
DiffFile returns the diff for a single file. For untracked files ("?"), it returns the file contents as an "added" diff. For staged files it uses --cached; otherwise it shows unstaged working-tree changes.
func (*Git) DiffRefs ¶
DiffRefs returns the diff between two refs. If both refs are empty, it runs plain `git diff` to show unstaged working-tree changes. If only ref2 is empty, it produces "ref1.." which in git means "changes reachable from ref1 that are not in the current working tree state" — callers that want the contents of a single commit should pass ref1^ and ref1 explicitly.
func (*Git) DiffStaged ¶
DiffStaged returns the diff of staged but uncommitted changes.
func (*Git) DiffStat ¶
DiffStat returns diff stat (summary) based on the number of target refs provided.
func (*Git) HasUncommittedChanges ¶
HasUncommittedChanges returns true if the working tree has uncommitted changes (modified, staged, untracked, or deleted files).
func (*Git) Log ¶
func (g *Git) Log(lastN int) ([]CommitInfo, error)
Log returns the lastN commits (newest first). If lastN <= 0, returns all.
func (*Git) LogAll ¶
func (g *Git) LogAll() ([]CommitInfo, error)
LogAll returns full commit history (newest first).
func (*Git) LogSince ¶
func (g *Git) LogSince(since time.Time) ([]CommitInfo, error)
LogSince returns commits since the given time (newest first).
func (*Git) RemoteTracking ¶
RemoteTracking returns the remote tracking branch, e.g. "origin/main". Returns empty string if no upstream is configured.
func (*Git) ResetHard ¶
ResetHard resets HEAD to the given commit, discarding all changes. Creates a backup branch for rollback safety.
func (*Git) ResetSoft ¶
ResetSoft resets HEAD to the given commit, keeping changes staged. Creates a backup branch for rollback safety.
func (*Git) Run ¶
Run executes a git command and returns the output. This is the exported version of run for commands not covered by specific wrapper methods.
func (*Git) StashApply ¶
StashApply applies a stash entry by index (0 = most recent).
func (*Git) StatusPorcelain ¶
func (g *Git) StatusPorcelain() ([]FileStatus, error)
StatusPorcelain returns structured git status for the working directory. Uses git status --porcelain (v1 format): "XY path" per line. Runs status and numstat concurrently for better performance (PERF-32).