git

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package git provides Git operations for PR workflows including platform detection and worktree management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BranchExists

func BranchExists(branchName string) (bool, error)

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

func DeleteRemoteBranch(branchName string) error

DeleteRemoteBranch deletes a branch from the origin remote.

func FetchOrigin

func FetchOrigin() error

FetchOrigin fetches the latest refs from the origin remote.

func GetBaseBranch

func GetBaseBranch(preferredBase string) (string, error)

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

func GetOriginURL() (string, error)

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

func GetRepoRoot() (string, error)

GetRepoRoot returns the absolute path to the root of the git repository. Returns an error if not in a git repository.

func PathExistsOnRef

func PathExistsOnRef(ref, path string) (bool, error)

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.

Jump to

Keyboard shortcuts

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