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 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) 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 ¶ added in v1.3.0
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 ¶ added in v1.3.0
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 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 ¶ added in v1.3.0
func NewClientWithOptions(opts ...ClientOption) *Client
func (*Client) CheckoutNewBranch ¶ added in v0.12.7
CheckoutNewBranch creates and switches to a new branch
func (*Client) CheckoutNewBranchForce ¶ added in v1.8.0
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 ¶ added in v0.12.7
GetCurrentBranchSymbolic returns the current branch name using symbolic-ref, which works even on empty repos (no commits yet).
func (*Client) GetDefaultBranch ¶ added in v1.8.0
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 ¶ added in v0.5.5
HasStagedChanges checks if there are staged changes ready to be committed
func (*Client) IsEmpty ¶ added in v0.12.7
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 ¶ added in v0.15.0
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 ¶ added in v0.12.7
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) Reset ¶ added in v1.5.0
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 ¶ added in v1.5.0
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 ¶ added in v1.3.0
type ClientOption func(*Client)
func WithCommitActor ¶ added in v1.3.0
func WithCommitActor(name, email string) ClientOption
func WithEnv ¶ added in v1.3.0
func WithEnv(env ...string) ClientOption
func WithHTTPBasicAuth ¶ added in v1.3.0
func WithHTTPBasicAuth(scheme, host, username, password string) ClientOption
func WithHTTPSBasicAuth ¶ added in v1.3.0
func WithHTTPSBasicAuth(host, username, password string) ClientOption
func WithSSHKey ¶ added in v1.3.0
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 ¶ added in v1.3.0
RemoteAuthInfo describes the host and transport parsed from a git remote URL.
func ParseRemoteAuthInfo ¶ added in v1.3.0
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.