{"modulePath":"github.com/boneskull/gh-stack","version":"v1.3.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package git\n\ninternal/git/git.go\n\n## Variables\n\n```go\nvar ErrDirtyWorkTree = errors.New(\"working tree has uncommitted changes\")\n```\nErrDirtyWorkTree is returned when the working tree has uncommitted changes.\n\n## Functions\n\n```go\nfunc AbbrevSHA(sha string) string\n```\nAbbrevSHA safely abbreviates a SHA to 7 characters. Returns the full string if it's shorter than 7 characters.\n\n## Types\n\n```go\ntype Commit struct {\n\tSubject string // First line of the commit message\n\tBody    string // Everything after the first line (may be empty)\n}\n```\nCommit represents a git commit with its subject and body.\n\n```go\ntype Git struct {\n\t// contains filtered or unexported fields\n}\n```\nGit provides git operations for a repository.\n\n```go\nfunc New(repoPath string) *Git\n```\nNew creates a Git instance for the repository at the given path.\n\n```go\nfunc (g *Git) BranchExists(branch string) bool\n```\nBranchExists checks if a branch exists.\n\n```go\nfunc (g *Git) Checkout(branch string) error\n```\nCheckout switches to the specified branch.\n\n```go\nfunc (g *Git) Commit(message string) error\n```\nCommit creates a commit with the given message.\n\n```go\nfunc (g *Git) CommitExists(sha string) bool\n```\nCommitExists checks if a commit SHA exists in the repository.\n\n```go\nfunc (g *Git) CreateAndCheckout(name string) error\n```\nCreateAndCheckout creates a new branch and switches to it.\n\n```go\nfunc (g *Git) CreateBranch(name string) error\n```\nCreateBranch creates a new branch at the current HEAD.\n\n```go\nfunc (g *Git) CreateBranchAt(name, sha string) error\n```\nCreateBranchAt creates a new branch at a specific SHA. This is equivalent to \\`git branch \\\u003cname\u003e \\\u003csha\u003e\\`.\n\n```go\nfunc (g *Git) CurrentBranch() (string, error)\n```\nCurrentBranch returns the name of the current branch.\n\n```go\nfunc (g *Git) DeleteBranch(branch string) error\n```\nDeleteBranch deletes a local branch.\n\n```go\nfunc (g *Git) FastForward(branch string) error\n```\nFastForward fast-forwards a branch to its remote tracking branch.\n\n```go\nfunc (g *Git) Fetch() error\n```\nFetch fetches from origin.\n\n```go\nfunc (g *Git) GetCommits(base, head string) ([]Commit, error)\n```\nGetCommits returns the commits from base..head (commits in head not in base). Returns commits in reverse chronological order (newest first).\n\n```go\nfunc (g *Git) GetGitDir() string\n```\nGetGitDir returns the .git directory path.\n\n```go\nfunc (g *Git) GetMergeBase(a, b string) (string, error)\n```\nGetMergeBase returns the merge base of two branches.\n\n```go\nfunc (g *Git) GetResolvedGitDir() (string, error)\n```\nGetResolvedGitDir returns the actual git directory for this repository. In a main worktree this is typically \\\u003crepo\u003e/.git. In a linked worktree this resolves to the per-worktree dir (e.g. \\\u003cmain-repo\u003e/.git/worktrees/\\\u003cname\u003e), which is where rebase state lives.\n\n```go\nfunc (g *Git) GetTip(branch string) (string, error)\n```\nGetTip returns the commit SHA at the tip of a branch.\n\n```go\nfunc (g *Git) HasStagedChanges() (bool, error)\n```\nHasStagedChanges returns true if there are staged changes.\n\n```go\nfunc (g *Git) HasUnmergedCommits(branch, upstream string) (bool, error)\n```\nHasUnmergedCommits returns true if the branch has commits not yet in upstream. Uses git cherry to detect by diff content, which works for cherry-picks where the commit SHAs differ but the content is the same. Note: This does NOT detect squash merges where multiple commits are combined. Use IsContentMerged for squash merge detection.\n\n```go\nfunc (g *Git) IsAncestor(ancestor, descendant string) bool\n```\nIsAncestor returns true if ancestor is a git ancestor of descendant. Uses \\`git merge-base --is-ancestor\\` which returns exit code 0 when true.\n\n```go\nfunc (g *Git) IsContentMerged(branch, upstream string) (bool, error)\n```\nIsContentMerged returns true if the branch has no content differences from upstream. This detects squash merges where the tree content is identical even though the commit history differs. Returns true if \\`git diff upstream branch\\` is empty.\n\n```go\nfunc (g *Git) IsDirty() (bool, error)\n```\nIsDirty returns true if there are uncommitted changes (staged or unstaged).\n\n```go\nfunc (g *Git) IsRebaseInProgress() bool\n```\nIsRebaseInProgress checks if a rebase is in progress. Uses GetResolvedGitDir so it works in linked worktrees where .git is a file, not a directory.\n\n```go\nfunc (g *Git) ListRemoteBranches() (map[string]bool, error)\n```\nListRemoteBranches returns the set of branch names that exist on origin, based on locally-cached remote-tracking refs (no network call). This is accurate as long as a fetch or push has been done recently.\n\n```go\nfunc (g *Git) ListWorktrees() (map[string]string, error)\n```\nListWorktrees parses \\`git worktree list --porcelain\\` and returns a map of branch name to worktree path for all linked worktrees (the main worktree is excluded).\n\n```go\nfunc (g *Git) NeedsRebase(branch, parent string) (bool, error)\n```\nNeedsRebase returns true if branch needs to be rebased onto parent.\n\n```go\nfunc (g *Git) Push(branch string, force bool) error\n```\nPush pushes a branch to origin. When force is true, --force-with-lease is used; when false, the push is a normal fast-forward push (and will fail if the remote has diverged).\n\n```go\nfunc (g *Git) PushMany(branches []string, force bool) error\n```\nPushMany pushes multiple branches to origin in a single invocation. When force is true, --force-with-lease and --atomic are added so that the push is all-or-nothing: if any ref is rejected (e.g. lease conflict), none of the refs are updated on the remote. Returns nil immediately when branches is empty.\n\nAll flags are placed before a \\`--\\` end-of-options marker so refspecs that happen to start with \\`-\\` are never misinterpreted as git options.\n\n```go\nfunc (g *Git) Rebase(onto string, updateRefs bool) error\n```\nRebase rebases the current branch onto target. updateRefs controls whether --update-refs is passed to git rebase. When true, git moves any branch refs that point to commits inside the rebased range. When false, --no-update-refs is passed explicitly to override any ambient rebase.updateRefs git config. Both flags require Git 2.38+; an error is returned if the requirement is not met.\n\n```go\nfunc (g *Git) RebaseAbort() error\n```\nRebaseAbort aborts an in-progress rebase.\n\n```go\nfunc (g *Git) RebaseContinue() error\n```\nRebaseContinue continues an in-progress rebase.\n\n```go\nfunc (g *Git) RebaseHere(onto string, updateRefs bool) error\n```\nRebaseHere rebases the already-checked-out HEAD onto the given branch. This is semantically identical to Rebase but named explicitly to clarify that no checkout is needed -- the caller is operating inside a worktree that already has the target branch checked out. updateRefs controls whether --update-refs is passed; see Rebase for details. Requires Git 2.38+; an error is returned if the requirement is not met.\n\n```go\nfunc (g *Git) RebaseOnto(newBase, oldBase, branch string, updateRefs bool) error\n```\nRebaseOnto rebases a branch onto a new base, replaying only commits after oldBase. Checks out the branch first, then runs: git rebase --onto \\\u003cnewBase\u003e \\\u003coldBase\u003e Useful when a parent branch was squash-merged and we need to replay only the commits unique to the child branch. updateRefs controls whether --update-refs is passed; see Rebase for details. Requires Git 2.38+; an error is returned if the requirement is not met.\n\n```go\nfunc (g *Git) RebaseOntoHere(newBase, oldBase string, updateRefs bool) error\n```\nRebaseOntoHere runs \\`git rebase --onto \\\u003cnewBase\u003e \\\u003coldBase\u003e\\` on the already-checked-out HEAD. Needed for fork-point rebases in worktrees where we cannot (and don't need to) checkout first. updateRefs controls whether --update-refs is passed; see Rebase for details. Requires Git 2.38+; an error is returned if the requirement is not met.\n\n```go\nfunc (g *Git) RemoteBranchExists(branch string) bool\n```\nRemoteBranchExists checks if a branch exists on the remote (origin).\n\n```go\nfunc (g *Git) SetBranchRef(branch, sha string) error\n```\nSetBranchRef sets a branch ref to point to a specific SHA. This is equivalent to \\`git branch -f \\\u003cbranch\u003e \\\u003csha\u003e\\`.\n\n```go\nfunc (g *Git) Stash(message string) (string, error)\n```\nStash creates a stash with the given message and returns the stash commit hash. Returns an empty string if there was nothing to stash. Includes untracked files (-u) to capture all working tree changes. The returned hash is stable and can be used to restore this specific stash even if other stashes are created later.\n\n```go\nfunc (g *Git) StashList() (bool, error)\n```\nStashList returns true if there are any stash entries.\n\n```go\nfunc (g *Git) StashPop(ref string) error\n```\nStashPop restores a specific stash entry when a reference is provided. If ref is empty, it pops the most recent stash entry (matching \\`git stash pop\\`). When a commit hash is provided (from Stash()), uses apply+drop since pop only accepts stash refs. Returns an error if there are conflicts or no matching stash entry.\n\n","path":"github.com/boneskull/gh-stack/internal/git","name":"git","synopsis":"internal/git/git.go","isRedistributable":true}
