Documentation
¶
Index ¶
- type Git
- func (g *Git) BranchExists(branch string) (bool, error)
- func (g *Git) BranchExistsIn(dir, branch string) (bool, error)
- func (g *Git) CheckHookCompatibility(repoRoot string) []string
- func (g *Git) Clone(url, dstPath string) error
- func (g *Git) CreateWorktree(path, branch string) error
- func (g *Git) CreateWorktreeIn(repoDir, path, branch string) error
- func (g *Git) CurrentBranch() (string, error)
- func (g *Git) CurrentBranchIn(dir string) (string, error)
- func (g *Git) DeepClean(url, dstPath string) error
- func (g *Git) DefaultBranch() string
- func (g *Git) DefaultBranchIn(dir string) string
- func (g *Git) DeleteBranch(branch string, isForced bool) error
- func (g *Git) ExecuteCommand(args ...string) error
- func (g *Git) ExecuteCommandAt(dir string, args ...string) error
- func (g *Git) FetchOrigin() error
- func (g *Git) FetchOriginTimeout(timeout time.Duration) error
- func (g *Git) ForceConfigure() error
- func (g *Git) ForceInstall() error
- func (g *Git) GetMainWorktree(fromPath string) (string, error)
- func (g *Git) GetRepoRoot() (string, error)
- func (g *Git) GetRepoRootIn(dir string) (string, error)
- func (g *Git) Install() error
- func (g *Git) IsWorktreeDirty(path string) (bool, error)
- func (g *Git) Kind() apps.AppKind
- func (g *Git) ListBranches() ([]string, error)
- func (g *Git) ListWorktrees() ([]WorktreeInfo, error)
- func (g *Git) ListWorktreesAt(dir string) ([]WorktreeInfo, error)
- func (g *Git) Name() string
- func (g *Git) Pop(branch string) error
- func (g *Git) PruneWorktrees() error
- func (g *Git) PruneWorktreesAt(dir string) error
- func (g *Git) Pull(branch string) error
- func (g *Git) RemoteBranchExists(branch string) (bool, error)
- func (g *Git) RemoteBranchExistsIn(dir, branch string) (bool, error)
- func (g *Git) RemoveWorktree(path string, deleteBranch bool, branchName string) error
- func (g *Git) Restore(branch, files string) error
- func (g *Git) RunCapture(args ...string) (string, error)
- func (g *Git) ShortHead() (string, error)
- func (g *Git) SoftConfigure() error
- func (g *Git) SoftInstall() error
- func (g *Git) SwitchBranch(branch string) error
- func (g *Git) Uninstall() error
- func (g *Git) Update() error
- type WorktreeInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Git ¶
type Git struct {
Cmd cmd.Command
Base cmd.BaseCommandExecutor
// Stream, when true, tees git command output (clone/pull/fetch/merge/…) to
// the terminal in real time. Used by `dg task` utilities so humans and
// agents see progress as it happens. Commands whose output is parsed
// (e.g. ListBranches) intentionally stay non-streaming.
Stream bool
}
func (*Git) BranchExists ¶
BranchExists checks if a branch exists in the repository
func (*Git) BranchExistsIn ¶
BranchExistsIn is BranchExists evaluated against the repository at dir ("" = current directory).
func (*Git) CheckHookCompatibility ¶
CheckHookCompatibility scans the repo's effective hooks directory for scripts that use `[ -d .git ]` or `test -d .git`. In a git worktree the .git entry is a FILE, not a directory, so those checks always fail and block git commit.
Also detects Affiance hooks which have a known bug where the .git file regex fails to match due to trailing newlines, causing "no .git directory found". See: https://github.com/mariusbutuc/affiance/issues/XXX
Returns one warning string per offending hook file, or nil if all clear.
func (*Git) CreateWorktree ¶
CreateWorktree creates a new worktree with a branch Handles three cases: 1. Local branch exists: checkout that branch 2. Remote branch exists: create tracking branch (after fetch) 3. Neither exists: create new branch from the freshly-fetched default branch
func (*Git) CreateWorktreeIn ¶
CreateWorktreeIn is CreateWorktree evaluated against the repository at repoDir ("" = current directory), so worktrees can be created for a repo the caller is not inside.
func (*Git) CurrentBranch ¶
CurrentBranch returns the checked-out branch name, or "" when HEAD is detached (mirrors `git branch --show-current`).
func (*Git) CurrentBranchIn ¶
CurrentBranchIn is CurrentBranch evaluated against the repository at dir ("" = current directory).
func (*Git) DefaultBranch ¶
DefaultBranch returns the repository's default branch name (e.g. "main"). It resolves origin/HEAD when available; when unset it probes origin/main, origin/master, origin/develop in order via RemoteBranchExists and returns the first that exists, falling back to "main" as a last resort so callers always get a usable branch name.
func (*Git) DefaultBranchIn ¶
DefaultBranchIn is DefaultBranch evaluated against the repository at dir ("" = current directory).
func (*Git) ExecuteCommand ¶
func (*Git) ExecuteCommandAt ¶
ExecuteCommandAt runs a git command with -C <dir> so it operates in the given directory regardless of the process's current working directory.
func (*Git) FetchOrigin ¶
func (*Git) FetchOriginTimeout ¶
FetchOriginTimeout runs `git fetch origin` bounded by timeout, so a hung network call can't block a caller expecting a fast response (e.g. TaskManager.ReviewScope). A zero timeout is unbounded, same as FetchOrigin.
func (*Git) ForceConfigure ¶
func (*Git) ForceInstall ¶
func (*Git) GetMainWorktree ¶
GetMainWorktree resolves the main worktree (repo root) path from any worktree in the repo, via `git worktree list --porcelain`'s first "worktree <path>" line (always the main worktree). Exported so callers outside this package (e.g. the worktree tooling's repo-candidate resolution) can reuse the same mechanism instead of duplicating it.
func (*Git) GetRepoRoot ¶
GetRepoRoot returns the root directory of the current git repository
func (*Git) GetRepoRootIn ¶
GetRepoRootIn is GetRepoRoot evaluated against the repository at dir ("" = current directory). It also validates that dir is inside a git repo.
func (*Git) IsWorktreeDirty ¶
IsWorktreeDirty checks if a worktree has uncommitted changes
func (*Git) ListBranches ¶
ListBranches returns all local branch names, stripping the current-branch marker (* ) and surrounding whitespace.
func (*Git) ListWorktrees ¶
func (g *Git) ListWorktrees() ([]WorktreeInfo, error)
ListWorktrees returns parsed worktree information
func (*Git) ListWorktreesAt ¶
func (g *Git) ListWorktreesAt(dir string) ([]WorktreeInfo, error)
ListWorktreesAt lists worktrees for the git repository at the given directory. This avoids depending on the current working directory.
func (*Git) PruneWorktrees ¶
PruneWorktrees removes stale worktree entries
func (*Git) PruneWorktreesAt ¶
PruneWorktreesAt removes stale worktree entries, running from the given directory.
func (*Git) RemoteBranchExists ¶
RemoteBranchExists checks if a remote branch exists (e.g., origin/feature-A)
func (*Git) RemoteBranchExistsIn ¶
RemoteBranchExistsIn is RemoteBranchExists evaluated against the repository at dir ("" = current directory).
func (*Git) RemoveWorktree ¶
RemoveWorktree removes a worktree and optionally its associated branch. Resolves the main worktree first so the remove command doesn't run from within the worktree being deleted.
func (*Git) RunCapture ¶
RunCapture runs a git command and returns its stdout, for callers (e.g. `dg task`) that need to parse output rather than just check for an error.
func (*Git) ShortHead ¶
ShortHead returns HEAD's short commit SHA (mirrors `git rev-parse --short HEAD`).
func (*Git) SoftConfigure ¶
func (*Git) SoftInstall ¶
func (*Git) SwitchBranch ¶
type WorktreeInfo ¶
WorktreeInfo contains information about a git worktree.