git

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package git wraps git commands and helpers used by lazyworktree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NotifyFn

type NotifyFn func(message string, severity string)

NotifyFn receives ongoing notifications.

type NotifyOnceFn

type NotifyOnceFn func(key string, message string, severity string)

NotifyOnceFn reports deduplicated notification messages.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service orchestrates git and helper commands for the UI.

func NewService

func NewService(notify NotifyFn, notifyOnce NotifyOnceFn) *Service

NewService constructs a Service and sets up concurrency limits.

func (*Service) ApplyDelta

func (s *Service) ApplyDelta(ctx context.Context, diff string) string

ApplyDelta pipes diff output through delta if available ApplyDelta pipes diff output through delta when available.

func (*Service) BuildThreePartDiff

func (s *Service) BuildThreePartDiff(ctx context.Context, path string, cfg *config.AppConfig) string

BuildThreePartDiff assembles a comprehensive diff showing staged, modified, and untracked sections. The output is truncated according to cfg.MaxDiffChars and cfg.MaxUntrackedDiffs settings. Part 1: Staged changes (git diff --cached) Part 2: Unstaged changes (git diff) Part 3: Untracked files (limited by MaxUntrackedDiffs)

func (*Service) CherryPickCommit added in v1.12.0

func (s *Service) CherryPickCommit(ctx context.Context, commitSHA, targetPath string) (bool, error)

CherryPickCommit applies a commit to a target worktree. Returns true on success, false on failure (including conflicts).

func (*Service) CreateWorktreeFromPR added in v1.2.0

func (s *Service) CreateWorktreeFromPR(ctx context.Context, prNumber int, remoteBranch, localBranch, targetPath string) bool

CreateWorktreeFromPR creates a worktree from a PR's remote branch. It creates a detached worktree first, then uses gh/glab CLI to checkout the PR inside that worktree, which properly sets up fork remotes and tracking.

func (*Service) ExecuteCommands

func (s *Service) ExecuteCommands(ctx context.Context, cmdList []string, cwd string, env map[string]string) error

ExecuteCommands runs provided shell commands sequentially inside the given working directory.

func (*Service) FetchAllOpenPRs added in v1.2.0

func (s *Service) FetchAllOpenPRs(ctx context.Context) ([]*models.PRInfo, error)

FetchAllOpenPRs fetches all open PRs/MRs and returns them as a slice.

func (*Service) FetchCIStatus

func (s *Service) FetchCIStatus(ctx context.Context, prNumber int, branch string) ([]*models.CICheck, error)

FetchCIStatus fetches CI check statuses for a PR from GitHub or GitLab.

func (*Service) FetchPRForWorktree added in v1.13.0

func (s *Service) FetchPRForWorktree(ctx context.Context, worktreePath string) *models.PRInfo

FetchPRForWorktree fetches PR info for a specific worktree by running gh/glab in that directory. This correctly detects PRs even when the local branch name differs from the remote branch.

func (*Service) FetchPRMap

func (s *Service) FetchPRMap(ctx context.Context) (map[string]*models.PRInfo, error)

FetchPRMap gathers PR/MR information via supported host APIs (GitHub or GitLab). Returns a map keyed by branch name to PRInfo. Detects the host automatically based on the repository's remote URL.

func (*Service) GetMainBranch

func (s *Service) GetMainBranch(ctx context.Context) string

GetMainBranch returns the main branch name for the current repository.

func (*Service) GetMainWorktreePath

func (s *Service) GetMainWorktreePath(ctx context.Context) string

GetMainWorktreePath returns the path of the main worktree.

func (*Service) GetWorktrees

func (s *Service) GetWorktrees(ctx context.Context) ([]*models.WorktreeInfo, error)

GetWorktrees parses git worktree metadata and returns the list of worktrees. This method concurrently fetches status information for each worktree to improve performance. The first worktree in the list is marked as the main worktree.

func (*Service) RenameWorktree

func (s *Service) RenameWorktree(ctx context.Context, oldPath, newPath, oldBranch, newBranch string) bool

RenameWorktree attempts to move and rename branches for a worktree migration.

func (*Service) ResolveRepoName

func (s *Service) ResolveRepoName(ctx context.Context) string

ResolveRepoName resolves the repository name using various methods. ResolveRepoName returns the repository identifier for caching purposes.

func (*Service) RunCommandChecked

func (s *Service) RunCommandChecked(ctx context.Context, args []string, cwd, errorPrefix string) bool

RunCommandChecked runs the provided git command and reports failures via notify callbacks.

func (*Service) RunGit

func (s *Service) RunGit(ctx context.Context, args []string, cwd string, okReturncodes []int, strip, silent bool) string

RunGit executes a git command and optionally trims its output.

func (*Service) SetDebugLogger added in v1.4.0

func (s *Service) SetDebugLogger(logger *log.Logger)

SetDebugLogger attaches a logger for debug output.

func (*Service) SetDeltaArgs added in v1.4.0

func (s *Service) SetDeltaArgs(args []string)

SetDeltaArgs sets additional delta arguments used when formatting diffs.

func (*Service) SetDeltaPath added in v1.5.1

func (s *Service) SetDeltaPath(path string)

SetDeltaPath sets the path to delta executable and enables/disables based on empty string.

func (*Service) UseDelta

func (s *Service) UseDelta() bool

UseDelta reports whether delta integration is enabled.

Jump to

Keyboard shortcuts

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