Documentation
¶
Overview ¶
Package git provides centralized utilities and command builders for invoking git.
Index ¶
- Constants
- func IsRepo(dir string) bool
- func ResolveCloneDir(reposRoot, uri string) (string, error)
- func URI2RelPath(uri string) (string, error)
- type Command
- func (c *Command) Checkout(ctx context.Context, dir, target string, stderr io.Writer) error
- func (c *Command) Clone(ctx context.Context, uri, targetDir string, stderr io.Writer) error
- func (c *Command) CloneCmd(uri, dir string) []string
- func (c *Command) CurrentBranch(ctx context.Context, dir string) (string, error)
- func (c *Command) DiffCmd(interactive bool, flags ...string) []string
- func (c *Command) EnsureCloned(ctx context.Context, reposRoot, uri string, stderr io.Writer) (string, error)
- 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 ¶
func IsRepo ¶ added in v0.3.0
IsRepo reports whether dir contains a ".git" entry (file or directory).
func ResolveCloneDir ¶ added in v0.3.0
ResolveCloneDir resolves the absolute local directory path under reposRoot for uri.
func URI2RelPath ¶ added in v0.3.0
URI2RelPath converts a repository URI (HTTPS, HTTP, SSH, git://, SCP-like git@host:path, or host/path) into a relative directory path (<host>/<path> without trailing .git).
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) Clone ¶ added in v0.3.0
Clone clones uri into targetDir, routing command output to stderr.
func (*Command) CloneCmd ¶ added in v0.3.0
CloneCmd constructs argv for "git clone -- <uri> <dir>" with the given URI and destination directory.
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) EnsureCloned ¶ added in v0.3.0
func (c *Command) EnsureCloned(ctx context.Context, reposRoot, uri string, stderr io.Writer) (string, error)
EnsureCloned resolves the local directory for uri under reposRoot and clones the repository if it does not already exist (as determined by IsRepo).
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