Documentation
¶
Overview ¶
Package backend defines the VCS backend interface and shared types. New VCS backends implement the Backend interface and register themselves via Register; the tool then uses them for detection, status, and dispatch.
Index ¶
- Constants
- Variables
- func ComputeBookmarkState(bookmark *BookmarkStatus)
- func DetectDir(path, marker string) (bool, error)
- func ExtractExitCode(err error) (int, bool)
- func Names() []string
- func Register(backend Backend) error
- func ResetDetectCache()
- type Backend
- type BookmarkStatus
- type RefState
- type RepoStatus
- type RunResult
Constants ¶
const ( PriorityJj = 20 PriorityGit = 10 )
Variables ¶
var ErrNoArgs = errors.New("no arguments provided")
ErrNoArgs is returned by Backend.Run when called with no arguments.
Functions ¶
func ComputeBookmarkState ¶
func ComputeBookmarkState(bookmark *BookmarkStatus)
ComputeBookmarkState derives the RefState for a single BookmarkStatus from its Ahead/Behind counts and whether a remote is configured.
func DetectDir ¶
DetectDir returns true if the directory at path contains a directory with the given marker name (e.g. ".git" or ".jj").
func ExtractExitCode ¶
ExtractExitCode returns the exit code from an exec.ExitError. Returns ok=false if err is nil or not an ExitError.
func Names ¶ added in v0.10.0
func Names() []string
Names returns all registered backend names, in priority order.
func Register ¶
Register adds a backend to the global registry. Detection priority follows Backend.Priority() order (higher first).
func ResetDetectCache ¶ added in v0.12.0
func ResetDetectCache()
ResetDetectCache clears the memoized Detect results. Used by tests and by long-lived callers (TUI refresh) that want fresh detection.
Types ¶
type Backend ¶
type Backend interface {
// Name returns the canonical backend identifier, e.g. "git" or "jj".
Name() string
// Priority returns the detection priority. Higher values are checked first.
// For colocated repos, the backend with the highest priority wins.
Priority() int
// Detect returns true if the directory at path is managed by this VCS.
// It must not return an error for non-matching dirs; only real I/O
// failures warrant an error.
Detect(path string) (bool, error)
// Status returns the unified status for the repo at path.
Status(ctx context.Context, path string) (RepoStatus, error)
// SubcommandArgs returns the full argument list for a VCS operation.
// For example, git returns ["fetch"] but jj returns ["git", "fetch"]
// because jj wraps git operations under the "git" subcommand.
SubcommandArgs(op string) []string
// Subcommands returns available subcommands for the VCS tool, e.g.
// ["add", "branch", "log", "status"] for git. Returns an empty slice
// when subcommands cannot be loaded (tool not found, parse error, etc).
Subcommands(ctx context.Context) ([]string, error)
// Run executes the given args using this VCS tool in path.
// When interactive is true, the caller has already arranged for the
// subprocess to inherit the terminal; Run must not capture output.
Run(ctx context.Context, path string, args []string, interactive bool) (RunResult, error)
}
Backend is the interface every VCS backend must implement. Backends are stateless; all repo-specific state is passed per call.
type BookmarkStatus ¶
type BookmarkStatus struct {
Name string
// Remote name (e.g. "origin"). Empty when no remote.
Remote string
Ahead int
Behind int
// True when jj reports a bookmark conflict (diverged push).
// For git this is always false; git represents this as a diverged state.
Conflict bool
// Computed sync state derived from Ahead/Behind/Remote.
State RefState
}
BookmarkStatus holds tracking information for a single bookmark (jj) or the current branch (git). Both backends populate this struct so the UI can render them identically.
type RefState ¶
type RefState int
RefState describes the relationship between a local ref and its remote.
const ( // RefStateUnknown means the bookmark has no tracking remote. RefStateUnknown RefState = iota // RefStateSynced means local matches remote. RefStateSynced // RefStateAhead means local is ahead of remote. RefStateAhead // RefStateBehind means local is behind remote. RefStateBehind // RefStateDiverged means local and remote have diverged. RefStateDiverged // RefStateNoRemote means no remote is configured. RefStateNoRemote // RefStateGone means remote ref was deleted. RefStateGone )
func WorstState ¶
func WorstState(bookmarks []BookmarkStatus, hasConflict bool) RefState
WorstState returns the most severe RefState across all bookmarks. Severity order: Conflict > Diverged > Behind > Ahead > NoRemote > Synced.
type RepoStatus ¶
type RepoStatus struct {
// Ref is the human-readable current position: branch name for git,
// change ID short for jj.
Ref string
// Bookmarks holds tracking state for all local bookmarks/branches.
// Git populates exactly one entry (the current branch).
// jj populates one entry per local bookmark at or near @.
Bookmarks []BookmarkStatus
// OverallState is the worst-case RefState across all Bookmarks,
// used for sorting and the summary colour in the ll table.
OverallState RefState
Dirty bool
// True when the repo has unresolved VCS conflicts
// (jj conflict markers, git merge conflicts).
Conflict bool
CommitMsg string
// Relative commit time (e.g. "3 days ago").
CommitTime string
// Working copy (@) commits ahead of HEAD bookmark. Only populated by
// the jj backend (git's working copy is always at the branch tip).
LocalAhead int
}
RepoStatus is the unified status schema populated by each backend.
type RunResult ¶
type RunResult struct {
// Output is the combined stdout+stderr of the subprocess, captured
// when running in parallel. In interactive mode this is empty.
Output string
ExitCode int
}
RunResult holds the outcome of a single repo dispatch.
func RunCommand ¶
func RunCommand( ctx context.Context, binary string, path string, args []string, interactive bool, ) (RunResult, error)
RunCommand executes a binary with args in the given directory. When interactive, it passes through stdin/stdout/stderr to the terminal. Otherwise it captures combined stdout+stderr into the returned RunResult. ExitError is unwrapped: the exit code is set on the result and the error is cleared (non-zero exit is not considered an infrastructure failure).