Help us shape the future of Go! Take the 2026 Go Developer Survey

repo

package
v1.53.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BareClone

func BareClone(ctx context.Context, repoURL, branch, bareRepoPath string, auth *ssh.PublicKeys) error

BareClone clones a git repository as a bare repository.

func CheckoutBareRepo

func CheckoutBareRepo(ctx context.Context, repoPath, workTree string, force, all bool) error

CheckoutBareRepo performs a git checkout operation for a bare repository. It takes the repository path `repoPath` and work tree `workTree` as inputs. If force is true, it will discard any local changes and force the checkout. If all is true, it will checkout all files from the index/HEAD. Returns an error if the operation fails.

func CheckoutWorktree

func CheckoutWorktree(ctx context.Context, bareRepoPath, worktreeDir string) error

CheckoutWorktree checks out the tree from a bare repository to a worktree directory.

func Clone

func Clone(ctx context.Context, url, destPath string) error

Clone clones a git repository to the specified path. It uses os/exec for the clone operation and provides informative error messages.

func ConfigureBareRepo

func ConfigureBareRepo(ctx context.Context, bareRepoPath string) error

ConfigureBareRepo sets the bare repository to not show untracked files.

func EffectivePath added in v1.53.0

func EffectivePath(repoURL, customPath string) (string, error)

EffectivePath returns the directory name for a repository: customPath when set, otherwise the name derived from the URL.

func EnsureOnDefaultBranch

func EnsureOnDefaultBranch(ctx context.Context, repoPath string) error

EnsureOnDefaultBranch ensures that the repository is on the default branch (main or master). It dynamically detects the default branch and switches to it if necessary. It takes the repository path `repoPath` as input and returns an error if the operation fails.

func FetchAllPrune added in v1.14.0

func FetchAllPrune(ctx context.Context, repoPath string) error

FetchAllPrune performs git fetch --all --prune for the given repository path.

func FetchAllPruneWithForce added in v1.36.0

func FetchAllPruneWithForce(ctx context.Context, repoPath string) error

FetchAllPruneWithForce performs git fetch --all --prune with --force flag.

func FetchBareRepo

func FetchBareRepo(ctx context.Context, repoPath, workTree string) error

FetchBareRepo fetches updates for a bare repository. It takes the repository path `repoPath` and work tree `workTree` as inputs and returns an error if the operation fails.

func GetCurrentBranch

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

GetCurrentBranch returns the current branch name for the repository.

func GetDevelopBranch

func GetDevelopBranch(ctx context.Context, repoPath string) (string, error)

GetDevelopBranch returns the development branch name for the repository (develop, dev, or development). It checks for common development branch names and returns the one that exists.

func GetGitLabHostAndProjectPath

func GetGitLabHostAndProjectPath(ctx context.Context, repoPath string) (string, string, error)

GetGitLabHostAndProjectPath attempts to detect GitLab host and project path from the current repo remote. It returns host (e.g., gitlab.com) and project path (e.g., group/subgroup/repo).

func GetMainBranch

func GetMainBranch(ctx context.Context, repoPath string) (string, error)

GetMainBranch returns the main branch name for the repository (main or master). It checks for both main and master branches and returns the one that exists.

func InitSubmodules

func InitSubmodules(ctx context.Context, bareRepoPath, worktreeDir string, auth *ssh.PublicKeys) error

InitSubmodules initializes and updates git submodules for a bare repository.

func IsCloned added in v1.34.0

func IsCloned(repoPath string) bool

IsCloned checks if a git repository is cloned at the given path by checking if the `.git` directory exists.

func IsDirty

func IsDirty(ctx context.Context, repoPath string) (bool, error)

IsDirty checks if the repository at the given path has uncommitted changes. It takes the repository path `repoPath` as input and returns a boolean indicating whether the repository is dirty and an error if any occurs.

func PullLatestCode

func PullLatestCode(ctx context.Context, repoPath string) error

PullLatestCode pulls the latest changes from the current branch of the repository. It takes the repository path `repoPath` as input and returns an error if the operation fails. The function automatically detects the current branch and pulls from the corresponding remote.

func PullRebaseBareRepo

func PullRebaseBareRepo(ctx context.Context, repoPath, workTree string) error

PullRebaseBareRepo performs a pull with rebase operation for a bare repository. It takes the repository path `repoPath` and work tree `workTree` as inputs and returns an error if the operation fails.

func RepoNameFromURL added in v1.53.0

func RepoNameFromURL(repoURL string) (string, error)

RepoNameFromURL extracts the repository name from a git URL. Supports both SSH (git@host:path/git.git) and HTTPS (https://host/path/git.git) formats.

Types

type StatusInfo added in v1.19.0

type StatusInfo struct {
	Branch         string
	IsDetached     bool
	AheadCount     int
	BehindCount    int
	HasUpstream    bool
	UnstagedCount  int
	StagedCount    int
	UntrackedCount int
	ConflictCount  int
	OngoingOp      string // "rebase", "merge", "cherry-pick", "bisect", or ""
}

StatusInfo holds detailed git repository status information.

func GetDetailedStatus added in v1.19.0

func GetDetailedStatus(ctx context.Context, repoPath string) (StatusInfo, error)

GetDetailedStatus retrieves rich git status details by running the standard Git CLI.

type TagClobberError added in v1.35.0

type TagClobberError struct {
	Message string
	Output  string
}

TagClobberError is returned when a git fetch fails due to tag conflicts.

func (*TagClobberError) Error added in v1.35.0

func (e *TagClobberError) Error() string

Jump to

Keyboard shortcuts

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