Skip to contents

Pull and push until nothing local is left. Wraps mergin sync from the mergin-client CLI, which pulls, uploads one batch of at most 100 changes, and repeats while changes remain, pulling between batches (#399).

Usage

rfp_mergin_sync(path)

Arguments

path

Character. Path to the local Mergin project directory.

Value

Invisible character - the local project version after the sync (the last version pushed, or the last pulled when there was nothing to push). The raw CLI output is available as attr(result, "output").

Details

The CLI exits 0 when a sync fails, so the outcome is verified on disk and against the server rather than read from the exit code:

  • the CLI reported Project synced successfully and no error line;

  • no local changes remain, as the client counts them (an editor's .qgs edit, which the server will not take, does not count);

  • the server version is at or above the local one (a phone may push just after);

  • when this call pushed, the last version it logged is the local version, and its author on the server is the logged-in user.

Any failure is an error carrying the CLI output and the tail of the client log. A failed sync, including a CLI that crashed or was killed, is checked against the server first: when a batch landed while the local metadata stayed behind, or the client could not apply a version to its base files, the error says not to sync again (the next sync's pull can duplicate rows) and to take a fresh copy. Versions pulled between batches are reported, and a conflicted copy created by a pull raises a catchable warning(): it is a local file like any other, so the sync uploaded it.

Examples

if (FALSE) { # \dontrun{
rfp_mergin_status("~/Projects/gis/restoration_wedzin_kwa")
version <- rfp_mergin_sync("~/Projects/gis/restoration_wedzin_kwa")
cat("Synced to", version, "\n")
} # }