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 ¶
const ( // PriorityJj is the detection priority for the jj backend. PriorityJj = 20 // PriorityGit is the detection priority for the git backend. PriorityGit = 10 )
Variables ¶
This section is empty.
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.
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
// 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 is the local bookmark/branch name.
Name string
// Remote is the remote name (e.g. "origin"). Empty when no remote.
Remote string
// Ahead is the number of local commits not present on the remote.
Ahead int
// Behind is the number of remote commits not present locally.
Behind int
// Conflict is true when jj reports a bookmark conflict (diverged push).
// For git this is always false; git represents this as a diverged state.
Conflict bool
// State is the 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 is true when there are uncommitted changes in the working copy.
Dirty bool
// Conflict is true when the repo itself has unresolved VCS conflicts
// (jj conflict markers, git merge conflicts).
Conflict bool
// CommitMsg is the last commit/change message.
CommitMsg string
// CommitTime is the relative commit time (e.g. "3 days ago").
CommitTime string
// LocalAhead is the number of commits the working copy (@) is ahead of
// the HEAD bookmark/branch. 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).