Documentation
¶
Index ¶
- func AddWorktree(repo Repo, newName, newPath, fromRef string) error
- func AddWorktreeFromRemote(repo Repo, worktreePath, branch, remoteBranch string) error
- func AmendHead(root string) (string, error)
- func ApplyPatchToIndex(worktreeRoot, patch string, reverse bool, unidiffZero bool) error
- func ApplyPatchToWorktree(worktreeRoot, patch string, reverse bool, unidiffZero bool) error
- func BinaryFileSizes(worktreeRoot string, file StageFileStatus) (prevSize, newSize int64, prevOK, newOK bool)
- func BranchRemote(repo Repo, branch string) string
- func CloneBare(repoURL, targetDir, cwd string) (string, error)
- func ColorizeDiff(worktreeRoot, path, rawDiff string, cached, sideBySide bool, ...) (string, error)
- func ColorizeUntrackedDiff(worktreeRoot, path, rawDiff string, sideBySide bool, ...) (string, error)
- func CommitFileDiffForRef(repoRoot, ref, path string) (string, error)
- func CommitFileDiffWithDeltaForRef(repoRoot, ref, path string, renderWidth int) (string, error)
- func CommitFixup(root, hash string) (string, error)
- func CreateAnnotatedTag(root, tag, message string) error
- func CreateBranch(repo Repo, name string) error
- func CurrentBranch(dir string) (string, error)
- func DefaultMainRemoteRef(repoRoot string) string
- func DeleteLocalBranch(repo Repo, name string, force bool) error
- func DeleteRemoteBranch(repo Repo, remoteName, branchName string) error
- func DeltaAvailable() bool
- func DiffPath(worktreeRoot, path string, cached bool, contextLines int) (string, error)
- func DiffPathWithDelta(worktreeRoot, path string, cached bool, sideBySide bool, renderWidth int, ...) (string, error)
- func DiffUntrackedPath(worktreeRoot, path string, color bool, sideBySide bool, renderWidth int, ...) (string, error)
- func DiscardUntrackedPath(worktreeRoot, relPath string) error
- func ExtractPRURL(output string) string
- func Fetch(repoRoot, remote string) error
- func FixFetchConfig(repoRoot string) error
- func HasUnstagedChanges(root string) (bool, error)
- func IsCommitPushed(root, hash string) (bool, error)
- func IsHEAD(root, hash string) (bool, error)
- func IsLocalBranch(repoRoot, ref string) bool
- func IsNonFastForwardPushError(err error) bool
- func IsRebasedOnMain(repo Repo, branch string) (bool, error)
- func LastTag(root string) string
- func ListRemotes(repo Repo) ([]string, error)
- func MoveWorktree(repo Repo, from, to string) error
- func NonInteractiveEnv() []string
- func ParseVersion(tag string) (major, minor, patch int, err error)
- func PruneAllRemotes(repo Repo) error
- func PruneRemote(repo Repo, remote string) error
- func Pull(worktreePath string) (string, error)
- func Push(worktreePath, remote, branch string) error
- func PushBranch(worktreePath, remote, branch string) (prURL, output string, err error)
- func PushBranchForce(worktreePath, remote, branch string) (string, error)
- func PushBranchForceWithLease(worktreePath, remote, branch string) error
- func PushOrigin(root string) error
- func PushTag(root, tag string) error
- func Rebase(dir string, onto string) (string, error)
- func RebaseAutosquash(root, hash string) (string, error)
- func RemoteDefaultBranch(repoRoot string) string
- func RemoveWorktree(repo Repo, name string, force bool) error
- func RenameBranch(repo Repo, oldName, newName string) error
- func ResolveCommitish(repoRoot, ref string) (string, error)
- func RestorePaths(worktreeRoot string, paths []string) error
- func RewordCommit(root, hash, message string) (string, error)
- func RewordHead(root, message string) (string, error)
- func StageIntentPath(worktreeRoot, path string) error
- func StagePath(worktreeRoot, path string) error
- func StagedFiles(root string) ([]string, error)
- func Stash(dir string) (string, error)
- func StashPop(dir string) (string, error)
- func StashPushAuto(root string) (string, error)
- func TrackRemote(repoRoot, remote, branch string) error
- func UnstagePath(worktreeRoot, path string) error
- func UpdateRemotes(repo Repo) (string, error)
- func UpstreamBranch(repoRoot, branch string) string
- func WorktreeRoot(dir string) (string, error)
- type Branch
- type BranchHistoryClass
- type BranchHistoryCommit
- type Change
- type ChangeKind
- type Commit
- type CommitDetails
- type CommitFile
- type CommitInfo
- type DirInfo
- type FetchConfigProblem
- type Issue
- type LogEntry
- type LogFilter
- type PushDivergence
- type RefDecoration
- type RefDecorationKind
- type Repo
- type RunError
- type StageFileStatus
- type SyncStatus
- type SyncStatusName
- type Worktree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddWorktree ¶
AddWorktree creates a new linked worktree at newPath with a new branch newName, starting at fromRef (branch name, tag, or commit hash). fromRef may be empty, in which case git uses the current HEAD of the repo.
func AddWorktreeFromRemote ¶
AddWorktreeFromRemote adds a worktree for branch. It first tries to check out an existing local branch, then falls back to creating a tracking branch from remoteBranch (for freshly cloned bare repositories).
func AmendHead ¶ added in v0.14.5
AmendHead amends the HEAD commit with the currently staged changes.
func ApplyPatchToIndex ¶
ApplyPatchToIndex applies patch to the index in worktreeRoot.
func ApplyPatchToWorktree ¶
ApplyPatchToWorktree applies patch to the worktree in worktreeRoot.
func BinaryFileSizes ¶
func BinaryFileSizes(worktreeRoot string, file StageFileStatus) (prevSize, newSize int64, prevOK, newOK bool)
BinaryFileSizes returns previous and new file sizes for binary diff summaries. prevSize is read from HEAD (or rename source when available). newSize is read from the worktree path, falling back to the index blob.
func BranchRemote ¶
BranchRemote returns the remote configured for branch (e.g. "origin"), falling back to "origin" if none is set.
func CloneBare ¶
CloneBare clones repoURL using the .bare trick:
my-repo/ .bare/ ← actual bare git repo .git ← text file: "gitdir: ./.bare" main/ ← linked worktrees live here
targetDir, if non-empty, sets the outer directory name. Otherwise the name is inferred from the URL (with any ".git" suffix stripped). Returns the path to the outer directory (e.g. my-repo/).
func ColorizeDiff ¶ added in v0.13.0
func ColorizeDiff(worktreeRoot, path, rawDiff string, cached, sideBySide bool, renderWidth, contextLines int) (string, error)
ColorizeDiff colorizes a raw unified diff using delta if available, falling back to git diff --color=always.
func ColorizeUntrackedDiff ¶ added in v0.13.0
func ColorizeUntrackedDiff(worktreeRoot, path, rawDiff string, sideBySide bool, renderWidth, contextLines int) (string, error)
ColorizeUntrackedDiff colorizes a raw untracked diff using delta if available, falling back to git diff --no-index --color=always.
func CommitFileDiffForRef ¶ added in v0.13.0
func CommitFileDiffWithDeltaForRef ¶ added in v0.13.0
func CommitFixup ¶ added in v0.14.5
CommitFixup creates a fixup commit targeting the given hash.
func CreateAnnotatedTag ¶ added in v0.15.1
CreateAnnotatedTag creates an annotated tag at HEAD.
func CreateBranch ¶
CreateBranch creates and checks out a new branch.
func CurrentBranch ¶
CurrentBranch returns the short name of the current branch in dir.
func DefaultMainRemoteRef ¶
DefaultMainRemoteRef returns the best remote mainline ref for repoRoot. It prefers origin/<default-branch>, then falls back to origin/main/master if present.
func DeleteLocalBranch ¶
DeleteLocalBranch deletes a local branch. Use force=true to delete unmerged branches.
func DeleteRemoteBranch ¶
DeleteRemoteBranch deletes a branch on the remote.
func DeltaAvailable ¶
func DeltaAvailable() bool
func DiffPath ¶
DiffPath returns a unified diff for path. When cached is true, it reads index vs HEAD. Output is plain (no ANSI colors).
func DiffPathWithDelta ¶
func DiffPathWithDelta(worktreeRoot, path string, cached bool, sideBySide bool, renderWidth int, contextLines int) (string, error)
DiffPathWithDelta returns a unified diff rendered by git diff with delta as pager. If delta is unavailable, it falls back to git's own color output.
func DiffUntrackedPath ¶
func DiffUntrackedPath(worktreeRoot, path string, color bool, sideBySide bool, renderWidth int, contextLines int) (string, error)
DiffUntrackedPath returns a /dev/null -> file patch for an untracked path. Plain output is returned when color is false; otherwise output is rendered by git diff with delta as pager where possible.
func DiscardUntrackedPath ¶
DiscardUntrackedPath removes an untracked path from the working tree.
func ExtractPRURL ¶
ExtractPRURL scans git push output for a GitHub PR creation URL. Git prefixes remote messages with "remote: ", so we strip that first.
func FixFetchConfig ¶
FixFetchConfig corrects the origin fetch refspec and runs git fetch.
func HasUnstagedChanges ¶ added in v0.14.5
HasUnstagedChanges reports whether there are tracked working-tree changes not yet in the index.
func IsCommitPushed ¶ added in v0.14.5
IsCommitPushed reports whether hash appears in any remote tracking branch.
func IsLocalBranch ¶ added in v0.15.4
func IsNonFastForwardPushError ¶
IsNonFastForwardPushError returns true when err matches a rejected push that can be resolved with a force push.
func IsRebasedOnMain ¶
IsRebasedOnMain reports whether branch is rebased on top of repo.MainBranch, i.e. whether the main branch tip is an ancestor of branch. Returns true when branch IS main (nothing to rebase) or when no main branch is detected.
func LastTag ¶ added in v0.15.1
LastTag returns the most recent tag reachable from HEAD, or "v0.0.0" if none.
func ListRemotes ¶
ListRemotes returns the names of all configured remotes.
func MoveWorktree ¶
MoveWorktree moves a worktree from one path to another.
func NonInteractiveEnv ¶
func NonInteractiveEnv() []string
func ParseVersion ¶ added in v0.15.1
ParseVersion parses "vMAJOR.MINOR.PATCH" into its integer components.
func PruneAllRemotes ¶
PruneAllRemotes prunes all configured remotes.
func PruneRemote ¶
PruneRemote removes remote-tracking references for deleted remote branches.
func Pull ¶
Pull fetches and integrates changes from the remote into the worktree and returns the combined output.
func Push ¶
Push uploads local branch commits to the remote using an explicit "git push <remote> <branch>" invocation.
func PushBranch ¶
PushBranch pushes branch to remote and returns any PR creation URL found in the git output (e.g. the GitHub "Create a pull request" link), or "" if none. It also returns the combined output for display.
func PushBranchForce ¶
PushBranchForce force-pushes branch using --force and returns the combined output.
func PushBranchForceWithLease ¶
PushBranchForceWithLease force-pushes branch using --force-with-lease.
func PushOrigin ¶ added in v0.15.1
PushOrigin pushes the current branch to origin.
func RebaseAutosquash ¶ added in v0.14.5
RebaseAutosquash performs a non-interactive autosquash rebase from hash^ onward.
func RemoteDefaultBranch ¶
RemoteDefaultBranch returns the repository's default branch using origin/HEAD when available, then falls back to local branch checks.
func RemoveWorktree ¶
RemoveWorktree removes a worktree by name or path.
func RenameBranch ¶
RenameBranch renames a local branch from oldName to newName.
func ResolveCommitish ¶ added in v0.12.10
func RestorePaths ¶
RestorePaths restores the given paths in both index and worktree from HEAD.
func RewordCommit ¶ added in v0.14.6
RewordCommit rewrites the message of an arbitrary non-HEAD commit via interactive rebase. --autostash handles both staged and unstaged working-tree changes automatically.
func RewordHead ¶ added in v0.14.6
RewordHead amends the HEAD commit message only, leaving any staged content untouched.
func StageIntentPath ¶
StageIntentPath records an intent-to-add entry without adding content.
func StagedFiles ¶ added in v0.14.5
StagedFiles returns the paths of files with staged index changes.
func StashPushAuto ¶ added in v0.14.5
StashPushAuto stashes all tracked working-tree changes plus untracked files.
func TrackRemote ¶
TrackRemote configures an existing branch to track <remote>/<branch>.
func UnstagePath ¶
UnstagePath removes path changes from the index while preserving worktree edits.
func UpdateRemotes ¶
UpdateRemotes fetches updates from all remotes and returns their combined output.
func UpstreamBranch ¶
UpstreamBranch returns the upstream tracking ref (e.g. "origin/feature") for a local branch. It first checks the configured tracking branch, then falls back to "origin/<branch>" if that ref exists. Returns "" if neither applies.
func WorktreeRoot ¶
WorktreeRoot resolves dir to the root of the current non-bare worktree.
Types ¶
type Branch ¶
type Branch struct {
Name string
GitName string // as passed to git commands (e.g. "origin/main" for remote)
RemoteName string // non-empty for remote branches
IsRemote bool
}
Branch represents a local or remote git branch.
func ListBranches ¶
ListBranches returns all local and remote branches, excluding HEAD pointers.
type BranchHistoryClass ¶ added in v0.12.5
type BranchHistoryClass string
const ( BranchHistoryLocalOnly BranchHistoryClass = "local_only" BranchHistoryRemoteOnly BranchHistoryClass = "remote_only" )
type BranchHistoryCommit ¶ added in v0.12.5
type BranchHistoryCommit struct {
Commit
Class BranchHistoryClass
}
func BranchHistorySinceMain ¶ added in v0.12.5
func BranchHistorySinceMain(repo Repo, branch, upstreamRef string) ([]BranchHistoryCommit, error)
BranchHistorySinceMain returns branch history since the repo's remote mainline ref (for example origin/main or origin/master) when available.
type Change ¶
type Change struct {
Kind ChangeKind
Path string
}
Change represents a single file change reported by git status.
func UncommittedChanges ¶
UncommittedChanges returns modified, added, deleted, and untracked files in the worktree at the given path.
type ChangeKind ¶
type ChangeKind string
ChangeKind classifies a file change in the working tree.
const ( ChangeModified ChangeKind = "M" ChangeAdded ChangeKind = "A" ChangeDeleted ChangeKind = "D" ChangeRenamed ChangeKind = "R" ChangeUntracked ChangeKind = "?" )
type Commit ¶
Commit is a single git commit with abbreviated hash and subject line.
func CommitsBehindMain ¶
CommitsBehindMain returns commits on main that are not reachable from branch, ordered newest first.
func CommitsBetween ¶
CommitsBetween returns commits reachable from toRef but not fromRef, ordered newest first.
func CommitsSinceMain ¶
CommitsSinceMain returns commits on branch that are not reachable from the repo's local main branch, ordered newest first.
func HeadCommit ¶
HeadCommit returns the latest commit on the given branch.
type CommitDetails ¶ added in v0.12.11
type CommitDetails struct {
FullHash string
Hash string
AuthorName string
AuthorShort string
Subject string
Body string
Date time.Time
Decorations []RefDecoration
}
func CommitDetailsForRef ¶ added in v0.12.11
func CommitDetailsForRef(repoRoot, ref string) (CommitDetails, error)
type CommitFile ¶ added in v0.13.0
func CommitFilesForRef ¶ added in v0.13.0
func CommitFilesForRef(repoRoot, ref string) ([]CommitFile, error)
type DirInfo ¶
type DirInfo struct {
Repo Repo
WorktreeRoot string // non-empty when inside a linked worktree
IsRepoRoot bool
IsWorktreeRoot bool
}
DirInfo describes what kind of git context a directory is in.
func IdentifyDir ¶
IdentifyDir returns context about the directory: which repo it belongs to, whether it's a worktree root, etc.
type FetchConfigProblem ¶
FetchConfigProblem describes a misconfigured origin fetch setup and the commands needed to fix it.
func CheckFetchConfig ¶
func CheckFetchConfig(repoRoot string) *FetchConfigProblem
CheckFetchConfig checks whether origin is configured to populate refs/remotes/origin/* and that those refs exist. Returns nil if everything looks fine, or a FetchConfigProblem describing what to fix.
type Issue ¶
type Issue struct {
Description string
FixDescription string
// contains filtered or unexported fields
}
Issue represents a problem found by the doctor check.
type LogEntry ¶ added in v0.12.10
type LogEntry struct {
FullHash string
Hash string
AuthorName string
AuthorShort string
Subject string
Date time.Time
Graph string
Decorations []RefDecoration
}
func LogEntries ¶ added in v0.12.10
type LogFilter ¶ added in v0.15.4
LogFilter restricts a log query to a file path or a line range within a file.
type PushDivergence ¶
type PushDivergence struct {
Branch string
Remote string
Upstream string
Local CommitInfo
RemoteHead CommitInfo
}
func DetectPushDivergence ¶
func DetectPushDivergence(worktreePath, branch string) (*PushDivergence, error)
DetectPushDivergence fetches origin when an upstream branch exists and reports divergence between local branch and its upstream.
func DetectPushDivergenceAfterFetch ¶
func DetectPushDivergenceAfterFetch(worktreePath, branch string) (*PushDivergence, error)
type RefDecoration ¶ added in v0.12.10
type RefDecoration struct {
Name string
Kind RefDecorationKind
}
type RefDecorationKind ¶ added in v0.12.10
type RefDecorationKind string
const ( RefDecorationLocalBranch RefDecorationKind = "local_branch" RefDecorationRemoteBranch RefDecorationKind = "remote_branch" RefDecorationTag RefDecorationKind = "tag" )
type Repo ¶
type Repo struct {
Root string
WorktreeDir string // directory where linked worktrees live; if empty, defaults to Root
IsBare bool
MainBranch string // "main" or "master"
}
Repo represents a git repository.
func (Repo) LinkedWorktreeDir ¶
LinkedWorktreeDir returns the directory where linked worktrees are created. For normal bare repos this is the same as Root; for .bare repos it is the parent directory that contains both .bare/ and the worktrees.
type StageFileStatus ¶
StageFileStatus represents one file entry from git status porcelain output.
func ListStageFiles ¶
func ListStageFiles(worktreeRoot string) ([]StageFileStatus, error)
ListStageFiles returns status entries suitable for an interactive staging UI.
func (StageFileStatus) HasStagedChanges ¶
func (s StageFileStatus) HasStagedChanges() bool
func (StageFileStatus) HasUnstagedChanges ¶
func (s StageFileStatus) HasUnstagedChanges() bool
func (StageFileStatus) IsRenamed ¶
func (s StageFileStatus) IsRenamed() bool
func (StageFileStatus) IsUntracked ¶
func (s StageFileStatus) IsUntracked() bool
func (StageFileStatus) XY ¶
func (s StageFileStatus) XY() string
XY returns the two-character porcelain status code.
type SyncStatus ¶
type SyncStatus struct {
Name SyncStatusName
Ahead int // commits the local branch has that upstream doesn't
Behind int // commits upstream has that the local branch doesn't
}
SyncStatus holds the sync relationship between a local branch and a reference.
func BranchSyncStatusAgainstRef ¶
func BranchSyncStatusAgainstRef(repoRoot, localRef, remoteRef string) (SyncStatus, error)
BranchSyncStatusAgainstRef compares a local branch/ref against an explicit remote reference (for example: branch vs origin/main).
func WorktreeSyncStatus ¶
func WorktreeSyncStatus(repo Repo, branch string) (SyncStatus, error)
WorktreeSyncStatus returns the sync status of a worktree branch compared to its upstream remote tracking branch. Returns StatusUnknown if no upstream is configured.
func (SyncStatus) Pretty ¶
func (s SyncStatus) Pretty() string
Pretty returns a human-readable summary of the sync status.
type SyncStatusName ¶
type SyncStatusName string
SyncStatusName describes the relationship between a branch and its upstream.
const ( StatusSame SyncStatusName = "same" StatusAhead SyncStatusName = "ahead" StatusBehind SyncStatusName = "behind" StatusDiverged SyncStatusName = "diverged" StatusUnknown SyncStatusName = "unknown" )
type Worktree ¶
type Worktree struct {
Path string
Name string // path relative to the repo root
Branch string // short branch name, empty if detached
Head string // commit hash
IsDetached bool
IsBare bool
}
Worktree represents a git worktree.
func ListWorktrees ¶
ListWorktrees returns all linked worktrees for the repo (excludes the bare root).