git

package
v0.7.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecPath added in v0.7.0

func ExecPath(ctx context.Context) (string, error)

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps a go-git repository and exposes commit operations.

func NewClient

func NewClient(ioStreams *IO) (*Client, error)

NewClient opens the git repository that contains the current directory. ioStreams configures the streams used for interactive operations; nil uses os.Stdin/Stdout/Stderr.

func NewClientAt added in v0.4.2

func NewClientAt(ioStreams *IO, dir string) (*Client, error)

NewClientAt opens the git repository rooted at dir. ioStreams configures the streams used for interactive operations; nil uses os.Stdin/Stdout/Stderr.

func (*Client) Authors

func (c *Client) Authors() ([]string, error)

Authors returns a deduplicated, alphabetically sorted list of commit author strings ("Name <email>") from the repository history. The current git config identity is prepended as the first (default) entry.

func (*Client) Commit

func (c *Client) Commit(ctx context.Context, msg []byte, opts CommitOptions) (CommitSummary, error)

Commit records a commit with msg and the given options using the system git binary so that all configured hooks (pre-commit, commit-msg, post-commit) run. It returns a CommitSummary suitable for printing to the user.

func (*Client) CreateBranch

func (c *Client) CreateBranch(name, baseBranch string) error

CreateBranch creates a new branch from baseBranch and checks it out.

func (*Client) CurrentBranch added in v0.4.2

func (c *Client) CurrentBranch() (string, error)

CurrentBranch returns the short name of the branch HEAD points to. On a detached HEAD the returned name will not parse as an issue branch, so callers can simply ignore it.

func (*Client) DefaultBaseBranch

func (c *Client) DefaultBaseBranch() (string, error)

DefaultBaseBranch resolves the default base branch in priority order:

  1. refs/remotes/origin/HEAD
  2. "main" if the local ref exists
  3. "master" if the local ref exists

func (*Client) DeleteLocalBranch added in v0.4.2

func (c *Client) DeleteLocalBranch(ctx context.Context, name string, force bool) error

DeleteLocalBranch deletes the local branch by name. force=true uses -D (required after squash merges); force=false uses -d (safe).

func (*Client) IsMergedInto

func (c *Client) IsMergedInto(branchName, baseBranch string) (bool, error)

IsMergedInto reports whether branchName's tip commit is reachable from baseBranch, i.e. whether the branch has been merged into base (mirrors git merge-base --is-ancestor).

func (*Client) LocalBranchNames

func (c *Client) LocalBranchNames() ([]string, error)

LocalBranchNames returns the short names of all local branches.

func (*Client) MergeDryRun added in v0.4.2

func (c *Client) MergeDryRun(ctx context.Context, branchName, baseBranch string) ([]string, error)

MergeDryRun checks whether branchName merges cleanly into baseBranch. It performs the check in a temporary git worktree so the main working tree is never modified. Returns the list of conflicting file paths, or nil if clean.

func (*Client) MergeNoFF added in v0.4.2

func (c *Client) MergeNoFF(ctx context.Context, branchName, baseBranch string) error

MergeNoFF runs a classic --no-ff merge of branchName into baseBranch. After the merge the working directory is on baseBranch.

func (*Client) MergeSquash added in v0.4.2

func (c *Client) MergeSquash(ctx context.Context, branchName, baseBranch, author string) error

MergeSquash squash-merges branchName into baseBranch and commits. author is "Name <email>"; if empty the git config identity is used. After the merge the working directory is on baseBranch.

func (*Client) WorkingTreeRoot

func (c *Client) WorkingTreeRoot() (string, error)

WorkingTreeRoot returns the absolute path of the repository's working tree root.

type CommitOptions

type CommitOptions struct {
	All        bool
	Amend      bool
	NoVerify   bool
	Signoff    bool
	AllowEmpty bool
	Author     string // "Name <email>"; empty = git config identity
}

CommitOptions configures Client.Commit.

type CommitSummary

type CommitSummary struct {
	ShortHash string
	Branch    string
	IsRoot    bool
	Subject   string
	Files     int
	Additions int
	Deletions int
}

CommitSummary holds display information about a newly created commit.

type IO added in v0.7.2

type IO struct {
	In  io.Reader
	Out io.Writer
	Err io.Writer
}

IO holds the standard streams used for interactive git subprocess operations.

Jump to

Keyboard shortcuts

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