Skip to main content

Crate vcs_core

Crate vcs_core 

Source
Expand description

vcs-core — a unified facade over vcs-git and vcs-jj.

Two pieces both downstream tools kept re-implementing:

  • detect — walk up from a directory to find a .git/.jj repository (jj wins when colocated), returning the BackendKind and root.
  • Repo — a cwd-bound handle that dispatches the common VCS operations (status, diff stat, partial commit, worktree create/remove, …) to whichever backend is present, returning backend-agnostic DTOs. Open it once with Repo::open; re-anchor it to another directory with Repo::at without threading a dir argument through every call.

Tool-specific operations stay on the underlying typed clients, reachable via the cwd-bound Repo::git_at / Repo::jj_at handles (or the raw Repo::git / Repo::jj escape hatches). Some operations are deliberately not on the common surface because the backends model them too differently to unify without lying: a full merge (jj composes new + squash + bookmark moves), operation rollback (jj’s op restore has no faithful git analogue), and range/revset-scoped queries (commit_count, diff stats over a range — git’s a..b and jj’s revsets aren’t interchangeable). Reach those through the bound handles.

use vcs_core::Repo;
let repo = Repo::open(".")?;

The handle is generic over the ProcessRunner so tests can inject a fake; Repo::open uses the real job-backed runner.

Re-exports§

pub use vcs_git;
pub use vcs_jj;

Structs§

DiffStat
Aggregate insertion/deletion counts for the working copy.
FileChange
One changed path in the working copy, unified across git status / jj diff --summary.
Located
The result of detect: which backend, and the repository root it was found at.
Repo
A cwd-bound, backend-agnostic VCS handle. Operations run against the bound directory (cwd); use at to get a sibling handle bound elsewhere.
WorktreeInfo
One attached worktree (git) / workspace (jj).

Enums§

BackendKind
Which version-control tool backs a Repo.
ChangeKind
How a file changed in the working copy.
CreateOutcome
How a worktree was materialised. The facade always reports Plain; the CowCloned variant exists so a consumer that layers a copy-on-write strategy on top can reuse this type.
Error
An error from a Repo operation.
OperationState
Whether the working copy is mid-operation, unified across the backends’ different models: git exposes an in-progress merge or rebase as on-disk state (MERGE_HEAD / a rebase-* dir), while jj has no multi-step operations — it records a conflict directly on the working-copy change.

Traits§

VcsRepo
The backend-agnostic common surface of Repo, as a trait — so a consumer can hold a Box<dyn VcsRepo> / &dyn VcsRepo and code against the operations without naming the ProcessRunner generic or wrapping Repo themselves.

Functions§

detect
Walk up from start to the filesystem root looking for a repository. A .jj directory wins over .git (colocated repos are driven through jj); .git may be a directory or a gitlink file (a linked worktree/submodule). Pure filesystem probing — no subprocess.

Type Aliases§

Result
Result specialised to the facade Error.