Documentation
¶
Index ¶
- Constants
- func CreateWorkspace(repoPath, workspacePath, branch, base string) error
- func DeleteBranch(repoPath, branch string) error
- func DiscoverWorkspaces(project *data.Project) ([]data.Workspace, error)
- func GetBaseBranch(repoPath string) (string, error)
- func GetCurrentBranch(path string) (string, error)
- func GetRemoteURL(path, remote string) (string, error)
- func GetRepoRoot(path string) (string, error)
- func IsGitRepository(path string) bool
- func RemoveWorkspace(repoPath, workspacePath string) error
- func RunGit(dir string, args ...string) (string, error)
- func RunGitAllowFailure(dir string, args ...string) (string, error)
- func RunGitRaw(dir string, args ...string) ([]byte, error)
- type Change
- type ChangeKind
- type Commit
- type CommitLog
- type DiffLine
- type DiffLineKind
- type DiffMode
- type DiffResult
- type FileWatcher
- type GitError
- type Hunk
- type StatusCache
- type StatusManager
- func (m *StatusManager) GetCached(root string) *StatusResult
- func (m *StatusManager) Invalidate(root string)
- func (m *StatusManager) InvalidateAll()
- func (m *StatusManager) RefreshAll()
- func (m *StatusManager) RequestRefresh(root string)
- func (m *StatusManager) Run(ctx context.Context) error
- func (m *StatusManager) SetCacheTTL(ttl time.Duration)
- func (m *StatusManager) SetDebounceDelay(delay time.Duration)
- func (m *StatusManager) UpdateCache(root string, status *StatusResult)
- type StatusResult
Constants ¶
const ( // LargeFileSizeThreshold is the size above which files are considered "large" LargeFileSizeThreshold = 2 * 1024 * 1024 // 2MB )
Variables ¶
This section is empty.
Functions ¶
func CreateWorkspace ¶ added in v0.0.7
CreateWorkspace creates a new workspace backed by a git worktree
func DeleteBranch ¶
DeleteBranch deletes a git branch
func DiscoverWorkspaces ¶ added in v0.0.7
DiscoverWorkspaces discovers git worktrees for a project. Returns workspaces with minimal fields populated (Name, Branch, Repo, Root). The caller should merge with stored metadata to get full workspace data.
func GetBaseBranch ¶ added in v0.0.3
GetBaseBranch returns the base branch (main, master, or the default branch)
func GetCurrentBranch ¶
GetCurrentBranch returns the current branch name
func GetRemoteURL ¶
GetRemoteURL returns the URL of the specified remote
func GetRepoRoot ¶
GetRepoRoot returns the root directory of the git repository
func IsGitRepository ¶
IsGitRepository checks if the given path is a git repository
func RemoveWorkspace ¶ added in v0.0.7
RemoveWorkspace removes a workspace backed by a git worktree
func RunGitAllowFailure ¶ added in v0.0.3
RunGitAllowFailure executes git and returns stdout even if exit code is non-zero. Use for commands like `git diff --no-index` which return 1 when differences exist.
Types ¶
type Change ¶ added in v0.0.3
type Change struct {
Path string // Current file path
OldPath string // Original path (for renames/copies)
Kind ChangeKind // Type of change
Staged bool // Whether this change is staged
}
Change represents a single file change in git status
func (*Change) DisplayCode ¶ added in v0.0.3
DisplayCode returns a two-character status code for display First char is staged status, second is unstaged status
func (*Change) KindString ¶ added in v0.0.3
KindString returns a display string for the change kind
type ChangeKind ¶ added in v0.0.3
type ChangeKind int
ChangeKind represents the type of change
const ( ChangeModified ChangeKind = iota // File content changed ChangeAdded // New file ChangeDeleted // File removed ChangeRenamed // File renamed ChangeCopied // File copied ChangeUntracked // Untracked file )
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
type DiffLine ¶ added in v0.0.3
type DiffLine struct {
Kind DiffLineKind
Content string
}
DiffLine represents a single line in a diff
type DiffLineKind ¶ added in v0.0.3
type DiffLineKind int
DiffLineKind represents the type of a diff line
const ( DiffLineContext DiffLineKind = iota // Unchanged context line DiffLineAdd // Added line (green) DiffLineDelete // Deleted line (red) DiffLineHeader // File/hunk header )
type DiffResult ¶ added in v0.0.3
type DiffResult struct {
Path string // File path
Content string // Raw diff content
Hunks []Hunk // Parsed hunks for navigation
Lines []DiffLine // Parsed lines for rendering
Binary bool // True if this is a binary file
Large bool // True if the file is too large to display
Empty bool // True if there are no changes
Error string // Error message if diff failed
}
DiffResult holds parsed diff information for a single file
func GetBranchFileDiff ¶ added in v0.0.3
func GetBranchFileDiff(repoPath, path string) (*DiffResult, error)
GetBranchFileDiff returns the full diff for a single file on the branch
func GetCombinedDiff ¶ added in v0.0.3
func GetCombinedDiff(repoPath, path string) (*DiffResult, error)
GetCombinedDiff returns the combined diff for a file that has both staged and unstaged changes
func GetFileDiff ¶ added in v0.0.3
func GetFileDiff(repoPath, path string, mode DiffMode) (*DiffResult, error)
GetFileDiff returns the diff for a specific file
func GetUntrackedFileContent ¶ added in v0.0.3
func GetUntrackedFileContent(repoPath, path string) (*DiffResult, error)
GetUntrackedFileContent returns the content of an untracked file formatted as a diff
func (*DiffResult) AddedLines ¶ added in v0.0.3
func (d *DiffResult) AddedLines() int
AddedLines returns the count of added lines
func (*DiffResult) DeletedLines ¶ added in v0.0.3
func (d *DiffResult) DeletedLines() int
DeletedLines returns the count of deleted lines
func (*DiffResult) HunkCount ¶ added in v0.0.3
func (d *DiffResult) HunkCount() int
HunkCount returns the number of hunks in the diff
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 workspace is being watched
func (*FileWatcher) Run ¶ added in v0.0.5
func (fw *FileWatcher) Run(ctx context.Context) error
run processes file system events Run processes file system events until the context is canceled or the watcher closes.
func (*FileWatcher) Unwatch ¶
func (fw *FileWatcher) Unwatch(root string)
Unwatch stops watching a workspace
func (*FileWatcher) Watch ¶
func (fw *FileWatcher) Watch(root string) error
Watch starts watching a workspace for git changes
type Hunk ¶ added in v0.0.3
type Hunk struct {
OldStart int // Starting line in old file
OldCount int // Number of lines in old file
NewStart int // Starting line in new file
NewCount int // Number of lines in new file
StartLine int // Line index in rendered output (for navigation)
Header string // The full @@ line
}
Hunk represents a single hunk in a diff
type StatusCache ¶
type StatusCache struct {
Status *StatusResult
FetchedAt time.Time
}
StatusCache holds cached git status with TTL
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 workspace, or nil if not cached/expired
func (*StatusManager) Invalidate ¶
func (m *StatusManager) Invalidate(root string)
Invalidate removes a workspace 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 workspaces
func (*StatusManager) RequestRefresh ¶
func (m *StatusManager) RequestRefresh(root string)
RequestRefresh requests an async status refresh for a workspace Uses debouncing to prevent too frequent refreshes
func (*StatusManager) Run ¶ added in v0.0.5
func (m *StatusManager) Run(ctx context.Context) error
Run processes refresh requests until the context is canceled.
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 {
Staged []Change // Changes staged for commit
Unstaged []Change // Changes in working tree (not staged)
Untracked []Change // Untracked files
Clean bool // True if no changes
// Aggregate line-level diff stats
TotalAdded int // Total lines added across all changes
TotalDeleted int // Total lines deleted across all changes
}
StatusResult holds the parsed git status grouped by category
func GetStatus ¶
func GetStatus(repoPath string) (*StatusResult, error)
GetStatus returns the git status for a repository using porcelain v1 -z format This format handles spaces, unicode, and special characters in paths correctly
func (*StatusResult) AllChanges ¶ added in v0.0.3
func (s *StatusResult) AllChanges() []Change
AllChanges returns all changes as a flat list for backwards compatibility
func (*StatusResult) GetDirtyCount ¶
func (s *StatusResult) GetDirtyCount() int
GetDirtyCount returns the number of unique changed files
func (*StatusResult) GetStatusSummary ¶
func (s *StatusResult) GetStatusSummary() string
GetStatusSummary returns a summary string for the status