git

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package git provides git worktree operations for agent-deck

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BranchExists

func BranchExists(repoDir, branchName string) bool

BranchExists checks if a branch exists in the repository

func CreateWorktree

func CreateWorktree(repoDir, worktreePath, branchName string) error

CreateWorktree creates a new git worktree at worktreePath for the given branch If the branch doesn't exist, it will be created

func DeleteBranch added in v0.10.20

func DeleteBranch(repoDir, branchName string, force bool) error

DeleteBranch deletes a local branch. If force is true, uses -D (force delete).

func GeneratePathID added in v0.10.10

func GeneratePathID() string

GeneratePathID returns an 8-character random hex string for path uniqueness. Used to provide a unique identifier in worktree path templates via {session-id}.

func GenerateWorktreePath

func GenerateWorktreePath(repoDir, branchName, location string) string

GenerateWorktreePath generates a worktree directory path based on the repository directory, branch name, and location strategy. Location "subdirectory" places worktrees under <repo>/.worktrees/<branch>. Location "sibling" (or empty) places worktrees as <repo>-<branch> alongside the repo. A custom path (containing "/" or starting with "~") places worktrees at <path>/<repo_name>/<branch>.

func GetCurrentBranch

func GetCurrentBranch(dir string) (string, error)

GetCurrentBranch returns the current branch name for the repository at dir

func GetDefaultBranch added in v0.10.20

func GetDefaultBranch(repoDir string) (string, error)

GetDefaultBranch returns the default branch name (e.g. "main" or "master") for the repo

func GetMainWorktreePath

func GetMainWorktreePath(dir string) (string, error)

GetMainWorktreePath returns the path to the main worktree (original clone)

func GetRepoRoot

func GetRepoRoot(dir string) (string, error)

GetRepoRoot returns the root directory of the git repository containing dir

func GetWorktreeForBranch

func GetWorktreeForBranch(repoDir, branchName string) (string, error)

GetWorktreeForBranch returns the worktree path for a given branch, if any

func HasUncommittedChanges added in v0.10.20

func HasUncommittedChanges(dir string) (bool, error)

HasUncommittedChanges checks if the repository at dir has uncommitted changes

func IsGitRepo

func IsGitRepo(dir string) bool

IsGitRepo checks if the given directory is inside a git repository

func IsWorktree

func IsWorktree(dir string) bool

IsWorktree checks if the given directory is a git worktree (not the main repo)

func MergeBranch added in v0.10.20

func MergeBranch(repoDir, branchName string) error

MergeBranch merges the given branch into the current branch of the repository

func PruneWorktrees added in v0.10.20

func PruneWorktrees(repoDir string) error

PruneWorktrees removes stale worktree references

func RemoveWorktree

func RemoveWorktree(repoDir, worktreePath string, force bool) error

RemoveWorktree removes a worktree from the repository If force is true, it will remove even if there are uncommitted changes

func SanitizeBranchName

func SanitizeBranchName(name string) string

SanitizeBranchName converts a string to a valid branch name

func ValidateBranchName

func ValidateBranchName(name string) error

ValidateBranchName validates that a branch name follows git's naming rules

func WorktreePath added in v0.10.10

func WorktreePath(opts WorktreePathOptions) string

WorktreePath generates a worktree path. If opts.Template is set, it expands the template with variables {repo-name}, {repo-root}, {branch}, {session-id}. Unknown variables like {foo} are left as-is in the resolved path. Falls back to location-based strategy using opts.Location when template is empty or RepoDir is invalid.

Types

type Worktree

type Worktree struct {
	Path   string // Filesystem path to the worktree
	Branch string // Branch name checked out in this worktree
	Commit string // HEAD commit SHA
	Bare   bool   // Whether this is the bare repository
}

Worktree represents a git worktree

func ListWorktrees

func ListWorktrees(repoDir string) ([]Worktree, error)

ListWorktrees returns all worktrees for the repository at repoDir

type WorktreePathOptions added in v0.10.10

type WorktreePathOptions struct {
	Branch    string
	Location  string
	RepoDir   string
	SessionID string
	Template  string
}

WorktreePathOptions configures worktree path generation.

Jump to

Keyboard shortcuts

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