Documentation
¶
Overview ¶
Package git provides a shared utility layer for git operations. It wraps system git commands, providing a consistent API for use across workspace preparers and publishers. The design allows for future migration to go-git or a hybrid approach without changing the consumer API.
Index ¶
- func GetGlobalConfig(key string) string
- func RemoteGetConfig(ctx context.Context, key string) (string, error)
- type ApplyOptions
- type Client
- func (c *Client) Add(ctx context.Context, args ...string) error
- func (c *Client) AddAll(ctx context.Context) error
- func (c *Client) AddWorktree(ctx context.Context, path, ref string, detach bool) error
- func (c *Client) Apply(ctx context.Context, opts ApplyOptions) error
- func (c *Client) ApplyCheck(ctx context.Context, patchPath string, threeWay bool) error
- func (c *Client) Branch(ctx context.Context, name string, create bool) error
- func (c *Client) Checkout(ctx context.Context, ref string) error
- func (c *Client) Commit(ctx context.Context, message string) (string, error)
- func (c *Client) CommitWith(ctx context.Context, opts CommitOptions) (string, error)
- func (c *Client) ConfigGet(ctx context.Context, key string) (string, error)
- func (c *Client) DiagnoseWorkingTree(ctx context.Context) string
- func (c *Client) ExecCommand(ctx context.Context, args ...string) ([]byte, error)
- func (c *Client) GetHeadSHA(ctx context.Context) (string, error)
- func (c *Client) GetRepositoryInfo(ctx context.Context) (*RepositoryInfo, error)
- func (c *Client) GetWorkingTreeStatus(ctx context.Context) ([]FileStatus, error)
- func (c *Client) HasChanges(ctx context.Context) bool
- func (c *Client) Init(ctx context.Context) error
- func (c *Client) InitRepository(ctx context.Context) error
- func (c *Client) InitSubmodules(ctx context.Context) error
- func (c *Client) IsClean(ctx context.Context) bool
- func (c *Client) IsRepo(ctx context.Context) bool
- func (c *Client) IsShallowClone(ctx context.Context) (bool, error)
- func (c *Client) Push(ctx context.Context, opts PushOptions) error
- func (c *Client) RemoveWorktree(ctx context.Context, path string, force bool) error
- func (c *Client) SetConfig(ctx context.Context, key, value string) error
- func (c *Client) SetRemote(ctx context.Context, name, url string) error
- type ClientOptions
- type CloneOptions
- type CloneResult
- type CommitAuthor
- type CommitOptions
- type FileStatus
- type PushOptions
- type RepositoryInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetGlobalConfig ¶ added in v0.6.0
GetGlobalConfig reads a global git configuration value. Returns empty string if the configuration is not set. This function is useful for getting the host's git user.name and user.email to use as fallback when project config doesn't specify them.
func RemoteGetConfig ¶
RemoteGetConfig retrieves a global/system git configuration value. This function does not use a repository directory and reads from global/system config. Use client.ConfigGet() for repository-specific configuration.
Types ¶
type ApplyOptions ¶
type ApplyOptions struct {
// PatchPath is the path to the patch file.
PatchPath string
// ThreeWay enables 3-way merge.
ThreeWay bool
// CheckOnly validates the patch without applying it.
CheckOnly bool
}
ApplyOptions specifies options for applying a patch.
type Client ¶
type Client struct {
// Dir is the working directory of the git repository.
Dir string
// AuthToken is the optional authentication token for push operations.
AuthToken string
// Options provides optional git configuration.
Options *ClientOptions
}
Client represents a git client for operations on a repository.
func NewClientWithToken ¶
NewClientWithToken creates a new git client with authentication.
func (*Client) AddWorktree ¶
AddWorktree adds a new worktree at the given path, optionally checking out a ref.
func (*Client) Apply ¶
func (c *Client) Apply(ctx context.Context, opts ApplyOptions) error
Apply applies a patch file to the workspace.
func (*Client) ApplyCheck ¶
ApplyCheck checks if a patch can be applied without conflicts.
func (*Client) CommitWith ¶
CommitWith creates a commit with options.
func (*Client) DiagnoseWorkingTree ¶ added in v0.6.0
DiagnoseWorkingTree returns detailed diagnostic information about the working tree state. It returns a formatted string with file-by-file status information.
func (*Client) ExecCommand ¶
ExecCommand is a safe wrapper to allow callers to run arbitrary git commands.
func (*Client) GetHeadSHA ¶
GetHeadSHA returns the current HEAD SHA.
func (*Client) GetRepositoryInfo ¶
func (c *Client) GetRepositoryInfo(ctx context.Context) (*RepositoryInfo, error)
GetRepositoryInfo returns information about the repository.
func (*Client) GetWorkingTreeStatus ¶ added in v0.6.0
func (c *Client) GetWorkingTreeStatus(ctx context.Context) ([]FileStatus, error)
GetWorkingTreeStatus returns detailed status information about the working tree. It parses git status --porcelain output to return file-level status.
func (*Client) HasChanges ¶
HasChanges returns true if there are uncommitted changes.
func (*Client) InitRepository ¶
InitRepository initializes a git repository with default configuration.
func (*Client) InitSubmodules ¶
InitSubmodules initializes git submodules.
func (*Client) IsShallowClone ¶
IsShallowClone checks if the repository is a shallow clone.
func (*Client) Push ¶
func (c *Client) Push(ctx context.Context, opts PushOptions) error
Push pushes commits to a remote repository. Note: This requires git credentials to be configured for authentication.
func (*Client) RemoveWorktree ¶
RemoveWorktree removes an existing worktree.
type ClientOptions ¶
type ClientOptions struct {
// UserName is the git user name for commits.
UserName string
// UserEmail is the git user email for commits.
UserEmail string
// Quiet suppresses output from git commands.
Quiet bool
// DryRun logs commands without executing them.
DryRun bool
}
ClientOptions holds configuration for git operations.
func DefaultClientOptions ¶
func DefaultClientOptions() *ClientOptions
DefaultClientOptions returns the default client options.
type CloneOptions ¶
type CloneOptions struct {
// Source is the repository URL or path to clone from.
Source string
// Dest is the destination directory.
Dest string
// Ref is the reference to checkout after clone (optional).
Ref string
// Depth specifies shallow clone depth (0 for full history).
Depth int
// Local indicates to use --local for local repositories.
Local bool
// Submodules indicates whether to initialize submodules.
Submodules bool
// Quiet suppresses output.
Quiet bool
}
CloneOptions specifies options for cloning a repository.
type CloneResult ¶
type CloneResult struct {
// HEAD is the checked out commit SHA.
HEAD string
// Branch is the checked out branch name.
Branch string
// IsShallow indicates if the clone is shallow.
IsShallow bool
}
CloneResult holds the result of a clone operation.
func Clone ¶
func Clone(ctx context.Context, opts CloneOptions) (*CloneResult, error)
Clone clones a repository.
type CommitAuthor ¶
CommitAuthor represents the author of a commit.
type CommitOptions ¶
type CommitOptions struct {
// Message is the commit message.
Message string
// Author is the commit author (defaults to config).
Author *CommitAuthor
// AllowEmpty allows creating a commit with no changes.
AllowEmpty bool
}
CommitOptions specifies options for creating a commit.
type FileStatus ¶ added in v0.6.0
type FileStatus struct {
// Path is the file path.
Path string
// Status is the human-readable status (e.g., "modified", "added", "deleted").
Status string
// StatusCode is the raw status code from git status.
StatusCode string
}
FileStatus represents the status of a single file in the working tree.
type PushOptions ¶
type PushOptions struct {
// Remote is the remote name (default: "origin").
Remote string
// Branch is the branch to push.
Branch string
// Force enables force push.
Force bool
// SetUpstream sets the upstream branch.
SetUpstream bool
}
PushOptions specifies options for pushing to a remote.
type RepositoryInfo ¶
type RepositoryInfo struct {
// HEAD is the current commit SHA.
HEAD string
// IsShallow indicates if the repository is a shallow clone.
IsShallow bool
// Branch is the current branch name (empty if detached HEAD).
Branch string
// Clean indicates if the working directory has no changes.
Clean bool
}
RepositoryInfo holds information about a git repository.