Documentation
¶
Overview ¶
Package git wraps git commands and helpers used by lazyworktree.
Index ¶
- Variables
- type NotifyFn
- type NotifyOnceFn
- type Service
- func (s *Service) ApplyGitPager(ctx context.Context, diff string) string
- func (s *Service) BuildThreePartDiff(ctx context.Context, path string, cfg *config.AppConfig) string
- func (s *Service) CherryPickCommit(ctx context.Context, commitSHA, targetPath string) (bool, error)
- func (s *Service) CreateWorktreeFromPR(ctx context.Context, prNumber int, ...) bool
- func (s *Service) DetectHost(ctx context.Context) string
- func (s *Service) ExecuteCommands(ctx context.Context, cmdList []string, cwd string, env map[string]string) error
- func (s *Service) FetchAllOpenIssues(ctx context.Context) ([]*models.IssueInfo, error)
- func (s *Service) FetchAllOpenPRs(ctx context.Context) ([]*models.PRInfo, error)
- func (s *Service) FetchCIStatus(ctx context.Context, prNumber int, branch string) ([]*models.CICheck, error)
- func (s *Service) FetchCIStatusByCommit(ctx context.Context, commitSHA, worktreePath string) ([]*models.CICheck, error)
- func (s *Service) FetchPRForWorktree(ctx context.Context, worktreePath string) *models.PRInfo
- func (s *Service) FetchPRForWorktreeWithError(ctx context.Context, worktreePath string) (*models.PRInfo, error)
- func (s *Service) FetchPRMap(ctx context.Context) (map[string]*models.PRInfo, error)
- func (s *Service) GetCommitFiles(ctx context.Context, commitSHA, worktreePath string) ([]models.CommitFile, error)
- func (s *Service) GetCurrentBranch(ctx context.Context) (string, error)
- func (s *Service) GetHeadSHA(ctx context.Context, worktreePath string) string
- func (s *Service) GetMainBranch(ctx context.Context) string
- func (s *Service) GetMainWorktreePath(ctx context.Context) string
- func (s *Service) GetMergedBranches(ctx context.Context, baseBranch string) []string
- func (s *Service) GetWorktrees(ctx context.Context) ([]*models.WorktreeInfo, error)
- func (s *Service) IsGitHub(ctx context.Context) bool
- func (s *Service) IsGitHubOrGitLab(ctx context.Context) bool
- func (s *Service) RenameWorktree(ctx context.Context, oldPath, newPath, oldBranch, newBranch string) bool
- func (s *Service) ResolveRepoName(ctx context.Context) string
- func (s *Service) RunCommandChecked(ctx context.Context, args []string, cwd, errorPrefix string) bool
- func (s *Service) RunGit(ctx context.Context, args []string, cwd string, okReturncodes []int, ...) string
- func (s *Service) SetGitPager(pager string)
- func (s *Service) SetGitPagerArgs(args []string)
- func (s *Service) UseGitPager() bool
Constants ¶
This section is empty.
Variables ¶
var LookupPath = exec.LookPath
LookupPath is used to find executables in PATH. It's exposed as a package variable so tests can mock it and avoid depending on system binaries being installed.
Functions ¶
This section is empty.
Types ¶
type NotifyOnceFn ¶
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) ApplyGitPager ¶ added in v1.22.0
ApplyGitPager pipes diff output through the configured git pager 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
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 fetches the PR head commit, creates a worktree at that commit with a proper branch, and sets up branch tracking configuration (replicating what gh/glab pr checkout does).
func (*Service) DetectHost ¶ added in v1.24.0
DetectHost detects the git host (github, gitlab, or unknown)
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) FetchAllOpenIssues ¶ added in v1.20.0
FetchAllOpenIssues fetches all open issues and returns them as a slice.
func (*Service) FetchAllOpenPRs ¶ added in v1.2.0
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) FetchCIStatusByCommit ¶ added in v1.28.0
func (s *Service) FetchCIStatusByCommit(ctx context.Context, commitSHA, worktreePath string) ([]*models.CICheck, error)
FetchCIStatusByCommit fetches CI check statuses for a commit SHA (GitHub only). This is used for branches without an associated PR.
func (*Service) FetchPRForWorktree ¶ added in v1.13.0
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. Maintains backward compatibility by swallowing errors.
func (*Service) FetchPRForWorktreeWithError ¶ added in v1.24.0
func (s *Service) FetchPRForWorktreeWithError(ctx context.Context, worktreePath string) (*models.PRInfo, error)
FetchPRForWorktreeWithError fetches PR info and returns detailed error information.
func (*Service) FetchPRMap ¶
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) GetCommitFiles ¶ added in v1.17.0
func (s *Service) GetCommitFiles(ctx context.Context, commitSHA, worktreePath string) ([]models.CommitFile, error)
GetCommitFiles returns the list of files changed in a specific commit.
func (*Service) GetCurrentBranch ¶ added in v1.26.0
GetCurrentBranch returns the current branch name from the current working directory. Returns an error if not in a git repository or if HEAD is detached.
func (*Service) GetHeadSHA ¶ added in v1.28.0
GetHeadSHA returns the HEAD commit SHA for a worktree path.
func (*Service) GetMainBranch ¶
GetMainBranch returns the main branch name for the current repository.
func (*Service) GetMainWorktreePath ¶
GetMainWorktreePath returns the path of the main worktree.
func (*Service) GetMergedBranches ¶ added in v1.22.0
GetMergedBranches returns local branches that have been merged into the specified base branch.
func (*Service) GetWorktrees ¶
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) IsGitHub ¶ added in v1.28.0
IsGitHub returns true if the repository is connected to GitHub.
func (*Service) IsGitHubOrGitLab ¶ added in v1.24.0
IsGitHubOrGitLab returns true if the repository is connected to GitHub or GitLab.
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 ¶
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) SetGitPager ¶ added in v1.22.0
SetGitPager sets the diff formatter/pager command and enables/disables based on empty string.
func (*Service) SetGitPagerArgs ¶ added in v1.22.0
SetGitPagerArgs sets additional arguments used when formatting diffs.
func (*Service) UseGitPager ¶ added in v1.22.0
UseGitPager reports whether diff pager integration is enabled.