git

package
v1.7.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BranchExists

func BranchExists(gitDir, branch string) bool

BranchExists checks if a branch exists in the repository

func ConfigureFetchRefspec

func ConfigureFetchRefspec(gitDir, remoteURL string) error

ConfigureFetchRefspec sets up remote.origin.url and fetch refspec in bare repo. This is idempotent - safe to call multiple times.

func CreateWorktree

func CreateWorktree(gitDir, worktreePath, branch, baseBranch string) error

CreateWorktree creates a new worktree from a git directory

func DeleteBranch

func DeleteBranch(gitDir, branch string, force bool) error

DeleteBranch deletes a branch from the repository

func FetchOrigin added in v1.6.0

func FetchOrigin(gitDir string) error

FetchOrigin fetches from the origin remote to update remote-tracking refs.

func FetchRemote

func FetchRemote(gitDir, remote string) error

FetchRemote runs git fetch for the specified remote

func FindGitDir

func FindGitDir(path string) (string, error)

FindGitDir finds the .git directory from a path

func GetBranchRefs

func GetBranchRefs(gitDir string) (local []string, remote []string, err error)

GetBranchRefs returns all local and remote branch names. Local branches are returned as-is (e.g., "main", "feature/foo"). Remote branches are returned with remote prefix (e.g., "origin/main").

func GetCurrentBranch

func GetCurrentBranch(worktreePath string) (string, error)

GetCurrentBranch returns the current branch name, or empty string if detached HEAD

func GetDefaultBranch

func GetDefaultBranch(gitDir string) (string, error)

GetDefaultBranch returns the default branch name

func GetRemoteURL

func GetRemoteURL(gitDir, remote string) (string, error)

GetRemoteURL retrieves the remote URL for a given remote name. Returns empty string and nil error if remote is not configured.

func GetRemoteURLFromWorktree

func GetRemoteURLFromWorktree(worktreePath string) (string, error)

GetRemoteURLFromWorktree extracts remote URL from a worktree's git config.

func GetRepoPath

func GetRepoPath(gitDir string) string

GetRepoPath returns the repository working directory from a git dir

func HasBranchTracking

func HasBranchTracking(gitDir, branch string) (bool, error)

HasBranchTracking checks if a branch has upstream tracking configured.

func HasChanges

func HasChanges(worktreePath string) (bool, error)

HasChanges checks if there are any changes that would be captured by stash This includes tracked modifications and untracked files (but not ignored files)

func HasFetchRefspec

func HasFetchRefspec(gitDir string) (bool, error)

HasFetchRefspec checks if fetch refspec is already configured.

func HasStash

func HasStash(worktreePath string) (bool, error)

HasStash checks if there are any stashes in the repository

func IsDetachedHEAD

func IsDetachedHEAD(worktreePath string) (bool, error)

IsDetachedHEAD checks if the worktree is on a detached HEAD

func IsGitRepo

func IsGitRepo(path string) bool

IsGitRepo checks if a directory is a git repository (has .git directory)

func IsIgnored

func IsIgnored(worktreePath, relativePath string) (bool, error)

IsIgnored reports whether the given path is ignored by git.

func IsMergeInProgress

func IsMergeInProgress(worktreePath string) bool

IsMergeInProgress checks if a merge is currently in progress in the worktree

func IsMerged

func IsMerged(gitDir, branch, targetBranch string) (bool, error)

IsMerged checks if a branch is merged into another branch

func IsRebaseInProgress

func IsRebaseInProgress(worktreePath string) bool

IsRebaseInProgress checks if a rebase is currently in progress in the worktree

func IsWorktreeDirty

func IsWorktreeDirty(worktreePath string) (bool, error)

IsWorktreeDirty checks if the worktree has uncommitted changes

func ListAllBranches

func ListAllBranches(gitDir string) ([]string, error)

ListAllBranches lists all branches including current branch

func ListBranches

func ListBranches(gitDir string) ([]string, error)

ListBranches lists all local branches in the repository (excluding current branch)

func ListLocalBranches

func ListLocalBranches(gitDir string) ([]string, error)

ListLocalBranches returns all local branch names.

func ListRemoteBranches

func ListRemoteBranches(gitDir string) ([]string, error)

ListRemoteBranches lists all remote branches in the repository

func MergeInto

func MergeInto(worktreePath, remote, upstream string) error

MergeInto runs git merge from the current worktree with the specified remote/branch

func PopStash

func PopStash(worktreePath string) error

PopStash pops the most recent stash Returns an error if there are conflicts or if the pop fails

func RebaseOnto

func RebaseOnto(worktreePath, remote, upstream string) error

RebaseOnto runs git rebase from the current worktree onto the specified remote/branch

func RemoveWorktree

func RemoveWorktree(gitDir, worktreePath string, force bool) error

RemoveWorktree removes a worktree using a specific git directory

func SetBranchUpstream

func SetBranchUpstream(gitDir, branch, remote string) error

SetBranchUpstream configures a branch to track a remote. This is idempotent - safe to call multiple times.

func StashAll

func StashAll(worktreePath string, message string) error

StashAll creates a stash including tracked modifications and untracked files This captures tracked modifications and untracked files, but skips ignored files for better performance (ignored files like node_modules, vendor are not touched by git during sync anyway)

Types

type MergeConflictError

type MergeConflictError struct {
	Output string
}

MergeConflictError represents a merge that failed due to conflicts

func (*MergeConflictError) Error

func (e *MergeConflictError) Error() string

type RebaseConflictError

type RebaseConflictError struct {
	Output string
}

RebaseConflictError represents a rebase that failed due to conflicts

func (*RebaseConflictError) Error

func (e *RebaseConflictError) Error() string

type StashConflictError

type StashConflictError struct {
	Output string
}

StashConflictError represents a stash pop that failed due to conflicts

func (*StashConflictError) Error

func (e *StashConflictError) Error() string

type Worktree

type Worktree struct {
	Path      string
	Branch    string
	IsMain    bool
	IsCurrent bool
	IsMerged  bool
}

Worktree represents a git worktree

func ListWorktrees

func ListWorktrees(gitDir string) ([]Worktree, error)

ListWorktrees lists all worktrees for a git repository

func ListWorktreesDetailed

func ListWorktreesDetailed(gitDir, currentWorktreePath, defaultBranch string) ([]Worktree, error)

ListWorktreesDetailed lists all worktrees with additional metadata

func SortWorktrees

func SortWorktrees(worktrees []Worktree, by string, reverse bool) []Worktree

SortWorktrees sorts worktrees by the specified criteria

Jump to

Keyboard shortcuts

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