Documentation
¶
Overview ¶
Package git wraps the git CLI to scan, inspect, fetch, and pull local repositories concurrently.
Index ¶
- Constants
- func AuthorEmail(ctx context.Context, path string) string
- func AuthoredDays(ctx context.Context, path, since string) []string
- func Checkout(ctx context.Context, path, branch string) error
- func Clone(ctx context.Context, rawURL, root string) (string, error)
- func CommitActivity(ctx context.Context, path string) []int
- func CountCommitsSince(ctx context.Context, path string, since time.Time) int
- func Diff(ctx context.Context, path string, pathspec ...string) (string, error)
- func Fetch(ctx context.Context, r repo.Repo) (repo.Repo, error)
- func FilterByName(repos []repo.Repo, pattern string) ([]repo.Repo, error)
- func NewCommitCount(ctx context.Context, path, since string) int
- func NormalizeCloneURL(u string) string
- func RepoNameFromURL(u string) string
- func Scan(ctx context.Context, root string, concurrency int) ([]repo.Repo, error)
- func Stash(ctx context.Context, path string) error
- func Status(ctx context.Context, seed repo.Repo) (repo.Repo, error)
- func StatusAll(ctx context.Context, seeds []repo.Repo, concurrency int) []repo.Repo
- func StatusLines(ctx context.Context, path string) ([]string, error)
- func WebURL(ctx context.Context, path string) string
- type Branch
- type Commit
- type DetailInfo
- type GraphRow
- type PullResult
Constants ¶
const ( StatusPulled = "pulled" StatusSkipped = "skipped" StatusFailed = "failed" )
Pull result statuses, the allowed values of PullResult.Status.
const DefaultConcurrency = 8
Variables ¶
This section is empty.
Functions ¶
func AuthorEmail ¶
AuthorEmail returns the effective git user.email for a repo (local or global).
func AuthoredDays ¶
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 ¶
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 ¶
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 ¶
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
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
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 FilterByName ¶
FilterByName returns the repos whose name matches the regexp pattern (all repos when pattern is empty).
func NewCommitCount ¶
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 ¶
NormalizeCloneURL accepts a full git URL or an "owner/repo" shorthand.
func RepoNameFromURL ¶
RepoNameFromURL extracts the bare repository name from a clone URL.
func Stash ¶
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 ¶
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 StatusLines ¶ added in v0.6.0
StatusLines returns the non-empty `git status --porcelain` lines, a lightweight way to learn which files are dirty without the full Detail gather.
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.
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.
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.
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.