Documentation
¶
Overview ¶
Package git provides a wrapper for git operations via subprocess.
Index ¶
- Variables
- func CheckExcludedFilesExist(repoPath string) []string
- func ConfigureSparseCheckout(repoPath string) error
- func IsSparseCheckoutConfigured(repoPath string) bool
- type Git
- func (g *Git) AbortMerge() error
- func (g *Git) AbortRebase() error
- func (g *Git) Add(paths ...string) error
- func (g *Git) BranchCreatedDate(branch string) (string, error)
- func (g *Git) BranchExists(name string) (bool, error)
- func (g *Git) BranchPushedToRemote(localBranch, remote string) (bool, int, error)
- func (g *Git) CheckConflicts(source, target string) ([]string, error)
- func (g *Git) CheckUncommittedWork() (*UncommittedWorkStatus, error)
- func (g *Git) Checkout(ref string) error
- func (g *Git) Clone(url, dest string) error
- func (g *Git) CloneBare(url, dest string) error
- func (g *Git) CloneBareWithReference(url, dest, reference string) error
- func (g *Git) CloneWithReference(url, dest, reference string) error
- func (g *Git) Commit(message string) error
- func (g *Git) CommitAll(message string) error
- func (g *Git) CommitsAhead(base, branch string) (int, error)
- func (g *Git) CountCommitsBehind(ref string) (int, error)
- func (g *Git) CreateBranch(name string) error
- func (g *Git) CreateBranchFrom(name, ref string) error
- func (g *Git) CurrentBranch() (string, error)
- func (g *Git) DefaultBranch() string
- func (g *Git) DeleteBranch(name string, force bool) error
- func (g *Git) DeleteRemoteBranch(remote, branch string) error
- func (g *Git) Fetch(remote string) error
- func (g *Git) FetchBranch(remote, branch string) error
- func (g *Git) HasUncommittedChanges() (bool, error)
- func (g *Git) IsAncestor(ancestor, descendant string) (bool, error)
- func (g *Git) IsRepo() bool
- func (g *Git) ListBranches(pattern string) ([]string, error)
- func (g *Git) Merge(branch string) error
- func (g *Git) MergeNoFF(branch, message string) error
- func (g *Git) Pull(remote, branch string) error
- func (g *Git) Push(remote, branch string, force bool) error
- func (g *Git) Rebase(onto string) error
- func (g *Git) RemoteBranchExists(remote, branch string) (bool, error)
- func (g *Git) RemoteDefaultBranch() string
- func (g *Git) RemoteURL(remote string) (string, error)
- func (g *Git) Remotes() ([]string, error)
- func (g *Git) ResetBranch(name, ref string) error
- func (g *Git) Rev(ref string) (string, error)
- func (g *Git) StashCount() (int, error)
- func (g *Git) Status() (*GitStatus, error)
- func (g *Git) UnpushedCommits() (int, error)
- func (g *Git) WorkDir() string
- func (g *Git) WorktreeAdd(path, branch string) error
- func (g *Git) WorktreeAddDetached(path, ref string) error
- func (g *Git) WorktreeAddExisting(path, branch string) error
- func (g *Git) WorktreeAddExistingForce(path, branch string) error
- func (g *Git) WorktreeAddFromRef(path, branch, startPoint string) error
- func (g *Git) WorktreeList() ([]Worktree, error)
- func (g *Git) WorktreePrune() error
- func (g *Git) WorktreeRemove(path string, force bool) error
- type GitStatus
- type UncommittedWorkStatus
- type Worktree
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotARepo = errors.New("not a git repository") ErrMergeConflict = errors.New("merge conflict") ErrAuthFailure = errors.New("authentication failed") ErrRebaseConflict = errors.New("rebase conflict") )
Common errors
var ExcludedContextFiles = []string{
".cursor",
".mcp.json",
}
ExcludedContextFiles lists all context files that should be excluded by sparse checkout.
Functions ¶
func CheckExcludedFilesExist ¶
CheckExcludedFilesExist checks if any context files still exist in the repo after sparse checkout was configured. These files should have been removed by git read-tree, but may remain if they were untracked or modified. Returns a list of files that still exist and should be manually removed.
func ConfigureSparseCheckout ¶
ConfigureSparseCheckout sets up sparse checkout for a clone or worktree to exclude .cursor/. This ensures source repo settings don't override Gas Town agent settings. Exported for use by doctor checks.
func IsSparseCheckoutConfigured ¶
IsSparseCheckoutConfigured checks if sparse checkout is enabled and configured to exclude Cursor context files for a given repo/worktree. Returns true only if both core.sparseCheckout is true AND the sparse-checkout file contains all required exclusion patterns.
Types ¶
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git wraps git operations for a working directory.
func NewGitWithDir ¶
NewGitWithDir creates a Git wrapper with an explicit git directory. This is used for bare repos where gitDir points to the .git directory and workDir may be empty or point to a worktree.
func (*Git) AbortRebase ¶
AbortRebase aborts a rebase in progress.
func (*Git) BranchCreatedDate ¶
BranchCreatedDate returns the date when a branch was created. This uses the committer date of the first commit on the branch. Returns date in YYYY-MM-DD format.
func (*Git) BranchExists ¶
BranchExists checks if a branch exists locally.
func (*Git) BranchPushedToRemote ¶
BranchPushedToRemote checks if a branch has been pushed to the remote. Returns (pushed bool, unpushedCount int, err). This handles polecat branches that don't have upstream tracking configured.
func (*Git) CheckConflicts ¶
CheckConflicts performs a test merge to check if source can be merged into target without conflicts. Returns a list of conflicting files, or empty slice if clean. The merge is always aborted after checking - no actual changes are made.
The caller must ensure the working directory is clean before calling this. After return, the working directory is restored to the target branch.
func (*Git) CheckUncommittedWork ¶
func (g *Git) CheckUncommittedWork() (*UncommittedWorkStatus, error)
CheckUncommittedWork performs a comprehensive check for uncommitted work.
func (*Git) CloneBare ¶
CloneBare clones a repository as a bare repo (no working directory). This is used for the shared repo architecture where all worktrees share a single git database.
func (*Git) CloneBareWithReference ¶
CloneBareWithReference clones a bare repository using a local repo as an object reference.
func (*Git) CloneWithReference ¶
CloneWithReference clones a repository using a local repo as an object reference. This saves disk by sharing objects without changing remotes.
func (*Git) CommitsAhead ¶
CommitsAhead returns the number of commits that branch has ahead of base. For example, CommitsAhead("main", "feature") returns how many commits are on feature that are not on main.
func (*Git) CountCommitsBehind ¶
CountCommitsBehind returns the number of commits that HEAD is behind the given ref. For example, CountCommitsBehind("origin/main") returns how many commits are on origin/main that are not on the current HEAD.
func (*Git) CreateBranch ¶
CreateBranch creates a new branch.
func (*Git) CreateBranchFrom ¶
CreateBranchFrom creates a new branch from a specific ref.
func (*Git) CurrentBranch ¶
CurrentBranch returns the current branch name.
func (*Git) DefaultBranch ¶
DefaultBranch returns the default branch name (what HEAD points to). This works for both regular and bare repositories. Returns "main" as fallback if detection fails.
func (*Git) DeleteBranch ¶
DeleteBranch deletes a local branch.
func (*Git) DeleteRemoteBranch ¶
DeleteRemoteBranch deletes a branch on the remote.
func (*Git) FetchBranch ¶
FetchBranch fetches a specific branch from the remote.
func (*Git) HasUncommittedChanges ¶
HasUncommittedChanges returns true if there are uncommitted changes.
func (*Git) IsAncestor ¶
IsAncestor checks if ancestor is an ancestor of descendant.
func (*Git) ListBranches ¶
ListBranches returns all local branches matching a pattern. Pattern uses git's pattern matching (e.g., "polecat/*" matches all polecat branches). Returns branch names without the refs/heads/ prefix.
func (*Git) RemoteBranchExists ¶
RemoteBranchExists checks if a branch exists on the remote.
func (*Git) RemoteDefaultBranch ¶
RemoteDefaultBranch returns the default branch from the remote (origin). This is useful in worktrees where HEAD may not reflect the repo's actual default. Checks origin/HEAD first, then falls back to checking if master/main exists. Returns "main" as final fallback.
func (*Git) ResetBranch ¶
ResetBranch force-updates a branch to point to a ref. This is useful for resetting stale polecat branches to main.
func (*Git) StashCount ¶
StashCount returns the number of stashes in the repository.
func (*Git) UnpushedCommits ¶
UnpushedCommits returns the number of commits that are not pushed to the remote. It checks if the current branch has an upstream and counts commits ahead. Returns 0 if there is no upstream configured.
func (*Git) WorktreeAdd ¶
WorktreeAdd creates a new worktree at the given path with a new branch. The new branch is created from the current HEAD. Sparse checkout is enabled to exclude .cursor/ from source repos.
func (*Git) WorktreeAddDetached ¶
WorktreeAddDetached creates a new worktree at the given path with a detached HEAD. Sparse checkout is enabled to exclude .cursor/ from source repos.
func (*Git) WorktreeAddExisting ¶
WorktreeAddExisting creates a new worktree at the given path for an existing branch. Sparse checkout is enabled to exclude .cursor/ from source repos.
func (*Git) WorktreeAddExistingForce ¶
WorktreeAddExistingForce creates a new worktree even if the branch is already checked out elsewhere. This is useful for cross-rig worktrees where multiple clones need to be on main. Sparse checkout is enabled to exclude .cursor/ from source repos.
func (*Git) WorktreeAddFromRef ¶
WorktreeAddFromRef creates a new worktree at the given path with a new branch starting from the specified ref (e.g., "origin/main"). Sparse checkout is enabled to exclude .cursor/ from source repos.
func (*Git) WorktreeList ¶
WorktreeList returns all worktrees for this repository.
func (*Git) WorktreePrune ¶
WorktreePrune removes worktree entries for deleted paths.
type GitStatus ¶
type GitStatus struct {
Clean bool
Modified []string
Added []string
Deleted []string
Untracked []string
}
GitStatus represents the status of the working directory.
type UncommittedWorkStatus ¶
type UncommittedWorkStatus struct {
HasUncommittedChanges bool
StashCount int
UnpushedCommits int
// Details for error messages
ModifiedFiles []string
UntrackedFiles []string
}
UncommittedWorkStatus contains information about uncommitted work in a repo.
func (*UncommittedWorkStatus) Clean ¶
func (s *UncommittedWorkStatus) Clean() bool
Clean returns true if there is no uncommitted work.
func (*UncommittedWorkStatus) String ¶
func (s *UncommittedWorkStatus) String() string
String returns a human-readable summary of uncommitted work.