workspace

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package workspace is ynf's git: a mirror per repository, a checkout per step, and the commit and push that only ynf (never the agent) performs (ADR-007). The token reaches git through environment configuration, so it never appears in a process listing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Author

type Author struct{ Name, Email string }

Author is the git identity of ynf's commits.

type Workspace

type Workspace struct {
	Root   string
	Token  string
	Author Author
	// RemoteURL maps owner/name to a clone URL. Default https://github.com/<repo>.git.
	RemoteURL func(repo string) string
}

Workspace manages mirrors and checkouts under Root.

func (Workspace) Changed

func (w Workspace) Changed(ctx context.Context, wt string) ([]string, error)

Changed stages everything and lists the changed paths.

func (Workspace) Checkout

func (w Workspace) Checkout(ctx context.Context, mirror, ref, dir string) (string, error)

Checkout makes a self-contained clone of the mirror at origin/<ref>, detached, and returns its real path. Real, because a symlinked path makes git and linters disagree about which files changed (ADR-007).

A clone rather than a git worktree: a worktree's .git is a file pointing into the mirror by absolute host path, so a container that mounts only the checkout has no repository. Here .git is a real folder inside dir, and the one mount is enough. --local hardlinks the mirror's objects (no copy on the same filesystem); --shared would not do, as its alternates file points back into the mirror. The clone keeps the mirror's remote-tracking branch as origin/<ref>, so `--new-from-merge-base=origin/main` works in the run.

func (Workspace) Commit

func (w Workspace) Commit(ctx context.Context, wt, message string) (string, error)

Commit commits the staged change with message and returns the commit SHA.

func (Workspace) Diff

func (w Workspace) Diff(ctx context.Context, wt, base string) (string, error)

Diff is everything the checkout differs from base by, new files included: the agent's patch. It stages the change, as Changed does.

func (Workspace) FirstParent

func (w Workspace) FirstParent(ctx context.Context, mirror, sha string) (string, error)

FirstParent is the commit before a merge: the first parent of sha in the mirror. For a squash merge it is the base branch as it was; for a merge commit, the same, with the branch merged in.

func (Workspace) Head

func (w Workspace) Head(ctx context.Context, wt string) (string, error)

Head returns the checkout's HEAD commit.

func (Workspace) Mirror

func (w Workspace) Mirror(ctx context.Context, repo string) (string, error)

Mirror clones the repository, or fetches it if already cloned, and returns its real path.

func (Workspace) Push

func (w Workspace) Push(ctx context.Context, wt, repo, branch string) error

Push force-pushes HEAD to branch. ynf only force-pushes branches it originated; adopted branches are never force-pushed (ADR-007).

func (Workspace) PushFastForward

func (w Workspace) PushFastForward(ctx context.Context, wt, repo, branch string) error

PushFastForward pushes HEAD to branch only if that is a fast-forward: the push to someone else's branch, which must never overwrite their work (ADR-007).

func (Workspace) RangeDiff

func (w Workspace) RangeDiff(ctx context.Context, mirror, from, to string) (string, error)

RangeDiff is the change from one commit to another in the mirror: the human patch.

func (Workspace) RemoteHas

func (w Workspace) RemoteHas(ctx context.Context, mirror, branch string) bool

RemoteHas reports whether origin has the branch (after the last fetch).

func (Workspace) RemoteSHA

func (w Workspace) RemoteSHA(ctx context.Context, mirror, branch string) (string, error)

RemoteSHA returns origin's branch tip as of the last fetch.

func (Workspace) RemoveCheckout

func (w Workspace) RemoveCheckout(dir string) error

RemoveCheckout deletes a checkout. It is a whole repository, so there is no registration to undo.

Jump to

Keyboard shortcuts

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