Artifact 0dfbf07367ce7b72e1838075f59ef59c05517592412fde1f1b105909efc96fde:
- File
docs/upstreams.md
— part of check-in
[2d73c831f4]
at
2026-11-16 18:00:10
on branch trunk
— An accepted upstream update can be undone, and merges use the recorded base
suit upstream NAME undo reverses the last accept by a new check-in on trunk. Every file that accept changed goes back to what it was, the record upstreams/NAME goes back to the check-in accepted before (or is removed), and the upstream is waiting for review again. History is not rewritten. A file edited on trunk since the accept is a conflict: the command lists it and changes nothing. Undo twice walks back two accepts. An undo is never followed by an automatic accept.
The merge base for an upstream is now the branch check-in the record names, or trunk's first check-in when there is no record, and no longer what the library infers from ancestry. The dry run, the merge and suit's own check for deleted files all use that one base. Because of it:
- the same update can be accepted again after an undo, and gives exactly the files it gave before; - a newer take accepted after an undo brings all of its content, not only its difference from the undone one; - after accept --mine, a later update that leaves the settled lines alone merges cleanly, where it could conflict again before. One that changes them again is a conflict, as it should be.
A take no longer mistakes a file an undo brought back for one of the owner's own. The settle writer restores a file's mode as well as its bytes.
Left: a record edited by hand to name a check-in that is not on the branch makes accept fall back to the library's common ancestor.
159 new store cases, among them the undo story both ways, undo across two machines, and undo in the fault sweep.
1473 unit checks, 620 shell cases, 1153 store cases (was 994), 846 placement cases and 378 project cases, under clang, under gcc 16, with no user name set, and under a strict umask, in one run of make gate (44 minutes). 100% coverage in all 26 source files. One existing line changed: the fault sweep's list gained undo. (user: dmestas, size: 18002) [annotate] [blame] [check-ins using]
# Upstreams An upstream is a source of assets that someone else maintains ([vocabulary.md](vocabulary.md)). Its files come into a wardrobe from a folder on disk, wait there for review, and are merged into trunk. A local fix survives an update, and an update that would overwrite one waits for you. This page is part one (phase 8c-1): taking from a folder. Fetching an archive over HTTPS is part two and is not built. ## The model - Each upstream has a branch of its own, `upstream-NAME`, in the repository of the wardrobe whose `suit.conf` defines it ([conf-format.md](conf-format.md), "More than one wardrobe"). Branches travel with the wardrobe: `suit sync`, `suit tend` and `suit clone` carry every branch, so a take on one machine is seen on the others. - The branch holds only that upstream's files, at `INTO/ENTRY/...` for each entry (file or folder) of the folder read. Its first check-in has trunk's first check-in, the empty one every wardrobe starts with, as its parent, so trunk and the branch share an ancestor and a later merge is three-way. Each take after that is one check-in on top of the branch's tip. - The base of each merge is the check-in of the branch whose files trunk holds now, the one the record `upstreams/NAME` names ("The record"), not the newest ancestor trunk and the branch share. - Updates merge into trunk, in the working copy, after a dry run. A file you edited and the upstream changed on a different line merges; the same line is a conflict, and nothing is changed. - An update waits for review unless the upstream says `trust = auto`. - Taking never touches the working copy. The check-in is built from a deck (libfossil's own calls, `fsl_deck_save`) in the wardrobe's repository, with no checkout, so your edits, new files and the files suit placed stay as they are. Every byte of a file that suit writes into the working copy goes through suit's file writer, as for an update. ## The config ``` [upstream mattpocock] url = https://github.com/mattpocock/skills pin = de4f182c30876a2460ca307e2f601b9b892527e5 path = skills/engineering into = skills trust = review ``` | Key | Meaning | Default | |---|---|---| | `url` | Where part two will fetch from. Not used by `take`. | none | | `pin` | A word naming the version. Required by `take`, at most 256 bytes. It is a label: suit cannot check that a folder matches it. It is written into the check-in's comment. | none | | `path` | The folder of the upstream to read, relative to FOLDER, with no `..` part. | the folder's top | | `into` | Where the files land in the wardrobe: a relative path of names, at most 256 bytes, no empty, `.` or `..` part and no part that starts with a dot. | `skills` | | `trust` | `review` or `auto`. | `review` | An upstream that carries two kinds of asset is written as two sections that share `url` and `pin`, one for each `into`. ## Commands | Command | Does | Exit codes | |---|---|---| | `suit upstream NAME take FOLDER` | Checks the files of FOLDER in on the branch. With `trust = review` leaves an item in the attention file. With `trust = auto` goes on as `accept` does. | 0, 1, 2, 3 lint, 12, 13, 15 | | `suit upstream NAME diff` | Prints what `accept` would change in trunk. Changes nothing. | 0, 1, 2, 12, 15 | | `suit upstream NAME accept [--theirs PATH] [--mine PATH]...` | Merges the branch's tip into trunk. | 0, 1, 2, 12, 13, 15 | | `suit upstream NAME undo` | Reverses the newest accept not yet undone, by a new check-in on trunk. | 0, 1, 2, 12, 13, 15 | | `suit upstreams` | One line for each upstream of every wardrobe. Changes nothing. | 0, 1, 2, 15 | Exit 2 is a usage or config error: an upstream the config does not define (the message names it), a missing `pin`, a `path` with a `..` part or an absolute one, a `--theirs` or `--mine` path that is not a conflict it can settle. Exit 1 is any other error (a folder that cannot be read, a symlink, a limit, a clash). Exit 3 is a lint finding, 12 is local changes in the working copy, 13 is a conflict, 15 is an unfinished update ([store.md](store.md), "The journal and repair"). ### take `FOLDER` is a folder on disk. With `path` set, the folder read is `FOLDER/PATH`, which must exist and be a folder. 1. Names that start with `.` are skipped at any depth, so `.git` never comes in. 2. A symlink is refused: the take fails, naming the link. Only regular files and folders are taken; a fifo or a socket is refused the same way. The executable bit of a file is kept. 3. At most 4096 files and 64 MiB in all (`UPSTREAM_FILES_MAX`, `UPSTREAM_BYTES_MAX`). Over either, nothing is checked in and the message says which. A path is at most 512 bytes inside `INTO`, and folders nest at most 32 levels, counting the folder read as the first; over either, the take fails. 4. A folder that holds no file to take (nothing, or only names that start with a dot) is refused. 5. The lint that runs at check-in runs on the files to be taken, with the rules of the wardrobe's `suit.lint` ([store.md](store.md), "The lint"), and the skill folder rule applies to what lands under `skills/`. A finding stops the take, listed as the lint lists it, with exit 3. 6. A file the take would add at `INTO/...` that trunk already has, and that is neither in the tree of the last check-in on this branch nor in the check-in trunk's `upstreams/NAME` names (an undo can bring back a file a later take removed), is a clash: the take fails naming the file, with exit 1. If another upstream's branch holds the file the message names that upstream. Two upstreams may not supply the same path. Nothing is changed. 7. If the files, their modes and their content, are the branch tip's, nothing is checked in: `upstream NAME: no change`, exit 0. 8. Otherwise one check-in on `upstream-NAME` with the comment `upstream NAME at PIN`. Files the upstream no longer has are removed on the branch. 9. With `trust = review`: `upstream NAME: update waiting for review`, once in the attention file for the upstream (replaced, never repeated), and on standard output. With `trust = auto`: the same item is written, then the take goes on as `accept` and removes it when that merges; a conflict leaves the item described below and exits 13. The take is one transaction. A lint finding, a clash, or a failed write leaves the repository, the working copy and the attention file as they were. ### accept Merges the tip of `upstream-NAME` into trunk, in the working copy of the wardrobe that defines it, with the discipline of the fork merge in `suit sync` ([store.md](store.md)). 1. Nothing taken yet: exit 1. The working copy is not at trunk's tip: exit 1, run `suit store update NAME`; the merge is made at trunk's tip so that its check-in builds on trunk and never forks it. 2. The working copy's `upstreams/NAME` already names the branch's tip: `upstream NAME: nothing to accept`, exit 0. A stale attention item for the upstream is dropped. 3. Local changes in the working copy stop it: `local changes: run suit commit or wait for suit tend`, exit 12. 4. A dry run, against the base the record names ("The record"). A file changed on both sides merges when the changes do not overlap (a line-level three-way merge, as libfossil does it) and is a conflict when they do. Also conflicts: a binary file both sides changed, a file one side changed and the other deleted, and a file added over an untracked file. 5. No conflict: the merge is made through suit's file writer and the journal, the record `upstreams/NAME` is written (below), and the merge is checked in as `Merge upstream NAME at PIN`, where PIN is the pin the branch was taken at. The attention item is removed. 6. Any conflict: no file changes, no conflict marker is written anywhere, the attention item becomes `upstream NAME: N files conflict`, `conflict PATH` is printed for each, in byte order of path, and the exit is 13. 7. `--theirs PATH` takes the upstream's version of a conflicting file and `--mine PATH` keeps trunk's. Each can be given more than once, up to 64 paths for each, and the rest is merged. It succeeds only if every conflict is named. With conflicts left, those are listed and counted and nothing changes. A PATH that is not a conflict it can settle (not in conflict at all, or a file added over an untracked file, which the merge would overwrite) is an error, exit 2, and a PATH named by both is a usage error. 8. An accept that was undone can be made again, and so can a newer take: the base is the check-in the record names after the undo ("Undo"). `--theirs` and `--mine` first let the merge write the files, with markers in the ones that overlap, then replace each settled file with the chosen version. The journal covers a stop part way, as for an update. ### diff One line for each file `accept` would change in trunk, in byte order of path: `add PATH`, `change PATH`, `remove PATH` or `conflict PATH`. It prints the list only. A unified diff of trunk's version against the merged result is not printed: libfossil can merge and diff text, but a merged result only exists once the merge has written files, and `diff` changes nothing. The exit is 0 even when there are conflicts, since the lines say so. The same checks as `accept` apply first (nothing taken, not at trunk's tip, nothing to accept, local changes). ### upstreams One line for each upstream of every wardrobe, in byte order of name: ``` NAME: STATE (taken PIN_TAKEN, config PIN) ``` `PIN_TAKEN` is read from the comment of the branch's tip and `PIN` is the config's (`none` when it has none). `STATE` is one of: - `never taken`: no branch yet (the line is `NAME: never taken (config PIN)`). - `current`: the working copy's `upstreams/NAME` names the branch's tip. - `waiting for review`: it does not, or there is no such file or it is malformed. - `conflict`: it is not, and the attention file holds `upstream NAME: N files conflict`. ## The record Every accept that succeeds writes one small tracked file in the wardrobe, `upstreams/NAME`: the full hash of the `upstream-NAME` check-in that was accepted, a space, its pin and a newline. It is written through suit's file writer after the merge and any settling are applied and before the check-in, and is part of the merge check-in, so that check-in always changes at least that file and libfossil's refusal of an empty check-in cannot arise. It is how suit knows an upstream is `current`: the file names the branch's tip, whatever the merge did, and it travels with the wardrobe, so another machine sees it after `suit sync`. It is not decided by asking libfossil whether the tip is an ancestor, because a merge settled with `--mine` can be checked in without a merge parent (observed in the library's `plink` table), which would leave the upstream `waiting` for ever. A missing or malformed file means never accepted; the next accept rewrites it. The record is also the base of the next merge. `accept` and `diff` merge the branch's tip into trunk against the check-in the record names (libfossil's `baselineRid`, fossil's `merge --baseline`), or against trunk's first check-in, the parent of the first take, when there is no record. So what is merged is always the upstream's change from the files trunk took last to the tip, whatever trunk's history holds: after an undo, whose undone tip stays an ancestor of trunk, and after `--mine`, whose check-in has no merge parent. A record that is there but names no check-in of the branch (changed by hand) leaves the base to the newest ancestor trunk and the branch share, as libfossil finds it. The merge check-in still has the tip as its second parent, so `fossil timeline` and `zit` show the branch merged into trunk as before. The lint passes it, a take does not treat it as a clash (it is in no upstream's `into` unless you point `into` at `upstreams`), and placing reads only the `skills`, `agents` and `commands` folders, so it is never placed. `diff` does not list it. ## The attention file One item for each upstream, replaced and never repeated ([store.md](store.md), "The attention file"): - `upstream NAME: update waiting for review`, from a take. - `upstream NAME: N files conflict`, from an `accept` that found conflicts. N counts the ones left after `--theirs` and `--mine`. A clean `accept` removes it. The item belongs to the machine that took: another machine sees the update through `suit upstreams`. An item of an upstream is kept apart from the items of a wardrobe: `suit tend` of a wardrobe that has the same name as an upstream leaves the upstream's item, and the reverse. When `suit sync` (or `suit store update`) brings the working copy to a newer version, each upstream branch in the wardrobe's repository whose tip the working copy's `upstreams/NAME` records as accepted has its item removed, so an accept made on another machine does not leave a stale item here. Items of upstreams still waiting stay. The check reads the record, not the config, and does nothing when the repository has no upstream branch. ## Undo `suit upstream NAME undo` reverses the newest accept of NAME that has not been undone, in the wardrobe that defines it. It is a new check-in on trunk. It never rewrites history and never moves a branch. `suit back` cannot do this: the undo record libfossil keeps for a merge ends when the merge is checked in, so after an accept, as after any `suit commit`, `suit back NAME` says it cannot go back (exit 14) and changes nothing. Each of these stops with its own message and changes nothing: 1. NAME is not an upstream of any wardrobe: exit 2. 2. Local changes in the working copy: `local changes: run suit commit or wait for suit tend`, exit 12. 3. The working copy is not at trunk's tip: exit 1, run `suit store update NAME`, as for `accept`. 4. An unfinished update: exit 15. 5. Nothing to undo: `upstream NAME: nothing to undo`, exit 0. That is when `upstreams/NAME` is missing or not whole (a hash of 40 to 64 hex digits, a space, a pin, a newline and nothing after), or when no accept of NAME is left in trunk's history. Let M be the check-in of the accept: the newest check-in in trunk's history whose comment is `Merge upstream NAME at PIN`, not counting one that a later `Undo upstream NAME at PIN` already reversed (each undo hides the accept below it, so two undos in a row reverse two accepts). Let P be M's first parent, which is trunk just before the accept. For every file M changed relative to P (added, changed or removed, the record file included, a change of the executable bit too): - If the file at trunk's tip is byte for byte, and mode for mode, what M made of it (or still absent, when M removed it), it goes back to its content in P, or is removed when P did not have it. - Otherwise it changed after the accept, and that is a conflict. So is a file that would come back where an untracked file of yours is. With any conflict no file changes, `conflict PATH` is printed for each in byte order of path, `upstream NAME: N files conflict; undo changed nothing` goes to standard error, and the exit is 13. There is no `--mine` or `--theirs`: settle the files by hand and run it again. A file the accept did not change is not looked at, so an edit of yours to one survives the undo. The files are written through suit's file writer and the journal, as for `accept`, and checked in on trunk as `Undo upstream NAME at PIN`, PIN being the pin recorded for M. It is an ordinary check-in with one parent. A failed step puts every file back, and the repository and the attention file stay as they were. The record file goes back to its content in P: the previous accepted hash and pin, or no file when P had none. So `suit upstreams` says `waiting for review` again, since the branch's tip is not the accepted one, and the item `upstream NAME: update waiting for review` is written, as after a take with `trust = review`. This holds for `trust = auto` too: an undo is never followed by an automatic accept, and a later take of the same files says `no change`. ### After an undo The record names the previous accepted check-in, or is gone, so `accept` merges the branch's tip against that ("The record"). Accepting the undone update again gives trunk the files it had after the accept that was undone, byte for byte, and `diff` lists what that would change. A newer take is merged the same way: all of its changes since the check-in the record names come in, not only those since the undone take, and your edits to other lines stay. With `trust = auto` such a newer take is accepted as any take is; the undo itself is never followed by an automatic accept. ## Limits of the library - A file one side deleted and the other changed is not reported by libfossil's merge: it drops the file the upstream deleted even if you changed it, and leaves out one you deleted and the upstream changed. Suit finds both by comparing the base's files with each side's, and counts them as conflicts. `--mine` and `--theirs` settle them. - Left alone, libfossil merges against the newest ancestor trunk and the branch share, which after an undo or a `--mine` is not what trunk holds; suit names the base itself ("The record"). Only a record changed by hand so that it names no check-in of the branch falls back to that ancestor. - Updating a working copy to a version that has fewer files leaves the empty folders behind, so on another machine an undo that removed a folder's last file leaves the folder, empty. ## Part two Not built, and waiting on HTTPS (the same transport as `suit sync` to an `https://` remote): `suit upstream NAME fetch` will download the archive at `url` for the pinned version, check it against a checksum kept in a second key, unpack it and take it as `take` does, and `suit tend` will look for new versions by itself. Everything on this page works the same on what it takes.