gitexec

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package gitexec provides context-aware shell execution for git and gh.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDeadline

func IsDeadline(err error) bool

IsDeadline reports whether err is caused by context timeout or cancellation.

func RepoBaseName

func RepoBaseName(root string) string

RepoBaseName returns the repository directory name.

func SSHURLFromNameWithOwner

func SSHURLFromNameWithOwner(nameWithOwner string) string

SSHURLFromNameWithOwner returns a deterministic GitHub SSH URL.

func TrimmedStdout

func TrimmedStdout(result Result) string

TrimmedStdout returns stdout without surrounding whitespace.

Types

type CommandError

type CommandError struct {
	Name   string
	Args   []string
	Dir    string
	Stderr string
	// ExitCode is the process exit code, or -1 when unavailable.
	ExitCode int
	Err      error
}

CommandError wraps an external command failure with useful context.

func (*CommandError) Error

func (e *CommandError) Error() string

Error returns a concise command failure message.

func (*CommandError) Unwrap

func (e *CommandError) Unwrap() error

Unwrap returns the underlying process error.

type CommitInfo

type CommitInfo struct {
	ShortHash string
	Unix      int64
}

CommitInfo describes the current HEAD commit.

type ExecRunner

type ExecRunner struct{}

ExecRunner runs commands with os/exec.

func (*ExecRunner) Run

func (r *ExecRunner) Run(ctx context.Context, dir, name string, args ...string) (Result, error)

Run executes name with args in dir and returns stdout and stderr.

func (*ExecRunner) RunWithInput added in v0.2.1

func (r *ExecRunner) RunWithInput(
	ctx context.Context,
	dir string,
	stdin string,
	name string,
	args ...string,
) (Result, error)

RunWithInput executes name with args and writes stdin to the process.

type Git

type Git struct{}

Git wraps common git operations used by skeeper.

func NewGit

func NewGit() *Git

NewGit returns a git helper.

func (*Git) AheadBehind

func (g *Git) AheadBehind(ctx context.Context, dir, left, right string) (int, int, error)

AheadBehind counts commits reachable from left but not right, and right but not left.

func (*Git) CurrentBranch

func (g *Git) CurrentBranch(ctx context.Context, root string) (string, error)

CurrentBranch returns the checked-out branch name.

func (*Git) GitDir

func (g *Git) GitDir(ctx context.Context, root string) (string, error)

GitDir returns the absolute .git directory path for root.

func (*Git) HasHead

func (g *Git) HasHead(ctx context.Context, dir string) bool

HasHead reports whether dir has a valid HEAD commit.

func (*Git) HeadSHA

func (g *Git) HeadSHA(ctx context.Context, root string) (string, error)

HeadSHA returns the current HEAD SHA.

func (*Git) HeadShortSHA

func (g *Git) HeadShortSHA(ctx context.Context, root string) (string, error)

HeadShortSHA returns the short current HEAD SHA.

func (*Git) HeadSubject

func (g *Git) HeadSubject(ctx context.Context, root string) (string, error)

HeadSubject returns the current HEAD subject.

func (*Git) IsDirty

func (g *Git) IsDirty(ctx context.Context, dir string) (bool, error)

IsDirty reports whether the worktree or index has uncommitted changes.

func (*Git) LastCommit

func (g *Git) LastCommit(ctx context.Context, dir string) (CommitInfo, error)

LastCommit returns the short hash and commit time for HEAD.

func (*Git) RefExists

func (g *Git) RefExists(ctx context.Context, dir, ref string) bool

RefExists reports whether ref exists in dir.

func (*Git) Root

func (g *Git) Root(ctx context.Context, dir string) (string, error)

Root returns the top-level worktree path for dir.

type Result

type Result struct {
	Stdout string
	Stderr string
}

Result captures process output streams.

type Runner

type Runner interface {
	Run(ctx context.Context, dir, name string, args ...string) (Result, error)
	RunWithInput(ctx context.Context, dir, stdin, name string, args ...string) (Result, error)
}

Runner executes external commands in a working directory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL