git

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeGitopiaURL

func NormalizeGitopiaURL(url string) string

NormalizeGitopiaURL converts various Gitopia URL formats to the canonical gitopia:// format

func SetupGitConfig

func SetupGitConfig(ctx context.Context, name, email string) error

SetupGitConfig sets the global git user name and email.

func ValidateGitopiaURL

func ValidateGitopiaURL(url string) bool

ValidateGitopiaURL checks if a URL is a valid Gitopia URL

Types

type AuthManager

type AuthManager struct {
	WalletPath string
}

AuthManager handles git authentication for Gitopia

func NewAuthManager

func NewAuthManager() *AuthManager

NewAuthManager creates a new authentication manager

func (*AuthManager) CleanupAuth

func (am *AuthManager) CleanupAuth() error

CleanupAuth removes the temporary wallet file and unsets environment variables

func (*AuthManager) GetWalletPath

func (am *AuthManager) GetWalletPath() string

GetWalletPath returns the current wallet path

func (*AuthManager) IsAuthSetup

func (am *AuthManager) IsAuthSetup() bool

IsAuthSetup checks if git authentication is properly configured

func (*AuthManager) SetupAuth

func (am *AuthManager) SetupAuth(walletData []byte, walletAddress string) error

SetupAuth sets up git authentication using a wallet

type BranchOption

type BranchOption func(*BranchOptions)

func WithStartPoint

func WithStartPoint(startPoint string) BranchOption

type BranchOptions

type BranchOptions struct {
	StartPoint string
}

BranchOptions contains options for creating branches

type CheckoutOption

type CheckoutOption func(*CheckoutOptions)

func WithCreateBranch

func WithCreateBranch(createBranch bool) CheckoutOption

func WithForceCheckout

func WithForceCheckout(force bool) CheckoutOption

type CheckoutOptions

type CheckoutOptions struct {
	CreateBranch bool
	Force        bool
}

CheckoutOptions contains options for checkout

type Client

type Client struct {
	// GitPath is the path to the git executable (default: "git")
	GitPath string
	// Timeout for git operations (default: 30 seconds)
	Timeout time.Duration
}

Client wraps git CLI operations

func NewClient

func NewClient() *Client

NewClient creates a new git client

func (*Client) Add

func (c *Client) Add(ctx context.Context, repoPath string, files ...string) error

Add stages files for commit

func (*Client) Checkout

func (c *Client) Checkout(ctx context.Context, repoPath, branchOrCommit string, options ...CheckoutOption) error

Checkout switches branches or restores files

func (*Client) Clone

func (c *Client) Clone(ctx context.Context, url, path string, options ...CloneOption) error

Clone clones a repository

func (*Client) Commit

func (c *Client) Commit(ctx context.Context, repoPath, message string, options ...CommitOption) (string, error)

Commit creates a new commit

func (*Client) CreateBranch

func (c *Client) CreateBranch(ctx context.Context, repoPath, branchName string, options ...BranchOption) error

CreateBranch creates a new branch

func (*Client) GetCurrentBranch

func (c *Client) GetCurrentBranch(ctx context.Context, repoPath string) (string, error)

GetCurrentBranch returns the current branch name

func (*Client) GetRemoteURL

func (c *Client) GetRemoteURL(ctx context.Context, repoPath, remote string) (string, error)

GetRemoteURL returns the URL of the specified remote

func (*Client) Init

func (c *Client) Init(ctx context.Context, path, remoteURL string) error

Init initializes a new git repository in the given path. If remoteURL is provided, it adds it as the 'origin' remote.

func (*Client) IsRepository

func (c *Client) IsRepository(path string) bool

IsRepository checks if the given path is a git repository

func (*Client) Pull

func (c *Client) Pull(ctx context.Context, repoPath string, options ...PullOption) error

Pull fetches and merges from remote

func (*Client) Push

func (c *Client) Push(ctx context.Context, repoPath string, options ...PushOption) error

Push pushes commits to remote

func (*Client) Status

func (c *Client) Status(ctx context.Context, repoPath string) (*Status, error)

Status returns the repository status

type CloneOption

type CloneOption func(*CloneOptions)

func WithBranch

func WithBranch(branch string) CloneOption

func WithDepth

func WithDepth(depth int) CloneOption

func WithQuiet

func WithQuiet(quiet bool) CloneOption

type CloneOptions

type CloneOptions struct {
	Branch string
	Depth  int
	Quiet  bool
}

CloneOptions contains options for cloning repositories

type CommitOption

type CommitOption func(*CommitOptions)

func WithAllowEmpty

func WithAllowEmpty(allowEmpty bool) CommitOption

func WithAmend

func WithAmend(amend bool) CommitOption

func WithAuthor

func WithAuthor(author string) CommitOption

type CommitOptions

type CommitOptions struct {
	Author     string
	AllowEmpty bool
	Amend      bool
}

CommitOptions contains options for committing

type FileChange

type FileChange struct {
	Path    string `json:"path"`
	Content string `json:"content,omitempty"`
	Mode    string `json:"mode"` // "create", "modify", "delete"
}

FileChange represents a file change for batch operations

type GitError

type GitError struct {
	Command  string
	Args     []string
	ExitCode int
	Stdout   string
	Stderr   string
	Err      error
}

GitError represents a git command error with detailed information

func (*GitError) Error

func (e *GitError) Error() string

func (*GitError) UserFriendlyMessage

func (e *GitError) UserFriendlyMessage() string

UserFriendlyMessage returns a user-friendly error message

type PullOption

type PullOption func(*PullOptions)

func WithBranchToPull

func WithBranchToPull(branch string) PullOption

func WithFFOnly

func WithFFOnly(ffOnly bool) PullOption

func WithRebase

func WithRebase(rebase bool) PullOption

func WithRemoteToPull

func WithRemoteToPull(remote string) PullOption

type PullOptions

type PullOptions struct {
	Remote string
	Branch string
	Rebase bool
	FFOnly bool
}

PullOptions contains options for pulling

type PushOption

type PushOption func(*PushOptions)

func WithBranchToPush

func WithBranchToPush(branch string) PushOption

func WithDelete

func WithDelete(delete bool) PushOption

func WithDryRun

func WithDryRun(dryRun bool) PushOption

func WithForce

func WithForce(force bool) PushOption

func WithForceWithLease

func WithForceWithLease(forceWithLease bool) PushOption

func WithRemote

func WithRemote(remote string) PushOption

func WithSetUpstream

func WithSetUpstream(setUpstream bool) PushOption

func WithTags

func WithTags(tags bool) PushOption

type PushOptions

type PushOptions struct {
	Remote         string
	Branch         string
	SetUpstream    bool
	Force          bool
	ForceWithLease bool
	DryRun         bool
	Tags           bool
	Delete         bool
}

PushOptions contains options for pushing

type Status

type Status struct {
	Branch        string   `json:"branch"`
	Staged        []string `json:"staged"`
	Modified      []string `json:"modified"`
	Untracked     []string `json:"untracked"`
	CommitsAhead  int      `json:"commits_ahead"`
	CommitsBehind int      `json:"commits_behind"`
	Clean         bool     `json:"clean"`
}

Status represents the status of a git repository

func (*Status) HasChanges

func (s *Status) HasChanges() bool

HasChanges returns true if there are any changes (staged or unstaged)

func (*Status) IsClean

func (s *Status) IsClean() bool

IsClean returns true if the working tree is clean

type WorkflowResult

type WorkflowResult struct {
	Success      bool              `json:"success"`
	Message      string            `json:"message"`
	Branch       string            `json:"branch,omitempty"`
	CommitHash   string            `json:"commit_hash,omitempty"`
	FilesChanged int               `json:"files_changed,omitempty"`
	PRURL        string            `json:"pr_url,omitempty"`
	PRNumber     int               `json:"pr_number,omitempty"`
	Errors       []string          `json:"errors,omitempty"`
	Metadata     map[string]string `json:"metadata,omitempty"`
}

WorkflowResult represents the result of a high-level git workflow operation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL