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 ¶
- func AddFiles(repoPath string, paths []string) error
- func BranchExists(repoPath, name string) (bool, error)
- func CheckoutBranch(repoPath, name string) error
- func CheckoutRemoteTracking(repoPath, name string) error
- func CommitChanges(repoPath, message string) (string, error)
- func GetChangedFiles(repoPath string) ([]string, error)
- func GetCurrentBranch(repoPath string) (string, error)
- func GetRepoOwnerName(repoPath string) (owner, name string, err error)
- func HasUncommittedChanges(repoPath string) (bool, error)
- func IsFeatureBranch(name string) bool
- func ParseRepoFlag(flag string) (owner, name string, err error)
- func ParseRepoURL(rawURL string) (owner, name string, err error)
- func PushToRemote(repoPath string) error
- func StashChanges(repoPath string) error
- func StashPop(repoPath string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BranchExists ¶
BranchExists reports whether a local branch with the given name exists.
func CheckoutBranch ¶
CheckoutBranch checks out a local branch by name using go-git. Use CheckoutRemoteTracking for branches that only exist on the remote.
func CheckoutRemoteTracking ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
HasUncommittedChanges returns true if the working tree has uncommitted modifications.
func IsFeatureBranch ¶
IsFeatureBranch reports whether name looks like a feature branch (e.g., "136-revise-comments").
func ParseRepoFlag ¶ added in v1.1.0
ParseRepoFlag parses a --repo flag value in "owner/repo" format.
func ParseRepoURL ¶ added in v1.1.0
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 ¶
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 ¶
StashChanges stashes all uncommitted changes. Uses exec because go-git does not implement stash (see go-git issue #606).
Types ¶
This section is empty.