Documentation
¶
Overview ¶
Package git implements a thin Git adapter that shells out to the `git` CLI via os/exec. Every operation is repository-scoped (no global state) and can optionally publish events through the provided Event Bus.
Copyright 2026 The GOT Authors. MIT License.
Copyright 2026 The GOT Authors. MIT License.
Copyright 2026 The GOT Authors. MIT License.
Index ¶
- type Branch
- type Commit
- type ExecAdapter
- func (a *ExecAdapter) AddRemote(ctx context.Context, name, url string) error
- func (a *ExecAdapter) CheckoutBranch(ctx context.Context, name string) error
- func (a *ExecAdapter) CreateBranch(ctx context.Context, name string) error
- func (a *ExecAdapter) CreateCommit(ctx context.Context, message, author string) (string, error)
- func (a *ExecAdapter) CurrentBranch(ctx context.Context) (string, error)
- func (a *ExecAdapter) DeleteBranch(ctx context.Context, name string, force bool) error
- func (a *ExecAdapter) GetCommitHistory(ctx context.Context, branch string, limit int) ([]Commit, error)
- func (a *ExecAdapter) GetGraph(ctx context.Context, branch string, maxCount int) ([]GraphNode, error)
- func (a *ExecAdapter) GetRemotes(ctx context.Context) ([]Remote, error)
- func (a *ExecAdapter) GetStatus(ctx context.Context) (*Status, error)
- func (a *ExecAdapter) ListBranches(ctx context.Context) ([]Branch, error)
- func (a *ExecAdapter) OpenRepository(ctx context.Context, path string) error
- func (a *ExecAdapter) Pull(ctx context.Context, remote, branch string) (*PullResult, error)
- func (a *ExecAdapter) Push(ctx context.Context, remote, branch string, force bool) (*PushResult, error)
- func (a *ExecAdapter) RemoveRemote(ctx context.Context, name string) error
- func (a *ExecAdapter) Root() string
- func (a *ExecAdapter) Run(ctx context.Context, args ...string) (string, string, error)
- type GitAdapter
- type GraphNode
- type PullResult
- type PushResult
- type Remote
- type Status
- type StatusEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Branch ¶
type Branch struct {
Name string `json:"name"`
Current bool `json:"current"`
Remote bool `json:"remote"`
SHA string `json:"sha,omitempty"`
Upstream string `json:"upstream,omitempty"`
}
Branch represents a Git branch.
type Commit ¶
type Commit struct {
SHA string `json:"sha"`
Message string `json:"message"`
Author string `json:"author"`
Date string `json:"date"`
Refs string `json:"refs,omitempty"` // branch/tag decorations
}
Commit represents a single commit in the history.
type ExecAdapter ¶
type ExecAdapter struct {
// contains filtered or unexported fields
}
ExecAdapter shells out to the `git` CLI. It is repository-scoped: the repo path is set at construction or via OpenRepository.
func NewExecAdapter ¶
func NewExecAdapter(bus *events.Bus) *ExecAdapter
NewExecAdapter creates a Git adapter backed by the `git` CLI. The bus may be nil, in which case events are silently dropped.
func (*ExecAdapter) AddRemote ¶
func (a *ExecAdapter) AddRemote(ctx context.Context, name, url string) error
AddRemote adds a new remote.
func (*ExecAdapter) CheckoutBranch ¶
func (a *ExecAdapter) CheckoutBranch(ctx context.Context, name string) error
CheckoutBranch switches to a branch.
func (*ExecAdapter) CreateBranch ¶
func (a *ExecAdapter) CreateBranch(ctx context.Context, name string) error
CreateBranch creates a new branch at HEAD.
func (*ExecAdapter) CreateCommit ¶
CreateCommit creates a commit with the given message and optional author. Author defaults to Git config if empty.
func (*ExecAdapter) CurrentBranch ¶
func (a *ExecAdapter) CurrentBranch(ctx context.Context) (string, error)
CurrentBranch returns the current branch name, or "HEAD" when detached.
func (*ExecAdapter) DeleteBranch ¶
DeleteBranch removes a branch. If force is true, uses -D.
func (*ExecAdapter) GetCommitHistory ¶
func (a *ExecAdapter) GetCommitHistory(ctx context.Context, branch string, limit int) ([]Commit, error)
GetCommitHistory returns commits for a branch (or all if empty).
func (*ExecAdapter) GetGraph ¶
func (a *ExecAdapter) GetGraph(ctx context.Context, branch string, maxCount int) ([]GraphNode, error)
GetGraph returns the commit graph structure for visualisation. Uses git log --graph format to get parent-child relationships.
func (*ExecAdapter) GetRemotes ¶
func (a *ExecAdapter) GetRemotes(ctx context.Context) ([]Remote, error)
GetRemotes lists all configured remotes.
func (*ExecAdapter) GetStatus ¶
func (a *ExecAdapter) GetStatus(ctx context.Context) (*Status, error)
GetStatus parses `git status --porcelain` to produce a structured Status.
func (*ExecAdapter) ListBranches ¶
func (a *ExecAdapter) ListBranches(ctx context.Context) ([]Branch, error)
ListBranches lists all local branches (and remote if requested).
func (*ExecAdapter) OpenRepository ¶
func (a *ExecAdapter) OpenRepository(ctx context.Context, path string) error
OpenRepository sets the repo path and publishes RepositoryOpened.
func (*ExecAdapter) Pull ¶
func (a *ExecAdapter) Pull(ctx context.Context, remote, branch string) (*PullResult, error)
Pull pulls changes from a remote branch.
func (*ExecAdapter) Push ¶
func (a *ExecAdapter) Push(ctx context.Context, remote, branch string, force bool) (*PushResult, error)
Push pushes a branch to a remote.
func (*ExecAdapter) RemoveRemote ¶
func (a *ExecAdapter) RemoveRemote(ctx context.Context, name string) error
RemoveRemote removes a remote.
func (*ExecAdapter) Root ¶
func (a *ExecAdapter) Root() string
Root returns the repository root path.
type GitAdapter ¶
type GitAdapter interface {
// OpenRepository re-initializes the adapter for the given repo path.
// Must be called before any other operation.
OpenRepository(ctx context.Context, path string) error
// Root returns the repository root path.
Root() string
// Status returns the working tree status.
GetStatus(ctx context.Context) (*Status, error)
// Commit creates a commit with the given message (and optional author).
// Author defaults to the Git config user.name / user.email if empty.
CreateCommit(ctx context.Context, message, author string) (string, error)
// GetCommitHistory returns commit history for a branch (or all if empty).
GetCommitHistory(ctx context.Context, branch string, limit int) ([]Commit, error)
// Branch operations.
ListBranches(ctx context.Context) ([]Branch, error)
CreateBranch(ctx context.Context, name string) error
CheckoutBranch(ctx context.Context, name string) error
DeleteBranch(ctx context.Context, name string, force bool) error
CurrentBranch(ctx context.Context) (string, error)
// Remote operations.
GetRemotes(ctx context.Context) ([]Remote, error)
AddRemote(ctx context.Context, name, url string) error
RemoveRemote(ctx context.Context, name string) error
Push(ctx context.Context, remote, branch string, force bool) (*PushResult, error)
Pull(ctx context.Context, remote, branch string) (*PullResult, error)
// Graph returns the commit graph structure for visualisation.
GetGraph(ctx context.Context, branch string, maxCount int) ([]GraphNode, error)
}
GitAdapter provides repository-scoped Git operations. Every method takes a context for cancellation and returns typed Go values — callers never parse raw git output.
type GraphNode ¶
type GraphNode struct {
SHA string `json:"sha"`
Message string `json:"message"`
Parents []string `json:"parents"`
Refs string `json:"refs,omitempty"`
}
GraphNode represents a single node in the commit graph.
type PullResult ¶
PullResult holds the output of a pull operation.
type PushResult ¶
type PushResult struct {
Output string `json:"output"`
}
PushResult holds the output of a push operation.
type Remote ¶
type Remote struct {
Name string `json:"name"`
URL string `json:"url"`
PushURL string `json:"push_url,omitempty"`
}
Remote represents a Git remote.
type Status ¶
type Status struct {
Branch string `json:"branch"`
Clean bool `json:"clean"`
Staged []StatusEntry `json:"staged"`
Unstaged []StatusEntry `json:"unstaged"`
Untracked []string `json:"untracked"`
}
Status holds the full working tree status.
type StatusEntry ¶
type StatusEntry struct {
IndexStatus string `json:"index_status"` // staged change (M, A, D, R, C, or space)
WorktreeStatus string `json:"worktree_status"` // unstaged change (M, A, D, or space)
Path string `json:"path"`
OldPath string `json:"old_path,omitempty"` // for renames/copies
}
StatusEntry represents a single file in the working tree status.