libvcs.sync.base¶
Foundation for the sync classes. Add your own VCS — or extend libvcs — by
subclassing BaseSync.
Foundational tools to set up a VCS manager in libvcs.sync.
Bases:
objectDescribe a checkout using the backend’s local metadata.
Meaning of
ref_namein the backend.
Whether the selected ref follows new revisions on update.
Whether Subversion entries have different base revisions.
Whether a Subversion subtree follows a different repository URL.
Bases:
objectSelect one backend ref; omission from a sync call follows the current ref.
Branch or Mercurial bookmark to follow; mutually exclusive with
tag,commit, andrev.
Tag name to check out detached; unsupported on Subversion.
Commit or changeset identifier to check out detached; unsupported on Subversion.
Backend revision selector (branch/tag/commit fallback on Git and Mercurial; nonnegative revision number or
"HEAD"on Subversion).
Remote alias supplying branch or revision refs; unsupported on Subversion.
Bases:
objectControl configured-target drift and local changes independently.
How existing checkouts react when their position differs from the resolved target (
"follow"updates;"keep"and"warn"leave existing checkouts unchanged offline).
How updates treat uncommitted local changes (
"abort"refuses the update;"preserve"captures and restores changes with a retainedRecoveryToken;"discard"removes supported local changes).
Bases:
objectIdentify retained private recovery material until explicit release.
VCS backend that captured the material (
"git","hg", or"svn").
Filesystem path to the private token directory holding the operation record and sealed material.
Bases:
objectIdentify a conflicting relative path and its stable backend reason.
Backend conflict classification, such as
"text","binary","tree","untracked-obstruction", or"missing-intent-upstream-changed".
Bases:
objectAn error encountered during a sync step.
Name of the sync step that failed, e.g.
"fetch"or"checkout".
Underlying exception, or
Nonewhen the step reported a failure without raising.
Examples
>>> error = SyncError(step="fetch", message="remote not found") >>> error.step 'fetch' >>> error.message 'remote not found' >>> error.exception is None True
Bases:
objectResult of a repository synchronization.
Whether every sync step succeeded.
SyncResult.add_error()flips this toFalse.
Errors recorded during the sync, in the order they happened. Empty while the sync is still clean.
Outcome of advancing or creating the target checkout.
Examples
>>> result = SyncResult() >>> result.ok True >>> bool(result) True
>>> result = SyncResult() >>> result.add_error(step="fetch", message="remote not found") >>> result.ok False >>> bool(result) False >>> result.errors[0].step 'fetch'
Record an error and mark the result as failed.
- Parameters:
ok (
bool)recovery (
RecoveryToken|None)update_state (
Literal['not-started', 'completed', 'failed', 'unknown'])preservation_state (
Literal['not-needed', 'saved', 'restored', 'conflicted', 'failed', 'unknown'])conflicts (
tuple[SyncConflict, ...])
- Return type:
Bases:
NamedTupleGeneric VCS Location (URL and optional revision).
Return a new dict which maps field names to their values.
Make a new VCSLocation object from a sequence or iterable
Parse pip URL via libvcs.sync.base.BaseSync.url.
- Parameters:
pip_url (
str)- Return type:
Bases:
objectBase class for repositories.
List of supported schemes to register in
urlparse.uses_netloc
Initialize a tool to manage a local VCS Checkout, Clone, Copy, or Work tree.
- Parameters:
progress_callback (
func) –Retrieve live progress from
sys.stderr(useful for certain vcs commands likegit pull. Useprogress_callback:>>> import os >>> import sys >>> def progress_cb(output, timestamp): ... sys.stdout.write(output) ... sys.stdout.flush() >>> class Project(BaseSync): ... bin_name = 'git' ... def obtain(self, *args, **kwargs): ... self.ensure_dir() ... self.run( ... ['clone', '--progress', self.url, self.path], ... log_in_real_time=True ... ) >>> r = Project( ... url=f'file://{create_git_remote_repo()}', ... path=str(tmp_path), ... progress_callback=progress_cb ... ) >>> r.obtain() Cloning into '...'... remote: Enumerating objects: ... remote: Counting objects: ...% (...)... ... remote: Total ... (delta 0), reused 0 (delta 0), pack-reused 0 ... Receiving objects: ...% (...)... ... >>> assert r.path.exists() >>> assert pathlib.Path(r.path / '.git').exists()
url (
str)path (
StrPath)
- Return type:
Return the short name of a repo checkout.
Create synchronization object from pip-style URL.
Return combined stderr/stdout from a command.
This method will also prefix the VCS command bin_name. By default runs using the cwd libvcs.sync.base.BaseSync.path of the repo.
- Parameters:
- Returns:
combined stdout/stderr in a big string, newlines retained
- Return type:
Read the backend’s local checkout metadata without contacting a remote.
- Returns:
Current revision, ref identity, and attachment flags.
- Return type:
Resolve a target from available metadata without fetching or checking out.
- Parameters:
target (
SyncTarget|None,optional) – Explicit target selector; defaults to the constructorrevor the checkout’s current tracked ref.- Returns:
Resolved revision and ref identity from local metadata.
- Return type:
- Raises:
ValueError– Iftargetis unsupported for the backend or cannot be resolved offline.
Read native local-change metadata without contacting a remote.
- Returns:
Truewhen tracked modifications, schedules, or untracked files are present.- Return type:
List retained and interrupted operations without resuming their updates.
- Returns:
Snapshots carrying each retained
RecoveryTokenand any record or material validation errors.- Return type:
tuple[SyncResult, ...]
Recover original state into a new destination while retaining the token.
- Parameters:
token (
RecoveryToken) – Token returned byupdate_repo()orlist_recoveries().destination (
StrPath) – Absent target directory outside the source checkout and recovery store; its parent directory must already exist.
- Returns:
Offline recovery outcome with
tokenretained for repeat use untilrelease_changes()is called.- Return type:
Release owned recovery material explicitly, without changing the checkout.
- Parameters:
token (
RecoveryToken) – Token whose verified private artifacts should be deleted.- Raises:
ValueError– Iftokendoes not match this backend/store or its owned material is missing or ambiguous.- Return type:
Assure destination path exists. If not, create directories.
Pull latest changes to here from remote repository.
- Returns:
Result of the sync operation, with any errors recorded.
- Return type:
- Parameters: