git

package
v0.29.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: GPL-3.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package git provides Git operations and error definitions.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBranchNotFound         = errors.New("branch not found")
	ErrWorktreeExists         = errors.New("worktree already exists")
	ErrWorktreeNotFound       = errors.New("worktree not found")
	ErrWorktreePathNotFound   = errors.New("worktree path not found")
	ErrRepositoryNotClean     = errors.New("repository is not clean")
	ErrRemoteAddFailed        = errors.New("failed to add remote")
	ErrFetchFailed            = errors.New("failed to fetch from remote")
	ErrBranchNotFoundOnRemote = errors.New("branch not found on remote")

	// Specific reference conflict error types for testing.
	ErrBranchParentExists = errors.New("cannot create branch: reference already exists")
	ErrTagParentExists    = errors.New("cannot create branch: tag already exists")
)

Git-specific error types.

Functions

func SetupTestRepo added in v0.24.0

func SetupTestRepo(t *testing.T) (string, func())

SetupTestRepo creates a temporary git repository for testing.

Types

type BranchExistsOnRemoteParams

type BranchExistsOnRemoteParams struct {
	RepoPath   string
	RemoteName string
	Branch     string
}

BranchExistsOnRemoteParams contains parameters for BranchExistsOnRemote.

type CloneParams

type CloneParams struct {
	RepoURL    string
	TargetPath string
	Recursive  bool
}

CloneParams contains parameters for Clone.

type CreateBranchFromParams added in v0.15.0

type CreateBranchFromParams struct {
	RepoPath   string
	NewBranch  string
	FromBranch string
}

CreateBranchFromParams contains parameters for CreateBranchFrom.

type Git

type Git interface {
	// Status executes `git status` in specified directory.
	Status(workDir string) (string, error)

	// ConfigGet executes `git config --get <key>` in specified directory.
	ConfigGet(workDir, key string) (string, error)

	// CreateWorktree creates a new worktree for the specified branch.
	CreateWorktree(repoPath, worktreePath, branch string) error

	// CreateWorktreeWithNoCheckout creates a new worktree without checking out files.
	CreateWorktreeWithNoCheckout(repoPath, worktreePath, branch string) error

	// CloneToPath clones a local repository to a target path with a specific branch.
	CloneToPath(sourceRepoPath, targetPath, branch string) error

	// CheckoutBranch checks out a branch in the specified worktree.
	CheckoutBranch(worktreePath, branch string) error

	// GetCurrentBranch gets the current branch name.
	GetCurrentBranch(repoPath string) (string, error)

	// GetRepositoryName gets the repository name from remote origin URL with fallback to local path.
	GetRepositoryName(repoPath string) (string, error)

	// IsClean checks if the repository is in a clean state (placeholder for future validation).
	IsClean(repoPath string) (bool, error)

	// BranchExists checks if a branch exists locally or remotely.
	BranchExists(repoPath, branch string) (bool, error)

	// CreateBranchFrom creates a new branch from a specific branch.
	CreateBranchFrom(params CreateBranchFromParams) error

	// CheckReferenceConflict checks if creating a branch would conflict with existing references.
	CheckReferenceConflict(repoPath, branch string) error

	// WorktreeExists checks if a worktree exists for the specified branch.
	WorktreeExists(repoPath, branch string) (bool, error)

	// RemoveWorktree removes a worktree from Git's tracking.
	RemoveWorktree(repoPath, worktreePath string, force bool) error

	// GetWorktreePath gets the path of a worktree for a branch.
	GetWorktreePath(repoPath, branch string) (string, error)

	// AddRemote adds a new remote to the repository.
	AddRemote(repoPath, remoteName, remoteURL string) error

	// FetchRemote fetches from a specific remote.
	FetchRemote(repoPath, remoteName string) error

	// BranchExistsOnRemote checks if a branch exists on a specific remote.
	BranchExistsOnRemote(params BranchExistsOnRemoteParams) (bool, error)

	// GetRemoteURL gets the URL of a remote.
	GetRemoteURL(repoPath, remoteName string) (string, error)

	// RemoteExists checks if a remote exists.
	RemoteExists(repoPath, remoteName string) (bool, error)

	// Clone clones a repository to the specified path.
	Clone(params CloneParams) error

	// GetDefaultBranch gets the default branch name from a remote repository.
	GetDefaultBranch(remoteURL string) (string, error)

	// Add adds files to the Git staging area.
	Add(repoPath string, files ...string) error

	// CreateBranch creates a new branch from the current branch.
	CreateBranch(repoPath, branch string) error

	// Commit creates a new commit with the specified message.
	Commit(repoPath, message string) error

	// GetBranchRemote gets the remote name for a branch (e.g., "origin", "justenstall").
	GetBranchRemote(repoPath, branch string) (string, error)

	// SetUpstreamBranch sets the upstream branch for the current branch.
	SetUpstreamBranch(repoPath, remote, branch string) error
}

Git interface provides Git command execution capabilities.

func NewGit

func NewGit() Git

NewGit creates a new Git instance.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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