Documentation
¶
Index ¶
- func ConvertToSSH(httpsURL string) (string, error)
- func DefaultHTTPAuthUsername(host, explicit string) string
- func GetSSHKeyPath() string
- func IsHTTPSURL(url string) bool
- func IsSSHURL(url string) bool
- func LooksLikeHTTPRemote(repoURL string) bool
- func SetSSHKeyPath(cmd *cobra.Command)
- func ValidateSSHKey(keyPath string) error
- type Availability
- type Client
- func (c *Client) Add(ctx context.Context, repoPath string, paths ...string) error
- func (c *Client) Checkout(ctx context.Context, repoPath, ref string) error
- func (c *Client) CheckoutNewBranch(ctx context.Context, repoPath, branch string) error
- func (c *Client) CheckoutNewBranchForce(ctx context.Context, repoPath, branch string) error
- func (c *Client) Clone(ctx context.Context, repoURL, destPath string) error
- func (c *Client) Commit(ctx context.Context, repoPath, message string) error
- func (c *Client) ExtraEnv() []string
- func (c *Client) Fetch(ctx context.Context, repoPath string) error
- func (c *Client) GetCurrentBranch(ctx context.Context, repoPath string) (string, error)
- func (c *Client) GetCurrentBranchSymbolic(ctx context.Context, repoPath string) (string, error)
- func (c *Client) GetDefaultBranch(ctx context.Context, repoPath string) (string, error)
- func (c *Client) GetRemoteURL(ctx context.Context, repoPath string) (string, error)
- func (c *Client) HasStagedChanges(ctx context.Context, repoPath string) (bool, error)
- func (c *Client) IsEmpty(ctx context.Context, repoPath string) (bool, error)
- func (c *Client) LsRemote(ctx context.Context, repoURL, ref string) (string, error)
- func (c *Client) Pull(ctx context.Context, repoPath string) error
- func (c *Client) PullRebase(ctx context.Context, repoPath string) error
- func (c *Client) Push(ctx context.Context, repoPath string) error
- func (c *Client) PushSetUpstream(ctx context.Context, repoPath, branch string) error
- func (c *Client) RebaseAbort(ctx context.Context, repoPath string) error
- func (c *Client) Reset(ctx context.Context, repoPath, mode, ref string) error
- func (c *Client) RestoreExcept(ctx context.Context, repoPath, excludeDir string) error
- func (c *Client) RevParse(ctx context.Context, repoPath, ref string) (string, error)
- type ClientOption
- type RemoteAuthInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertToSSH ¶
ConvertToSSH converts HTTPS git URLs to SSH format Example: https://github.com/owner/repo.git → git@github.com:owner/repo.git
func DefaultHTTPAuthUsername ¶
DefaultHTTPAuthUsername returns a reasonable basic-auth username for a git HTTP(S) token when the caller did not configure one explicitly.
Host-based detection only covers gitlab.com and *.gitlab.com — self-hosted GitLab instances on custom domains (gitlab.example.com, etc.) fall back to "x-access-token", which GitLab rejects. Callers pointing at self-hosted GitLab must pass explicit = "oauth2" to override.
func LooksLikeHTTPRemote ¶
LooksLikeHTTPRemote reports whether repoURL uses an HTTP(S) scheme even when the URL is malformed enough that ParseRemoteAuthInfo cannot extract a host.
func SetSSHKeyPath ¶
SetSSHKeyPath sets the global SSH key path from either the flag or environment variable This should be called once at startup from the root command
func ValidateSSHKey ¶
ValidateSSHKey validates SSH key file exists, readable, and has proper permissions If the keyPath looks like actual key content (starts with "-----BEGIN"), it's considered valid
Types ¶
type Availability ¶
Availability reports whether a usable git binary exists on this machine. Reason is a short, user-facing sentence when git is unusable.
func CheckAvailability ¶
func CheckAvailability(ctx context.Context) Availability
CheckAvailability probes for a working git without ever triggering side effects. The macOS trap: on a Mac without the Xcode Command Line Tools, /usr/bin/git is a shim whose mere execution (even `git --version`) pops Apple's GUI installer dialog — so on darwin the developer-tools presence is checked first via `xcode-select -p`, and the shim is never run when the tools are missing.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides high-level git operations with SSH key support
func NewClient ¶
func NewClient() *Client
NewClient creates a new git client using the global SSH key path
func NewClientWithOptions ¶
func NewClientWithOptions(opts ...ClientOption) *Client
func (*Client) CheckoutNewBranch ¶
CheckoutNewBranch creates and switches to a new branch
func (*Client) CheckoutNewBranchForce ¶
CheckoutNewBranchForce creates (or resets, if it already exists) a branch at the current HEAD and switches to it. Unlike CheckoutNewBranch it does not fail when the branch name is already present locally — important for the cached vault clone, which is reused across runs and may carry a leftover branch from a previous attempt.
func (*Client) GetCurrentBranch ¶
GetCurrentBranch returns the current branch name
func (*Client) GetCurrentBranchSymbolic ¶
GetCurrentBranchSymbolic returns the current branch name using symbolic-ref, which works even on empty repos (no commits yet).
func (*Client) GetDefaultBranch ¶
GetDefaultBranch returns the remote's default branch (e.g. "main") by reading the origin/HEAD symbolic ref that `git clone` records. Use this instead of the clone's current HEAD when you need the repo's real base branch: the cached clone is long-lived and may be left checked out on some other branch.
func (*Client) GetRemoteURL ¶
GetRemoteURL returns the remote URL for the repository (typically 'origin')
func (*Client) HasStagedChanges ¶
HasStagedChanges checks if there are staged changes ready to be committed
func (*Client) IsEmpty ¶
IsEmpty checks if a repository has no commits (e.g., freshly cloned empty repo)
func (*Client) LsRemote ¶
LsRemote queries a remote repository for a specific ref Returns the commit hash for the ref
func (*Client) PullRebase ¶
PullRebase pulls changes from the remote repository and rebases local commits on top. Used by runInVaultTx to resolve concurrent pushes from multiple sx processes writing to the same management files.
func (*Client) PushSetUpstream ¶
PushSetUpstream pushes a branch and sets its upstream tracking ref. Used for the first push to an empty repo and for the (uniquely named, never-preexisting) PR branch — neither needs --force, so this is a plain non-forcing push and must stay that way; force-pushing here would let a caller silently clobber a remote branch that already exists.
func (*Client) RebaseAbort ¶
RebaseAbort aborts an in-progress rebase, restoring the pre-rebase branch state. Returns an error when no rebase is in progress; callers recovering from a possibly-failed rebase should treat that as a no-op.
func (*Client) Reset ¶
Reset runs `git reset --<mode> <ref>` in repoPath. Used by vault-clone repair to move the branch pointer back to the remote tip.
func (*Client) RestoreExcept ¶
RestoreExcept restores all tracked files in both the index and worktree to HEAD, except those under excludeDir. Used by vault-clone repair to discard local manifest/asset divergence while leaving the queued usage appends under excludeDir staged for a follow-up commit.
type ClientOption ¶
type ClientOption func(*Client)
func WithCommitActor ¶
func WithCommitActor(name, email string) ClientOption
func WithEnv ¶
func WithEnv(env ...string) ClientOption
func WithHTTPBasicAuth ¶
func WithHTTPBasicAuth(scheme, host, username, password string) ClientOption
func WithHTTPSBasicAuth ¶
func WithHTTPSBasicAuth(host, username, password string) ClientOption
func WithSSHKey ¶
func WithSSHKey(path string) ClientOption
WithSSHKey overrides the SSH key path that would otherwise be inherited from the process-global value set by SetSSHKeyPath. Library consumers that don't go through the CLI flag/env wiring should use this to scope an SSH key to a single git.Client.
type RemoteAuthInfo ¶
RemoteAuthInfo describes the host and transport parsed from a git remote URL.
func ParseRemoteAuthInfo ¶
func ParseRemoteAuthInfo(repoURL string) RemoteAuthInfo
ParseRemoteAuthInfo extracts the auth-relevant host and transport from a git remote URL. It supports HTTP(S) URLs, ssh:// URLs, and scp-like SSH remotes such as git@github.com:owner/repo.git.