git

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package git provides Git helper functions for working with the user's local repository.

This package is intentionally separate from pkg/deps (which manages external dependency repos — clone, fetch, checkout remote specs) because it operates on a fundamentally different concern: the user's own working repository. Functions here cover day-to-day CLI operations such as branch detection, status inspection, stash, commit, and push — all on the repo the user has open in their shell.

Any CLI command that needs to interact with the user's local repo (sl revise, sl session, etc.) should import from this package rather than duplicating logic or adding working-repo helpers to pkg/deps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFiles

func AddFiles(repoPath string, paths []string) error

AddFiles stages the specified file paths in the repository.

func BranchExists

func BranchExists(repoPath, name string) (bool, error)

BranchExists reports whether a local branch with the given name exists.

func CheckoutBranch

func CheckoutBranch(repoPath, name string) error

CheckoutBranch checks out a local branch by name using go-git. Use CheckoutRemoteTracking for branches that only exist on the remote.

func CheckoutRemoteTracking

func CheckoutRemoteTracking(repoPath, name string) error

CheckoutRemoteTracking checks out a remote-tracking branch, creating a local tracking branch. Uses exec because go-git requires a 4-step manual process for remote tracking checkout.

func CommitChanges

func CommitChanges(repoPath, message string) (string, error)

CommitChanges creates a commit with the staged changes and returns the short (8-char) commit hash. Author info is read from the repository's global git config, with fallbacks to "SpecLedger".

func GetChangedFiles

func GetChangedFiles(repoPath string) ([]string, error)

GetChangedFiles returns the relative paths of all files with uncommitted changes (modified, added, deleted, or untracked) in the working tree or staging area.

func GetCurrentBranch

func GetCurrentBranch(repoPath string) (string, error)

GetCurrentBranch returns the short name of the current branch (e.g., "136-revise-comments"). Returns an 8-character commit hash prefix when HEAD is detached.

func GetRepoOwnerName

func GetRepoOwnerName(repoPath string) (owner, name string, err error)

GetRepoOwnerName parses the origin remote URL to extract the GitHub owner and repo name. Supports both HTTPS and SSH URLs with any hostname, including custom SSH config aliases.

func HasUncommittedChanges

func HasUncommittedChanges(repoPath string) (bool, error)

HasUncommittedChanges returns true if the working tree has uncommitted modifications.

func IsFeatureBranch

func IsFeatureBranch(name string) bool

IsFeatureBranch reports whether name looks like a feature branch (e.g., "136-revise-comments").

func ParseRepoFlag added in v1.1.0

func ParseRepoFlag(flag string) (owner, name string, err error)

ParseRepoFlag parses a --repo flag value in "owner/repo" format.

func ParseRepoURL added in v1.1.0

func ParseRepoURL(rawURL string) (owner, name string, err error)

ParseRepoURL extracts owner and repo name from a git remote URL. Supports SSH (git@host:owner/repo.git), ssh:// protocol (ssh://git@host/owner/repo.git), and HTTPS (https://host/owner/repo.git) with any hostname, including custom SSH config aliases. Repo names may contain dots (e.g., "my.repo").

func PushToRemote

func PushToRemote(repoPath string) error

PushToRemote pushes the current branch to the origin remote. Uses exec for reliable credential helper and SSH agent support (go-git push does not work reliably with macOS Keychain and HTTPS credential helpers).

func StashChanges

func StashChanges(repoPath string) error

StashChanges stashes all uncommitted changes. Uses exec because go-git does not implement stash (see go-git issue #606).

func StashPop

func StashPop(repoPath string) error

StashPop re-applies the most recent stash. Uses exec because go-git does not implement stash (see go-git issue #606).

Types

This section is empty.

Jump to

Keyboard shortcuts

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