Documentation
¶
Overview ¶
Package git provides centralized utilities and command builders for invoking git.
Index ¶
- Constants
- type Command
- func (c *Command) Checkout(ctx context.Context, dir, target string, stderr io.Writer) error
- func (c *Command) CurrentBranch(ctx context.Context, dir string) (string, error)
- func (c *Command) DiffCmd(interactive bool, flags ...string) []string
- func (c *Command) FetchCmd(flags ...string) []string
- func (c *Command) GitBin() string
- func (c *Command) GrepCmd(args ...string) []string
- func (c *Command) IsDirty(ctx context.Context, dir string) (bool, error)
- func (c *Command) LsFilesCmd(flags ...string) []string
- func (c *Command) Output(ctx context.Context, dir string, args ...string) (string, error)
- func (c *Command) PullCmd(flags ...string) []string
- func (c *Command) RemoteURL(ctx context.Context, dir string) (string, error)
- func (c *Command) ResolveDefaultBranch(ctx context.Context, dir string) (string, error)
- func (c *Command) Run(ctx context.Context, dir string, args []string, stdout, stderr io.Writer) error
- func (c *Command) StatusCmd(flags ...string) []string
- type Runner
Constants ¶
const DefaultCommand = "git"
DefaultCommand is the default binary name for git.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
// Bin is the path or name of the git binary. Defaults to DefaultCommand ("git") if empty.
Bin string
// Runner executes the command.
Runner Runner
}
Command represents a git command configuration.
func (*Command) CurrentBranch ¶
CurrentBranch returns the currently checked-out branch in dir.
func (*Command) DiffCmd ¶
DiffCmd constructs argv for "git diff" with the given flags. If interactive is false, it injects "--no-pager" before "diff".
func (*Command) IsDirty ¶
IsDirty checks if the git repository in dir has uncommitted changes or untracked files.
func (*Command) LsFilesCmd ¶
LsFilesCmd constructs argv for "git ls-files" with the given flags.
func (*Command) Output ¶
Output executes a git command in dir and returns its trimmed stdout string.
func (*Command) RemoteURL ¶
RemoteURL returns the remote URL for origin in dir, or an empty string if not found.
func (*Command) ResolveDefaultBranch ¶
ResolveDefaultBranch identifies the default branch for the repository in dir: 1. refs/remotes/origin/HEAD symbolic ref (e.g. "origin/main" -> "main") 2. init.defaultBranch config 3. refs/heads/main exists 4. refs/heads/master exists