git

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package git wraps the git CLI operations that commit-spark needs.

A Client executes git in its Dir (empty means the process's current directory, which is the normal case; tests set Dir to a temp repository). Query methods capture output and return it; the passthrough methods (StageAll, Commit, Push, PushUpstream) stream git's stdout/stderr to the Client's writers so hooks and commit summaries appear live.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Dir            string
	Stdout, Stderr io.Writer
}

Client runs git commands.

func (*Client) Commit

func (c *Client) Commit(ctx context.Context, message string) error

Commit runs git commit -m message.

func (*Client) CurrentBranch

func (c *Client) CurrentBranch(ctx context.Context) (string, error)

CurrentBranch returns the current branch name (empty when detached).

func (*Client) DefaultBranch

func (c *Client) DefaultBranch(ctx context.Context) (string, error)

DefaultBranch returns the remote's default branch via symbolic-ref refs/remotes/origin/HEAD. It errors when origin/HEAD is unset (common for a repo created with only `git remote add`); the caller decides on a fallback.

func (*Client) DiffRange

func (c *Client) DiffRange(ctx context.Context, rangeSpec string) (string, error)

DiffRange returns the diff for the given range specification (e.g. "origin/main..HEAD").

func (*Client) Push

func (c *Client) Push(ctx context.Context) error

Push runs git push.

func (*Client) PushUpstream

func (c *Client) PushUpstream(ctx context.Context, branch string) error

PushUpstream runs git push -u origin <branch>.

func (*Client) RemoteURL

func (c *Client) RemoteURL(ctx context.Context, name string) (string, error)

RemoteURL returns the URL of the named remote.

func (*Client) RepoRoot

func (c *Client) RepoRoot(ctx context.Context) (string, error)

RepoRoot returns the repository root (git rev-parse --show-toplevel).

func (*Client) StageAll

func (c *Client) StageAll(ctx context.Context) error

StageAll runs git add --all.

func (*Client) StagedDiff

func (c *Client) StagedDiff(ctx context.Context, excludeFiles []string) (*StagedDiff, error)

StagedDiff returns the staged diff (git diff --cached --diff-algorithm=minimal).

Lock files are auto-excluded the same way the original implementation did: if any staged file is NOT a lock file, lock files (package-lock.json, pnpm-lock.yaml, *.lock) are excluded; if ALL staged files are lock files they are kept. excludeFiles are additional user-supplied pathspec exclusions. When nothing remains staged, the returned StagedDiff has an empty Files slice.

type StagedDiff

type StagedDiff struct {
	Files []string
	Diff  string
}

StagedDiff is the result of StagedDiff: the retained file list and the diff text. An empty Files slice means nothing is staged.

Jump to

Keyboard shortcuts

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