git

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateWorktree

func CreateWorktree(repoPath, worktreePath, branch, base string) error

CreateWorktree creates a new git worktree

func DeleteBranch

func DeleteBranch(repoPath, branch string) error

DeleteBranch deletes a git branch

func DiscoverWorktrees

func DiscoverWorktrees(project *data.Project) ([]data.Worktree, error)

DiscoverWorktrees discovers all worktrees for a project and converts them to data.Worktree

func GetCurrentBranch

func GetCurrentBranch(path string) (string, error)

GetCurrentBranch returns the current branch name

func GetRemoteURL

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

GetRemoteURL returns the URL of the specified remote

func GetRepoRoot

func GetRepoRoot(path string) (string, error)

GetRepoRoot returns the root directory of the git repository

func IsGitRepository

func IsGitRepository(path string) bool

IsGitRepository checks if the given path is a git repository

func RemoveWorktree

func RemoveWorktree(repoPath, worktreePath string) error

RemoveWorktree removes a git worktree

func RunGit

func RunGit(dir string, args ...string) (string, error)

RunGit executes a git command in the specified directory

Types

type Commit

type Commit struct {
	ShortHash string // Abbreviated SHA (7 chars)
	FullHash  string // Full SHA (40 chars)
	Subject   string // First line of commit message
	Author    string // Author name
	Date      string // Relative date (e.g., "2 hours ago")
	GraphLine string // ASCII graph prefix (e.g., "* ", "| * ", etc.)
	Refs      string // Branch/tag names (e.g., "HEAD -> main, origin/main")
}

Commit represents a parsed git commit with graph information

type CommitLog

type CommitLog struct {
	Commits []Commit
}

CommitLog represents the result of parsing git log output

func GetCommitLog

func GetCommitLog(repoPath string, limit int) (*CommitLog, error)

GetCommitLog returns parsed commits with graph information Default limit is 100 commits

type FileStatus

type FileStatus struct {
	Code string // Two-character status code (e.g., "M ", " M", "??", "A ")
	Path string // File path relative to repo root
}

FileStatus represents the status of a single file

func (*FileStatus) DisplayCode

func (f *FileStatus) DisplayCode() string

DisplayCode returns a user-friendly display code For untracked files, returns "A " instead of "??" to indicate they are additions

func (*FileStatus) IsAdded

func (f *FileStatus) IsAdded() bool

IsAdded checks if a file status represents an addition

func (*FileStatus) IsDeleted

func (f *FileStatus) IsDeleted() bool

IsDeleted checks if a file status represents a deletion

func (*FileStatus) IsDirectory

func (f *FileStatus) IsDirectory() bool

IsDirectory checks if the path is a directory (ends with /)

func (*FileStatus) IsModified

func (f *FileStatus) IsModified() bool

IsModified checks if a file status represents a modification

func (*FileStatus) IsUntracked

func (f *FileStatus) IsUntracked() bool

IsUntracked checks if a file is untracked

type FileWatcher

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

FileWatcher watches git directories for changes and triggers status refreshes

func NewFileWatcher

func NewFileWatcher(onChanged func(root string)) (*FileWatcher, error)

NewFileWatcher creates a new file watcher

func (*FileWatcher) Close

func (fw *FileWatcher) Close() error

Close stops the watcher and releases resources

func (*FileWatcher) IsWatching

func (fw *FileWatcher) IsWatching(root string) bool

IsWatching checks if a worktree is being watched

func (*FileWatcher) Unwatch

func (fw *FileWatcher) Unwatch(root string)

Unwatch stops watching a worktree

func (*FileWatcher) Watch

func (fw *FileWatcher) Watch(root string) error

Watch starts watching a worktree for git changes

type GitError

type GitError struct {
	Command string
	Stderr  string
	Err     error
}

GitError wraps git command errors with additional context

func (*GitError) Error

func (e *GitError) Error() string

func (*GitError) Unwrap

func (e *GitError) Unwrap() error

type StatusCache

type StatusCache struct {
	Status    *StatusResult
	FetchedAt time.Time
}

StatusCache holds cached git status with TTL

func (*StatusCache) IsExpired

func (c *StatusCache) IsExpired(ttl time.Duration) bool

IsExpired checks if the cache entry has expired

type StatusManager

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

StatusManager manages async git status with caching and debouncing

func NewStatusManager

func NewStatusManager(onUpdate func(root string, status *StatusResult, err error)) *StatusManager

NewStatusManager creates a new status manager

func (*StatusManager) GetCached

func (m *StatusManager) GetCached(root string) *StatusResult

GetCached returns the cached status for a worktree, or nil if not cached/expired

func (*StatusManager) Invalidate

func (m *StatusManager) Invalidate(root string)

Invalidate removes a worktree from the cache

func (*StatusManager) InvalidateAll

func (m *StatusManager) InvalidateAll()

InvalidateAll clears the entire cache

func (*StatusManager) RefreshAll

func (m *StatusManager) RefreshAll()

RefreshAll refreshes status for all cached worktrees

func (*StatusManager) RequestRefresh

func (m *StatusManager) RequestRefresh(root string)

RequestRefresh requests an async status refresh for a worktree Uses debouncing to prevent too frequent refreshes

func (*StatusManager) SetCacheTTL

func (m *StatusManager) SetCacheTTL(ttl time.Duration)

SetCacheTTL sets the cache time-to-live

func (*StatusManager) SetDebounceDelay

func (m *StatusManager) SetDebounceDelay(delay time.Duration)

SetDebounceDelay sets the debounce delay

func (*StatusManager) UpdateCache

func (m *StatusManager) UpdateCache(root string, status *StatusResult)

UpdateCache directly updates the cache with a status result (no fetch)

type StatusResult

type StatusResult struct {
	Files []FileStatus
	Clean bool
}

StatusResult holds the parsed git status

func GetStatus

func GetStatus(repoPath string) (*StatusResult, error)

GetStatus returns the git status for a repository Uses -u flag to show individual files in untracked directories

func (*StatusResult) GetDirtyCount

func (s *StatusResult) GetDirtyCount() int

GetDirtyCount returns the number of modified files

func (*StatusResult) GetStatusSummary

func (s *StatusResult) GetStatusSummary() string

GetStatusSummary returns a summary string for the status

type WorktreeEntry

type WorktreeEntry struct {
	Path   string
	Head   string
	Branch string
	Bare   bool
}

WorktreeEntry represents a raw worktree entry from git

func ListWorktrees

func ListWorktrees(repoPath string) ([]WorktreeEntry, error)

ListWorktrees lists all worktrees for a repository

Jump to

Keyboard shortcuts

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