git

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package git wraps the git CLI to scan, inspect, fetch, and pull local repositories concurrently.

Index

Constants

View Source
const (
	StatusPulled  = "pulled"
	StatusSkipped = "skipped"
	StatusFailed  = "failed"
)

Pull result statuses, the allowed values of PullResult.Status.

View Source
const DefaultConcurrency = 8

Variables

This section is empty.

Functions

func AuthorEmail

func AuthorEmail(ctx context.Context, path string) string

AuthorEmail returns the effective git user.email for a repo (local or global).

func AuthoredDays

func AuthoredDays(ctx context.Context, path, since string) []string

AuthoredDays returns the committer dates (YYYY-MM-DD) of your own commits in a repo since the given window, one entry per commit, for the harvest heatmap.

func Checkout

func Checkout(ctx context.Context, path, branch string) error

Checkout switches the repo to the given branch (git's DWIM creates a tracking branch for a remote-only name). Returns git's error output on failure.

A branch name is a positional argument to `git checkout`, so a value beginning with "-" (which git's plumbing allows in a ref, e.g. a hostile upstream's refs/heads/-f) would be parsed as an option. We cannot use a "--" separator here (that forces pathspec interpretation and breaks branch switching), so we reject such names outright; Branches() already filters them from the picker.

func Clone

func Clone(ctx context.Context, rawURL, root string) (string, error)

Clone clones rawURL into root (one level deep) and returns the new directory name. It validates the URL form and the derived name, passes "--" before the URL, and restricts the git transport, so a pasted URL cannot be read as a flag, run a transport helper, or escape the root.

func CommitActivity

func CommitActivity(ctx context.Context, path string) []int

CommitActivity returns commit counts per week for the last activityWeeks weeks on the current branch, oldest bucket first, for the dashboard sparkline.

func CountCommitsSince added in v0.6.0

func CountCommitsSince(ctx context.Context, path string, since time.Time) int

CountCommitsSince returns how many commits on HEAD have a commit date after `since` (0 on error). Used to flag that a repo has moved on since Claude last ran there.

func Diff added in v0.2.0

func Diff(ctx context.Context, path string, pathspec ...string) (string, error)

Diff returns the working-tree diff against HEAD (staged + unstaged) for the inline diff viewer; an empty string means a clean tree. Falls back to a plain diff when the repo has no commits yet (no HEAD).

func Fetch

func Fetch(ctx context.Context, r repo.Repo) (repo.Repo, error)

Fetch runs `git fetch` for r and returns its refreshed status.

func FilterByName

func FilterByName(repos []repo.Repo, pattern string) ([]repo.Repo, error)

FilterByName returns the repos whose name matches the regexp pattern (all repos when pattern is empty).

func NewCommitCount

func NewCommitCount(ctx context.Context, path, since string) int

NewCommitCount counts commits in HEAD that aren't reachable from `since` (the previously-seen sha) - i.e. how many new commits landed since last visit.

func NormalizeCloneURL

func NormalizeCloneURL(u string) string

NormalizeCloneURL accepts a full git URL or an "owner/repo" shorthand.

func RepoNameFromURL

func RepoNameFromURL(u string) string

RepoNameFromURL extracts the bare repository name from a clone URL.

func Scan

func Scan(ctx context.Context, root string, concurrency int) ([]repo.Repo, error)

Scan discovers repositories under root and returns each with its git status.

func Stash

func Stash(ctx context.Context, path string) error

Stash saves the working tree and index (including untracked files) so a blocked branch switch can proceed; restore later with `git stash pop`.

func Status

func Status(ctx context.Context, seed repo.Repo) (repo.Repo, error)

Status fills in one repo's branch, dirty/stash/ahead-behind counts, upstream, last commit and fetch time, returning it with its display state computed.

func StatusAll

func StatusAll(ctx context.Context, seeds []repo.Repo, concurrency int) []repo.Repo

StatusAll resolves the git status of every seed concurrently, sorted by name.

func StatusLines added in v0.6.0

func StatusLines(ctx context.Context, path string) ([]string, error)

StatusLines returns the non-empty `git status --porcelain` lines, a lightweight way to learn which files are dirty without the full Detail gather.

func WebURL

func WebURL(ctx context.Context, path string) string

WebURL returns the browsable https URL for a repo's origin remote, or "".

Types

type Branch

type Branch struct {
	Name    string `json:"name"`
	Current bool   `json:"current"`
	Remote  bool   `json:"remote"` // remote-only (no local branch yet)
	Rel     string `json:"rel"`    // relative commit date
}

Branch is one ref offered by the branch switcher.

func Branches

func Branches(ctx context.Context, r repo.Repo) ([]Branch, error)

Branches lists local branches (newest commit first) plus remote-only branches from origin, for the branch switcher.

type Commit

type Commit struct {
	Hash    string `json:"hash"`
	Rel     string `json:"rel"`
	Subject string `json:"subject"`
	Author  string `json:"author"`
}

Commit is a single line in a repo's recent history.

func Worklog

func Worklog(ctx context.Context, path, since string) []Commit

Worklog returns your own commits in a repo within the time window (e.g. "1 day ago"), newest first - for the cross-repo activity digest.

type DetailInfo

type DetailInfo struct {
	Branch      string     `json:"branch"`
	Upstream    string     `json:"upstream"`
	StatusLines []string   `json:"status_lines"`
	Commits     []Commit   `json:"commits"`
	Graph       []GraphRow `json:"graph"`
	Remotes     []string   `json:"remotes"`
}

DetailInfo is the expanded view of one repository.

func Detail

func Detail(ctx context.Context, r repo.Repo) (DetailInfo, error)

Detail gathers the working-tree status, recent commits and remotes for one repository, for the detail view.

type GraphRow

type GraphRow struct {
	Rail     string `json:"rail"`
	IsCommit bool   `json:"is_commit"`
	Hash     string `json:"hash,omitempty"`
	Rel      string `json:"rel,omitempty"`
	Subject  string `json:"subject,omitempty"`
	Author   string `json:"author,omitempty"`
}

GraphRow is one line of `git log --graph` output: the rail characters plus, when the line carries a commit, its metadata.

type PullResult

type PullResult struct {
	Repo   repo.Repo `json:"repo"`
	Status string    `json:"status"`
	Reason string    `json:"reason,omitempty"`
	Error  string    `json:"error,omitempty"`
}

PullResult is the outcome of pulling one repository.

func Pull

func Pull(ctx context.Context, seed repo.Repo) PullResult

Pull fast-forwards seed (skipping dirty/no-upstream repos) and reports the outcome as a PullResult.

func PullRepos

func PullRepos(ctx context.Context, repos []repo.Repo, concurrency int) []PullResult

PullRepos pulls every repo concurrently and returns the results in order.

Jump to

Keyboard shortcuts

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