Documentation
¶
Overview ¶
Package git implements the Git CLI wrapper for tracking repository changes.
Index ¶
- func TruncateDiff(diff string, maxSizeKB int) (string, bool)
- type BranchInfo
- type BranchesResult
- type CheckoutResult
- type CommitResult
- type DeleteBranchResult
- type DirectoryEntry
- type EnhancedStatus
- type FetchResult
- type FileEntry
- type GraphLine
- type GraphLineType
- type GraphPosition
- type InitResult
- type LogEntry
- type LogResult
- type MergeResult
- type PullResult
- type PushResult
- type RemoteAddResult
- type RemoteInfo
- type RemoteListResult
- type RemoteRemoveResult
- type SetUpstreamResult
- type StashEntry
- type StashListResult
- type StashResult
- type Status
- type Tracker
- func (t *Tracker) Checkout(ctx context.Context, branch string, create bool) (*CheckoutResult, error)
- func (t *Tracker) Commit(ctx context.Context, message string, push bool) (*CommitResult, error)
- func (t *Tracker) DeleteBranch(ctx context.Context, branch string, force bool) (*DeleteBranchResult, error)
- func (t *Tracker) Diff(ctx context.Context, path string) (string, error)
- func (t *Tracker) DiffAll(ctx context.Context) (map[string]string, error)
- func (t *Tracker) DiffNewFile(ctx context.Context, path string) (string, error)
- func (t *Tracker) DiffStaged(ctx context.Context, path string) (string, error)
- func (t *Tracker) Discard(ctx context.Context, paths []string) error
- func (t *Tracker) Fetch(ctx context.Context, remote string, prune bool) (*FetchResult, error)
- func (t *Tracker) GetDiffForEvent(ctx context.Context, path string, maxDiffSizeKB int) *events.BaseEvent
- func (t *Tracker) GetEnhancedStatus(ctx context.Context) (*EnhancedStatus, error)
- func (t *Tracker) GetFileContent(ctx context.Context, path string, maxSizeKB int) (string, bool, error)
- func (t *Tracker) GetRepoName() string
- func (t *Tracker) GetRepoRoot() string
- func (t *Tracker) GetStatus(ctx context.Context) (*Status, error)
- func (t *Tracker) Init(ctx context.Context, initialBranch string, initialCommit bool, ...) (*InitResult, error)
- func (t *Tracker) IsGitRepo() bool
- func (t *Tracker) ListBranches(ctx context.Context) (*BranchesResult, error)
- func (t *Tracker) ListDirectory(ctx context.Context, path string) ([]DirectoryEntry, error)
- func (t *Tracker) Log(ctx context.Context, limit int, skip int, branch string, path string, ...) (*LogResult, error)
- func (t *Tracker) Merge(ctx context.Context, branch string, noFastForward bool, message string) (*MergeResult, error)
- func (t *Tracker) MergeAbort(ctx context.Context) (*MergeResult, error)
- func (t *Tracker) Pull(ctx context.Context, rebase bool) (*PullResult, error)
- func (t *Tracker) Push(ctx context.Context, force bool, setUpstream bool, remote, branch string) (*PushResult, error)
- func (t *Tracker) RemoteAdd(ctx context.Context, name string, url string, fetch bool) (*RemoteAddResult, error)
- func (t *Tracker) RemoteList(ctx context.Context) (*RemoteListResult, error)
- func (t *Tracker) RemoteRemove(ctx context.Context, name string) (*RemoteRemoveResult, error)
- func (t *Tracker) SetUpstream(ctx context.Context, branch string, upstream string) (*SetUpstreamResult, error)
- func (t *Tracker) Stage(ctx context.Context, paths []string) error
- func (t *Tracker) Stash(ctx context.Context, message string, includeUntracked bool) (*StashResult, error)
- func (t *Tracker) StashApply(ctx context.Context, index int) (*StashResult, error)
- func (t *Tracker) StashDrop(ctx context.Context, index int) (*StashResult, error)
- func (t *Tracker) StashList(ctx context.Context) (*StashListResult, error)
- func (t *Tracker) StashPop(ctx context.Context, index int) (*StashResult, error)
- func (t *Tracker) Status(ctx context.Context) ([]ports.GitFileStatus, error)
- func (t *Tracker) Unstage(ctx context.Context, paths []string) error
- type WorkspaceGitState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BranchInfo ¶
type BranchInfo struct {
Name string `json:"name"`
IsCurrent bool `json:"is_current"`
IsRemote bool `json:"is_remote"`
Upstream string `json:"upstream,omitempty"`
Ahead int `json:"ahead,omitempty"`
Behind int `json:"behind,omitempty"`
}
BranchInfo represents information about a git branch.
type BranchesResult ¶
type BranchesResult struct {
Current string `json:"current"`
Upstream string `json:"upstream,omitempty"`
Ahead int `json:"ahead"`
Behind int `json:"behind"`
Branches []BranchInfo `json:"branches"`
}
BranchesResult represents the result of listing branches.
type CheckoutResult ¶
type CheckoutResult struct {
Success bool `json:"success"`
Branch string `json:"branch,omitempty"`
FromBranch string `json:"from_branch,omitempty"` // Previous branch (for git_branch_changed event)
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
}
CheckoutResult represents the result of a checkout operation.
type CommitResult ¶
type CommitResult struct {
Success bool `json:"success"`
SHA string `json:"sha,omitempty"`
Message string `json:"message,omitempty"`
FilesCommitted int `json:"files_committed,omitempty"`
Pushed bool `json:"pushed,omitempty"`
Error string `json:"error,omitempty"`
}
CommitResult represents the result of a commit operation.
type DeleteBranchResult ¶
type DeleteBranchResult struct {
Success bool `json:"success"`
Branch string `json:"branch"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
}
DeleteBranchResult represents the result of a branch delete operation.
type DirectoryEntry ¶
type DirectoryEntry struct {
Name string `json:"name"`
Type string `json:"type"` // "file" or "directory"
Size *int64 `json:"size,omitempty"`
Modified *string `json:"modified,omitempty"`
ChildrenCount *int `json:"children_count,omitempty"`
}
DirectoryEntry represents a file or directory entry.
type EnhancedStatus ¶
type EnhancedStatus struct {
Branch string `json:"branch"`
Upstream string `json:"upstream,omitempty"`
Ahead int `json:"ahead"`
Behind int `json:"behind"`
Staged []FileEntry `json:"staged"`
Unstaged []FileEntry `json:"unstaged"`
Untracked []FileEntry `json:"untracked"`
Conflicted []FileEntry `json:"conflicted"`
RepoName string `json:"repo_name"`
RepoRoot string `json:"repo_root"`
}
EnhancedStatus represents enhanced git status with staging information.
type FetchResult ¶
type FetchResult struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
UpdatedRefs []string `json:"updated_refs,omitempty"`
NewBranches []string `json:"new_branches,omitempty"`
PrunedBranches []string `json:"pruned_branches,omitempty"`
}
FetchResult represents the result of a fetch operation.
type FileEntry ¶
type FileEntry struct {
Path string `json:"path"`
Status string `json:"status"`
Additions int `json:"additions,omitempty"`
Deletions int `json:"deletions,omitempty"`
}
FileEntry represents a file in git status with diff stats.
type GraphLine ¶
type GraphLine struct {
FromColumn int `json:"from_column"`
ToColumn int `json:"to_column"`
Type GraphLineType `json:"type"`
}
GraphLine represents a line segment in the git graph.
type GraphLineType ¶
type GraphLineType string
GraphLineType represents the type of line in a git graph.
const ( GraphLineStraight GraphLineType = "straight" GraphLineMergeLeft GraphLineType = "merge_left" GraphLineMergeRight GraphLineType = "merge_right" GraphLineBranchLeft GraphLineType = "branch_left" GraphLineBranchRight GraphLineType = "branch_right" GraphLinePass GraphLineType = "pass" )
type GraphPosition ¶
GraphPosition represents the position of a commit in the git graph.
type InitResult ¶
type InitResult struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
Branch string `json:"branch,omitempty"`
CommitSHA string `json:"commit_sha,omitempty"`
FilesCommitted int `json:"files_committed,omitempty"`
}
InitResult represents the result of a git init operation.
type LogEntry ¶
type LogEntry struct {
SHA string `json:"sha"`
ShortSHA string `json:"short_sha"`
Author string `json:"author"`
AuthorEmail string `json:"author_email"`
Date string `json:"date"`
RelativeDate string `json:"relative_date"`
Subject string `json:"subject"`
Body string `json:"body,omitempty"`
ParentSHAs []string `json:"parent_shas,omitempty"`
IsMerge bool `json:"is_merge"`
GraphPosition *GraphPosition `json:"graph_position,omitempty"`
}
LogEntry represents a single commit in the log.
type LogResult ¶
type LogResult struct {
Commits []LogEntry `json:"commits"`
TotalCount int `json:"total_count"`
HasMore bool `json:"has_more"`
MaxColumns int `json:"max_columns,omitempty"`
}
LogResult represents the result of a log operation.
type MergeResult ¶
type MergeResult struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
CommitSHA string `json:"commit_sha,omitempty"`
HasConflicts bool `json:"has_conflicts"`
ConflictedFiles []string `json:"conflicted_files,omitempty"`
}
MergeResult represents the result of a merge operation.
type PullResult ¶
type PullResult struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
CommitsPulled int `json:"commits_pulled,omitempty"`
FilesChanged int `json:"files_changed,omitempty"`
ConflictedFiles []string `json:"conflicted_files,omitempty"`
Error string `json:"error,omitempty"`
}
PullResult represents the result of a pull operation.
type PushResult ¶
type PushResult struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
CommitsPushed int `json:"commits_pushed,omitempty"`
Error string `json:"error,omitempty"`
}
PushResult represents the result of a push operation.
type RemoteAddResult ¶
type RemoteAddResult struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
Remote *RemoteInfo `json:"remote,omitempty"`
FetchedBranches []string `json:"fetched_branches,omitempty"`
}
RemoteAddResult represents the result of adding a remote.
type RemoteInfo ¶
type RemoteInfo struct {
Name string `json:"name"`
FetchURL string `json:"fetch_url"`
PushURL string `json:"push_url"`
Provider string `json:"provider,omitempty"`
TrackingBranches []string `json:"tracking_branches,omitempty"`
}
RemoteInfo represents information about a git remote.
type RemoteListResult ¶
type RemoteListResult struct {
Remotes []RemoteInfo `json:"remotes"`
}
RemoteListResult represents the result of listing remotes.
type RemoteRemoveResult ¶
type RemoteRemoveResult struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
}
RemoteRemoveResult represents the result of removing a remote.
type SetUpstreamResult ¶
type SetUpstreamResult struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
Branch string `json:"branch,omitempty"`
Upstream string `json:"upstream,omitempty"`
}
SetUpstreamResult represents the result of setting upstream.
type StashEntry ¶
type StashEntry struct {
Index int `json:"index"`
Name string `json:"name"`
Branch string `json:"branch"`
Message string `json:"message"`
}
StashEntry represents a single stash entry.
type StashListResult ¶
type StashListResult struct {
Stashes []StashEntry `json:"stashes"`
Count int `json:"count"`
}
StashListResult represents the result of listing stashes.
type StashResult ¶
type StashResult struct {
Success bool `json:"success"`
Message string `json:"message,omitempty"`
Error string `json:"error,omitempty"`
Name string `json:"name,omitempty"`
}
StashResult represents the result of a stash operation.
type Status ¶
type Status struct {
IsGitRepo bool `json:"is_git_repo"`
HasCommits bool `json:"has_commits"`
State WorkspaceGitState `json:"state"`
Branch string `json:"branch,omitempty"`
Upstream string `json:"upstream,omitempty"`
Ahead int `json:"ahead"`
Behind int `json:"behind"`
Staged []FileEntry `json:"staged"`
Unstaged []FileEntry `json:"unstaged"`
Untracked []FileEntry `json:"untracked"`
Conflicted []FileEntry `json:"conflicted"`
HasConflicts bool `json:"has_conflicts"`
Remotes []RemoteInfo `json:"remotes,omitempty"`
RepoName string `json:"repo_name,omitempty"`
RepoRoot string `json:"repo_root,omitempty"`
}
Status represents the full git status of a workspace.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker implements the GitTracker port interface.
func NewTracker ¶
NewTracker creates a new Git tracker.
func (*Tracker) Checkout ¶
func (t *Tracker) Checkout(ctx context.Context, branch string, create bool) (*CheckoutResult, error)
Checkout switches branches or creates a new branch.
func (*Tracker) DeleteBranch ¶
func (t *Tracker) DeleteBranch(ctx context.Context, branch string, force bool) (*DeleteBranchResult, error)
DeleteBranch deletes a local branch.
func (*Tracker) DiffNewFile ¶
DiffNewFile generates a diff-like output for untracked/new files. This reads the file content and formats it as if it were a git diff with all additions.
func (*Tracker) DiffStaged ¶
DiffStaged returns the staged diff for a specific file.
func (*Tracker) Discard ¶
Discard discards uncommitted changes (restore files to last commit). Handles tracked files (checkout), staged files (unstage + checkout), and untracked files (delete).
func (*Tracker) GetDiffForEvent ¶
func (t *Tracker) GetDiffForEvent(ctx context.Context, path string, maxDiffSizeKB int) *events.BaseEvent
GetDiffForEvent generates a git diff event for a file change.
func (*Tracker) GetEnhancedStatus ¶
func (t *Tracker) GetEnhancedStatus(ctx context.Context) (*EnhancedStatus, error)
GetEnhancedStatus returns comprehensive git status including staging info.
func (*Tracker) GetFileContent ¶
func (t *Tracker) GetFileContent(ctx context.Context, path string, maxSizeKB int) (string, bool, error)
GetFileContent returns the content of a file from the repository. Security: Uses os.ReadFile instead of shell command, with proper path validation.
func (*Tracker) GetRepoName ¶
GetRepoName returns the name of the repository.
func (*Tracker) GetRepoRoot ¶
GetRepoRoot returns the root path of the git repository.
func (*Tracker) Init ¶
func (t *Tracker) Init(ctx context.Context, initialBranch string, initialCommit bool, commitMessage string) (*InitResult, error)
Init initializes a git repository.
func (*Tracker) ListBranches ¶
func (t *Tracker) ListBranches(ctx context.Context) (*BranchesResult, error)
ListBranches lists all branches with info.
func (*Tracker) ListDirectory ¶
ListDirectory returns entries in a directory.
func (*Tracker) Log ¶
func (t *Tracker) Log(ctx context.Context, limit int, skip int, branch string, path string, graph bool) (*LogResult, error)
Log returns commit history.
func (*Tracker) Merge ¶
func (t *Tracker) Merge(ctx context.Context, branch string, noFastForward bool, message string) (*MergeResult, error)
Merge merges a branch into the current branch.
func (*Tracker) MergeAbort ¶
func (t *Tracker) MergeAbort(ctx context.Context) (*MergeResult, error)
MergeAbort aborts an in-progress merge.
func (*Tracker) Push ¶
func (t *Tracker) Push(ctx context.Context, force bool, setUpstream bool, remote, branch string) (*PushResult, error)
Push pushes commits to remote.
func (*Tracker) RemoteAdd ¶
func (t *Tracker) RemoteAdd(ctx context.Context, name string, url string, fetch bool) (*RemoteAddResult, error)
RemoteAdd adds a new remote.
func (*Tracker) RemoteList ¶
func (t *Tracker) RemoteList(ctx context.Context) (*RemoteListResult, error)
RemoteList returns all configured remotes.
func (*Tracker) RemoteRemove ¶
RemoteRemove removes a remote.
func (*Tracker) SetUpstream ¶
func (t *Tracker) SetUpstream(ctx context.Context, branch string, upstream string) (*SetUpstreamResult, error)
SetUpstream sets the upstream tracking branch.
func (*Tracker) Stash ¶
func (t *Tracker) Stash(ctx context.Context, message string, includeUntracked bool) (*StashResult, error)
Stash creates a new stash.
func (*Tracker) StashApply ¶
StashApply applies a stash without removing it.
func (*Tracker) StashList ¶
func (t *Tracker) StashList(ctx context.Context) (*StashListResult, error)
StashList returns all stash entries.
type WorkspaceGitState ¶
type WorkspaceGitState string
WorkspaceGitState represents the git state of a workspace.
const ( GitStateNoGit WorkspaceGitState = "no_git" GitStateInitialized WorkspaceGitState = "git_init" GitStateNoRemote WorkspaceGitState = "no_remote" GitStateNoPush WorkspaceGitState = "no_push" GitStateSynced WorkspaceGitState = "synced" GitStateDiverged WorkspaceGitState = "diverged" GitStateConflict WorkspaceGitState = "conflict" )