Documentation
¶
Overview ¶
Package git provides Git operations for PR workflows including platform detection and worktree management.
Index ¶
- func BranchExists(branchName string) (bool, error)
- func CleanupWorktree(info *WorktreeInfo) error
- func DeleteRemoteBranch(branchName string) error
- func FetchOrigin() error
- func GetBaseBranch(preferredBase string) (string, error)
- func GetOriginURL() (string, error)
- func GetRepoRoot() (string, error)
- func PathExistsOnRef(ref, path string) (bool, error)
- type Platform
- type PlatformInfo
- type WorktreeConfig
- type WorktreeInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BranchExists ¶
BranchExists checks if a branch exists on the origin remote.
func CleanupWorktree ¶
func CleanupWorktree(info *WorktreeInfo) error
CleanupWorktree removes a git worktree and its associated branch. It is safe to call multiple times.
func DeleteRemoteBranch ¶
DeleteRemoteBranch deletes a branch from the origin remote.
func FetchOrigin ¶
func FetchOrigin() error
FetchOrigin fetches the latest refs from the origin remote.
func GetBaseBranch ¶
GetBaseBranch determines the appropriate base branch to use for a PR. If preferredBase is provided and exists, it returns origin/<preferredBase>. Otherwise, it auto-detects origin/main or falls back to origin/master.
func GetOriginURL ¶
GetOriginURL retrieves the URL for the 'origin' remote. Returns an error if not in a git repository or if no origin remote exists.
func GetRepoRoot ¶
GetRepoRoot returns the absolute path to the root of the git repository. Returns an error if not in a git repository.
func PathExistsOnRef ¶
PathExistsOnRef checks if a given path exists on a specific git ref. The ref should be a full ref like "origin/main" or "origin/master". The path should be relative to the repository root.
Types ¶
type Platform ¶
type Platform string
Platform represents a Git hosting platform.
const ( // PlatformGitHub represents GitHub. PlatformGitHub Platform = "github" // PlatformGitLab represents GitLab. PlatformGitLab Platform = "gitlab" // PlatformGitea represents Gitea or Forgejo. PlatformGitea Platform = "gitea" // PlatformBitbucket represents Bitbucket. PlatformBitbucket Platform = "bitbucket" // PlatformUnknown represents an unknown or unsupported platform. PlatformUnknown Platform = "unknown" )
type PlatformInfo ¶
type PlatformInfo struct {
Platform Platform // The detected platform
CLITool string // CLI tool for PR creation: "gh", "glab", "tea", or ""
RepoURL string // Base URL for generating manual PR URLs
Owner string // Repository owner/organization
Repo string // Repository name
}
PlatformInfo contains information about a Git hosting platform.
func DetectPlatform ¶
func DetectPlatform( remoteURL string, ) (PlatformInfo, error)
DetectPlatform parses a Git remote URL and returns platform information. Supports HTTPS, SSH, and git:// protocol URLs.
type WorktreeConfig ¶
type WorktreeConfig struct {
BranchName string // Branch name to create (e.g., "spectr/change-id")
BaseBranch string // Base branch to start from (e.g., "origin/main")
}
WorktreeConfig contains configuration for creating a git worktree.
type WorktreeInfo ¶
type WorktreeInfo struct {
Path string // Absolute path to worktree directory
BranchName string // The branch created
TempDir bool // Whether this is in temp directory
}
WorktreeInfo contains information about a created worktree.
func CreateWorktree ¶
func CreateWorktree( config WorktreeConfig, ) (*WorktreeInfo, error)
CreateWorktree creates a new git worktree in a temporary directory. It creates a new branch based on the specified base branch.