Documentation
¶
Overview ¶
Package git provides a git client with credential helper support. Pattern inspired by github.com/cli/cli
Index ¶
- Variables
- func ExtractRepoName(rawURL string) string
- func FindGitDir(startPath string) (string, error)
- func GetExitCode(err error) int
- func IsAlreadyExists(err error) bool
- func IsAuthRequired(err error) bool
- func IsConflict(err error) bool
- func IsDetachedHead(err error) bool
- func IsNoUpstream(err error) bool
- func IsNotRepository(err error) bool
- func IsNothingToCommit(err error) bool
- func IsRefNotFound(err error) bool
- func ParseURL(rawURL string) (*url.URL, error)
- func ReadCredentialRequest(r io.Reader) (map[string]string, error)
- func RepoRoot(ctx context.Context) (string, error)
- func WriteCredential(w io.Writer, host, username, password string) error
- type BranchInfo
- type CheckoutOptions
- type Client
- func (c *Client) AddRemote(ctx context.Context, name, url string) error
- func (c *Client) AuthenticatedCommand(ctx context.Context, pattern CredentialPattern, args ...string) *exec.Cmd
- func (c *Client) Checkout(ctx context.Context, target string, opts CheckoutOptions) error
- func (c *Client) Clone(ctx context.Context, cloneURL, targetPath string) error
- func (c *Client) Command(ctx context.Context, args ...string) *exec.Cmd
- func (c *Client) CommandInteractive(ctx context.Context, args ...string) *exec.Cmd
- func (c *Client) Commit(ctx context.Context, message string, opts CommitOptions) error
- func (c *Client) CurrentBranch(ctx context.Context) (string, error)
- func (c *Client) DeleteBranch(ctx context.Context, name string, force bool) error
- func (c *Client) Diff(ctx context.Context, opts DiffOptions) (string, error)
- func (c *Client) Fetch(ctx context.Context, remote, refspec string) error
- func (c *Client) GetHead(ctx context.Context) (string, error)
- func (c *Client) GetRemoteURL(ctx context.Context, remote string) (string, error)
- func (c *Client) GetShortHead(ctx context.Context) (string, error)
- func (c *Client) IsRepository(ctx context.Context) bool
- func (c *Client) ListBranches(ctx context.Context, all bool) ([]string, error)
- func (c *Client) ListBranchesDetailed(ctx context.Context, all bool) ([]BranchInfo, error)
- func (c *Client) ListRemotes(ctx context.Context) ([]Remote, error)
- func (c *Client) Log(ctx context.Context, opts LogOptions) ([]Commit, error)
- func (c *Client) LogOneline(ctx context.Context, limit int) (string, error)
- func (c *Client) Merge(ctx context.Context, branch string, opts MergeOptions) error
- func (c *Client) NewGitCommand(ctx context.Context, args ...string) *GitCommand
- func (c *Client) Pull(ctx context.Context, remote, branch string) error
- func (c *Client) Push(ctx context.Context, remote, branch string, opts PushOptions) error
- func (c *Client) RemoveRemote(ctx context.Context, name string) error
- func (c *Client) Stash(ctx context.Context, opts StashOptions) error
- func (c *Client) StashDrop(ctx context.Context, stash string) error
- func (c *Client) StashList(ctx context.Context) (string, error)
- func (c *Client) StashPop(ctx context.Context) error
- func (c *Client) Status(ctx context.Context) (string, error)
- func (c *Client) StatusPorcelain(ctx context.Context) (string, error)
- func (c *Client) Tag(ctx context.Context, name, message string) error
- type CommandModifier
- type Commit
- type CommitOptions
- type CredentialPattern
- type CredentialStore
- type DiffOptions
- type FileStatus
- type GitCommand
- func (gc *GitCommand) Apply() *exec.Cmd
- func (gc *GitCommand) CombinedOutput() ([]byte, error)
- func (gc *GitCommand) Output() ([]byte, error)
- func (gc *GitCommand) Run() error
- func (gc *GitCommand) WithDir(dir string) *GitCommand
- func (gc *GitCommand) WithEnv(env ...string) *GitCommand
- func (gc *GitCommand) WithStdio(stdin io.Reader, stdout, stderr io.Writer) *GitCommand
- type GitError
- type LogOptions
- type MergeOptions
- type PushOptions
- type Remote
- type StashOptions
- type StatusInfo
Constants ¶
This section is empty.
Variables ¶
var AllMatchingCredentialsPattern = CredentialPattern{/* contains filtered or unexported fields */}
AllMatchingCredentialsPattern matches all hosts
Functions ¶
func ExtractRepoName ¶
ExtractRepoName extracts the repository name from a URL
func FindGitDir ¶
FindGitDir finds the .git directory from a path
func GetExitCode ¶ added in v0.3.0
GetExitCode returns the exit code from a git error, or -1 if not available
func IsAlreadyExists ¶ added in v0.3.0
IsAlreadyExists checks if the error indicates something already exists
func IsAuthRequired ¶ added in v0.3.0
IsAuthRequired checks if the error indicates authentication is required
func IsConflict ¶ added in v0.3.0
IsConflict checks if the error indicates a merge conflict
func IsDetachedHead ¶ added in v0.3.0
IsDetachedHead checks if the error indicates HEAD is detached
func IsNoUpstream ¶ added in v0.3.0
IsNoUpstream checks if the error indicates no upstream branch configured
func IsNotRepository ¶ added in v0.3.0
IsNotRepository checks if the error indicates not a git repository
func IsNothingToCommit ¶ added in v0.3.0
IsNothingToCommit checks if the error indicates nothing to commit
func IsRefNotFound ¶ added in v0.3.0
IsRefNotFound checks if the error indicates a ref was not found
func ReadCredentialRequest ¶
ReadCredentialRequest reads a credential request from git
Types ¶
type BranchInfo ¶ added in v0.3.0
type BranchInfo struct {
Name string
Current bool
Upstream string
LastCommit string
Gone bool // Upstream is gone
}
BranchInfo contains detailed branch information
type CheckoutOptions ¶
CheckoutOptions configures checkout behavior
type Client ¶
type Client struct {
ClonrPath string // Path to clonr executable (for credential helper)
RepoDir string // Repository directory
GitPath string // Path to git executable
Stderr io.Writer
Stdin io.Reader
Stdout io.Writer
}
Client wraps git operations with authentication support
func NewClientForRepo ¶
NewClientForRepo creates a client for a specific repository
func (*Client) AuthenticatedCommand ¶
func (c *Client) AuthenticatedCommand(ctx context.Context, pattern CredentialPattern, args ...string) *exec.Cmd
AuthenticatedCommand creates a git command with credential helper configured Note: Do not set Stdout/Stderr if you plan to use CombinedOutput()
func (*Client) Command ¶
Command creates a git command without authentication Note: Do not set Stdout/Stderr if you plan to use CombinedOutput()
func (*Client) CommandInteractive ¶
CommandInteractive creates a git command with stdio attached for interactive use
func (*Client) CurrentBranch ¶
CurrentBranch returns the current branch name
func (*Client) DeleteBranch ¶ added in v0.3.0
DeleteBranch deletes a branch
func (*Client) GetRemoteURL ¶
GetRemoteURL returns the URL for a remote
func (*Client) GetShortHead ¶ added in v0.3.0
GetShortHead returns the short form of current HEAD
func (*Client) IsRepository ¶
IsRepository checks if the current directory is a git repository
func (*Client) ListBranches ¶
ListBranches lists branches
func (*Client) ListBranchesDetailed ¶ added in v0.3.0
ListBranchesDetailed lists branches with detailed information
func (*Client) ListRemotes ¶ added in v0.3.0
ListRemotes lists all configured remotes
func (*Client) LogOneline ¶ added in v0.3.0
LogOneline returns a simple one-line log output
func (*Client) NewGitCommand ¶ added in v0.3.0
func (c *Client) NewGitCommand(ctx context.Context, args ...string) *GitCommand
NewGitCommand creates a new GitCommand
func (*Client) RemoveRemote ¶ added in v0.3.0
RemoveRemote removes a remote
func (*Client) Stash ¶
func (c *Client) Stash(ctx context.Context, opts StashOptions) error
Stash stashes changes
func (*Client) StatusPorcelain ¶ added in v0.3.0
StatusPorcelain returns machine-readable status
type CommandModifier ¶ added in v0.3.0
CommandModifier is a function that can modify a git command before execution
type Commit ¶ added in v0.3.0
type Commit struct {
SHA string
ShortSHA string
Author string
Email string
Date string
Subject string
Body string
Refs string
}
Commit represents a git commit
type CommitOptions ¶
type CommitOptions struct {
All bool // Stage all modified files before committing
}
CommitOptions configures commit behavior
type CredentialPattern ¶
type CredentialPattern struct {
// contains filtered or unexported fields
}
CredentialPattern represents a pattern for credential matching
func CredentialPatternFromGitURL ¶
func CredentialPatternFromGitURL(gitURL string) (CredentialPattern, error)
CredentialPatternFromGitURL derives a credential pattern from a git URL
func CredentialPatternFromHost ¶
func CredentialPatternFromHost(host string) CredentialPattern
CredentialPatternFromHost creates a pattern for a specific host
type CredentialStore ¶
CredentialStore provides credential storage interface
type DiffOptions ¶ added in v0.3.0
type DiffOptions struct {
Staged bool // Show staged changes (--cached)
Stat bool // Show diffstat (--stat)
NameOnly bool // Only show file names
NameStatus bool // Show file names and status
Commit string // Diff against a specific commit
Path string // Limit to a specific path
}
DiffOptions configures diff output
type FileStatus ¶ added in v0.3.0
type FileStatus struct {
Path string
Status string // M=modified, A=added, D=deleted, R=renamed, C=copied, U=updated
}
FileStatus represents the status of a single file
type GitCommand ¶ added in v0.3.0
GitCommand wraps exec.Cmd with additional functionality
func (*GitCommand) Apply ¶ added in v0.3.0
func (gc *GitCommand) Apply() *exec.Cmd
Apply applies all modifiers to the command
func (*GitCommand) CombinedOutput ¶ added in v0.3.0
func (gc *GitCommand) CombinedOutput() ([]byte, error)
CombinedOutput applies modifiers and returns combined output
func (*GitCommand) Output ¶ added in v0.3.0
func (gc *GitCommand) Output() ([]byte, error)
Output applies modifiers and returns the output
func (*GitCommand) Run ¶ added in v0.3.0
func (gc *GitCommand) Run() error
Run applies modifiers and runs the command
func (*GitCommand) WithDir ¶ added in v0.3.0
func (gc *GitCommand) WithDir(dir string) *GitCommand
WithDir sets the working directory for the command
func (*GitCommand) WithEnv ¶ added in v0.3.0
func (gc *GitCommand) WithEnv(env ...string) *GitCommand
WithEnv adds environment variables to the command
func (*GitCommand) WithStdio ¶ added in v0.3.0
func (gc *GitCommand) WithStdio(stdin io.Reader, stdout, stderr io.Writer) *GitCommand
WithStdio attaches stdin, stdout, stderr to the command
type GitError ¶
type GitError struct {
ExitCode int
Stderr string
Args []string
// contains filtered or unexported fields
}
GitError represents a git command error
func NewGitError ¶ added in v0.3.0
NewGitError creates a GitError from command output and error
type LogOptions ¶ added in v0.3.0
type LogOptions struct {
Limit int
Oneline bool
All bool
Format string // Custom format string
Since string // Show commits more recent than this date
Until string // Show commits older than this date
Author string // Filter by author
Grep string // Filter by commit message
}
LogOptions configures log output
type MergeOptions ¶
MergeOptions configures merge behavior
type PushOptions ¶
PushOptions configures push behavior
type StashOptions ¶
StashOptions configures stash behavior
type StatusInfo ¶ added in v0.3.0
type StatusInfo struct {
Branch string
Upstream string
Ahead int
Behind int
Staged []FileStatus
Unstaged []FileStatus
Untracked []string
HasChanges bool
HasUntracked bool
HasConflicts bool
}
StatusInfo contains detailed status information