OXYGENHUB
# 14edbaaf5291 oxygen / docs / guide.md
23.6 KiB · Markdown · last changed Remote bookmarks work like local ones; a newer format names the oxy that cannot read it (closes #48, closes #49) 1 month ago renderedsource blame history raw
1
# Oxygen user guide
2
3
This guide is organised by task. It assumes the `oxy` binary is on your
4
path (`cargo build --release` puts it in `target/release/`). The design
5
behind every command is in [spec.md]spec.md; this guide only tells you
6
what to type and what to expect.
7
8
Oxygen tracks *changes* rather than snapshots: a change is the set of
9
edits you made, it commutes with unrelated changes, and conflicts are
10
recorded in history instead of blocking you. Two ideas recur below:
11
12
- A **bookmark** (default `main`) names a *state*: the set of changes it
13
  contains. A state can have several **heads** when independent changes
14
  have not been related to each other; that is normal, not a problem.
15
- The **working copy** is itself a change that Oxygen rewrites every time
16
  it looks at your files. `oxy commit` turns it into a real change.
17
18
Output uses colour and glyphs on a terminal; pipe it, pass `--plain`, or set
19
`NO_COLOR` for plain ASCII.
20
21
## 1. Set yourself up
22
23
```
24
oxy identity create --name "Ada Lovelace" --email [email protected]
25
oxy config --user core.sign change
26
```
27
28
`identity create` generates a composite Ed25519 + ML-DSA-65 key pair, keeps
29
the secret in `~/.config/oxy/keys/`, and records you as the default author
30
in `~/.config/oxy/config.toml`. With `core.sign = change` every commit is
31
signed; without it, changes are sealed in batches when you push (also
32
authenticated, just later). Use `--local` to record the identity in one
33
repository only.
34
35
`oxy identity show` prints the key, its expiry, delegates, and whether the
36
secret is available. `oxy identity export` writes the public identity to a
37
file to hand to whoever manages a trust policy (section 8).
38
39
## 2. Start a repository
40
41
```
42
mkdir project && cd project
43
oxy init
44
oxy status
45
```
46
47
`oxy init` creates `.oxy/`. Add `.oxyignore` (gitignore syntax, per
48
directory, negations with `!`) for files that should never be tracked;
49
`/target` and `*.tmp` are typical entries. As in Git, ignore rules only
50
affect untracked files: a file already in history stays tracked until you
51
delete it.
52
53
To take over an existing Git project, see section 12.
54
55
## 3. Everyday work
56
57
```
58
oxy status                 # what changed since the last commit
59
oxy diff                   # the edits, file by file
60
oxy commit -m "Add retry loop"
61
oxy log                    # newest first; -n 10, -v for full messages
62
oxy show 658990aa          # one change by ChangeId prefix, #hash prefix, or @
63
```
64
65
Commit part of what changed with `oxy commit PATH.. -m "..."` (only those
66
paths; the rest stays as uncommitted work) or `oxy commit -i -m "..."`, which
67
offers each hunk in turn like `git add -p`; a hunk that another chosen hunk
68
needs, such as the directory a new file lives in, comes along by itself.
69
70
`status --json` prints the same for tools, with every conflict's kind, path and
71
contributing ChangeIds. On a terminal, `status` lists each path with a mark: `✚ added`, `✎ modified`, `✖ removed`,
72
`➜ renamed`, `⚙ mode`. Renames are detected: a removed file and an added
73
file of the same kind whose contents are at least half alike are recorded
74
as a move of the same file, so identity survives a rename.
75
76
Files containing NUL bytes are stored whole ("opaque"); text files are
77
stored line by line and merge line by line. `.oxyattributes` overrides the
78
guess (section 14).
79
80
Every change has two names: a **ChangeId** (`658990aa…`) that survives
81
rewrites, and a content hash (`#7469d16c…`) that changes when the change is
82
edited. Use whichever you have; prefixes work.
83
84
## 3a. Bookmarks: branches without merges
85
86
A bookmark names a state; each workspace works on one (`main` to begin
87
with). Because changes commute, "merging" is the union of two bookmarks'
88
heads, with no merge change and any real conflict recorded as in section 6.
89
90
```
91
oxy bookmark create feature        # at the working copy's base
92
oxy bookmark switch feature        # check it out; commits now go here
93
oxy commit -m "Feature work"
94
oxy bookmark switch main
95
oxy merge feature                  # main now holds both; working copy follows if clean
96
oxy bookmark list                  # ● current, heads, ↑n/↓n against origin
97
oxy push -b feature                # publish a bookmark other than the current one
98
oxy bookmark set feature 658990aa  # move it; oxy bookmark delete feature to drop it
99
```
100
101
`oxy checkout feature` materialises a bookmark without switching to it, and
102
a bookmark name works wherever a change is expected when it has one head.
103
Each workspace remembers its own bookmark, so two directories can sit on
104
two bookmarks of one repository.
105
106
**A state is its heads, not a history.** If you are coming from Git, this
107
is the one thing to know. A bookmark holds its heads and what they depend
108
on, and a change depends only on the changes it builds on (the files it
109
touched), not on everything recorded before it. So on a bookmark with
110
several heads, a new bookmark at one change can be a much older-looking
111
tree. `oxy bookmark create NAME CHANGE` refuses when that would leave out
112
earlier work and lists what it would lack. Then pick one:
113
114
```
115
oxy bookmark create logo 745307b4 --upto  # everything here up to that change, as a Git branch would be
116
oxy bookmark create logo 745307b4 --only  # just that change and what it depends on
117
oxy bookmark create logo                  # the whole current state, usually what you want
118
```
119
120
`oxy bookmark switch` says when the bookmark you switch to lacks changes
121
that the one you left has.
122
123
**A remote's bookmarks.** A clone fetches every change, checks out the
124
remote's default bookmark, and names the others `origin/NAME`: use them
125
anywhere a bookmark is expected (`oxy log origin/develop`,
126
`oxy diff main origin/develop`). `oxy bookmark list --all` shows them.
127
`oxy bookmark switch develop` makes a local `develop` from `origin/develop`
128
when there is none, and `oxy pull` then keeps every local bookmark up to
129
date with the remote's of the same name, not only the current one. Pulling
130
is a union, so this never loses work.
131
132
```
133
oxy clone https://oxygenhub.io/owner/game --recursive   # subrepos too
134
oxy bookmark list --all
135
oxy bookmark switch develop        # from origin/develop
136
oxy pull                           # updates develop, main and the rest
137
```
138
139
### A develop / feature flow
140
141
Names with `/` work everywhere, pushing included:
142
143
```
144
oxy bookmark create feature/42-login          # at the working copy's base
145
oxy bookmark switch feature/42-login --carry  # started already? take the edits along
146
oxy commit -F msg.txt                         # a long message from a file
147
oxy push -b feature/42-login
148
oxy bookmark switch develop
149
oxy merge feature/42-login                    # the working copy follows when it was clean
150
oxy push                                      # develop, with the feature in it
151
oxy bookmark delete feature/42-login          # oxy push --delete feature/42-login on the remote
152
```
153
154
`bookmark switch` stops when the working copy has uncommitted edits, so
155
nothing is lost by accident. There are two ways past it:
156
- `--carry` takes the edits along. It is refused only when the target
157
  bookmark has other versions of the files they touch.
158
- `--discard` drops the edits.
159
160
`oxy describe` names what the working copy holds, for build stamps:
161
- a tag, when a tag holds exactly this state;
162
- otherwise the nearest tag with the distance from it and the change;
163
- or, with no tag behind it, the bookmark and the change;
164
- with `-dirty` added when there are uncommitted edits.
165
166
## 4. Fix up history
167
168
Oxygen keeps its own record of every operation, so all of these are safe to
169
try and to undo.
170
171
```
172
oxy describe -m "Better message"        # reword the head the working copy sits on
173
oxy describe 658990aa -m "..."          # reword any change; dependents are rewritten
174
oxy amend                               # fold the working copy into the head
175
oxy amend --into 658990aa               # fold it into an older change
176
oxy split 658990aa src/parser.rs        # split a head: those paths become a separate first change
177
oxy abandon 658990aa                    # drop a change; its content stays on disk
178
oxy squash 658990aa --into 9df9ac29     # fold a change into one it depends on
179
oxy rebase 658990aa --onto feature      # re-express a change against another base
180
oxy undo                                # undo the last operation, whatever it was
181
oxy op log                              # the operation log
182
```
183
184
Rewriting a change that others depend on rewrites them too, keeping their
185
ChangeIds. Because unrelated changes already coexist, `rebase` is rarely
186
needed; its job is to change what a change is said to build on, for instance
187
to drop a dependency on something you are about to abandon. Where a dependent referred to a line that no longer exists, the
188
reference is re-anchored to the nearest surviving line and `oxy abandon`
189
prints a note about it.
190
191
## 4a. Who wrote this, and what broke it
192
193
```
194
oxy blame src/parser.rs          # every line: the change that introduced it, author, age
195
oxy blame src/parser.rs --json
196
```
197
198
Blame is exact: each line is an atom that remembers the change that
199
introduced it, so renames cost nothing and there is no heuristic.
200
201
```
202
oxy bisect start
203
oxy bisect good v1.2             # a change, bookmark or tag known to be fine
204
oxy bisect bad main              # and one known to be broken
205
oxy bisect run make test         # exit 0 good, 125 skip, anything else bad
206
oxy bisect reset                 # back to where you were
207
```
208
209
Without `run`, each step checks out a state to test and you answer with
210
`oxy bisect good`, `bad`, or `skip`. The candidates are the changes the bad
211
state has that the good one lacks, ordered so every tested state is
212
well-formed; the answer is the first change whose inclusion breaks things.
213
214
## 5. Move around
215
216
```
217
oxy checkout                    # the bookmark's heads
218
oxy checkout 658990aa           # the state of one change and its dependencies
219
oxy checkout v1.2               # a tag
220
oxy checkout --discard ...      # throw away uncommitted work first
221
```
222
223
Checking out a single older change gives you the files that change and its
224
dependencies touch, not a full snapshot from that date: in Oxygen a change
225
depends only on what it actually builds on.
226
227
## 6. Conflicts
228
229
A conflict never stops a commit, fetch, or pull. It is recorded in the
230
state and shown by `oxy status`, which exits with status 2 while any
231
conflict remains. Conflicted text files are written with markers:
232
233
```
234
<<<<<<< oxy conflict 1 of 2, side 1: change k7m2p9 "Add retry loop"
235
... lines ...
236
======= oxy conflict 1 of 2, side 2: change q3x8w1 "Refactor client"
237
... lines ...
238
>>>>>>> oxy conflict 1 of 2 end
239
```
240
241
Edit the file to what it should be (keep one side, both, or neither) and
242
remove the markers. Tree conflicts, such as two files wanting the same
243
name, appear as `<name>.oxy-conflict-<n>` candidates: keep the one you
244
want under the right name and delete the rest.
245
246
```
247
oxy resolve      # which conflicts your edits resolve, which still have markers
248
oxy commit -m "Resolve retry vs refactor"
249
```
250
251
The commit is recorded as a *resolution*, a change that depends on every
252
side of the conflict; anyone who fetches it gets the conflict resolved.
253
254
## 7. Work with others
255
256
Run a server (any machine with the repositories under one directory):
257
258
```
259
oxy serve --root /srv/oxy --bind 0.0.0.0:8890 --token SECRET \
260
          --tls-cert cert.pem --tls-key key.pem
261
```
262
263
Without `--tls-*` the server speaks plain HTTP; keep that on a loopback
264
address or behind a TLS terminator. `--token` makes pushes require a bearer
265
token; reads stay open.
266
267
On your machine:
268
269
```
270
echo SECRET | oxy auth login https://host:8890 --with-token --ca my-ca.pem
271
oxy clone https://host:8890/project
272
cd project
273
oxy push
274
oxy pull
275
```
276
277
`--ca` is only for a server with a self-signed certificate. On a hub such as
278
OxygenHub, `oxy auth login https://oxygenhub.io` signs in through the
279
browser instead: it shows a code to approve on the hub, and the hub issues a
280
token that lasts 90 days past its last use.
281
282
### Signing in
283
284
`oxy auth login HUB` keeps one token per hub (scheme, host and port) in
285
`~/.config/oxy/credentials.toml`, readable by you only, and every repository
286
on that hub uses it: clone, fetch, push and subrepos alike. Nothing secret is
287
written into a checkout. `oxy auth status` lists the hubs you are signed in
288
to and checks each token with its hub; `oxy auth logout HUB` forgets the token
289
and revokes it on the hub.
290
291
To keep tokens in the system keyring instead, name a Git credential helper:
292
`oxy config --user auth.helper libsecret` (Linux), `osxkeychain` (macOS) or
293
`manager` (Windows). The file then keeps only the account and CA.
294
295
A token is found in this order: the remote's own `remote.<name>.token`, then
296
`$OXY_TOKEN` (for CI), then the store, then a remote on the same hub in an
297
enclosing checkout (so a subrepo uses its parent's). oxy sends a token over
298
`https` only, or over plain `http` to this machine; it is never sent to
299
another host after a redirect, and a credentials file that others can read
300
is ignored.
301
302
- `oxy fetch` updates `origin/main` without touching your bookmark.
303
- `oxy pull` fetches, then makes your bookmark, and every other local
304
  bookmark the remote also has, the union of both sides.
305
  There is no merge commit; unrelated changes simply coexist, and a real
306
  conflict is recorded as in section 6. The working copy follows when it was
307
  clean.
308
- `oxy push` sends your changes and moves the remote bookmark. If the remote
309
  moved since you last fetched, the push is refused: pull and push again.
310
  `--force` overrides the compare-and-swap.
311
- `oxy remote add|remove|list` manages remotes; the clone source is `origin`.
312
313
A repository can also be cloned from a local path, which is handy for tests
314
and for a bare "hub" on a shared disk.
315
316
## 8. Decide who may publish: the trust policy
317
318
Without a policy a repository is *unverified*: everything is accepted and
319
every remote command says so. A policy names root keys and the keys allowed
320
to update each bookmark; servers and clients enforce it.
321
322
```
323
oxy policy init                    # your key becomes the only root; push publishes it
324
oxy policy show
325
oxy policy grant alice.identity    # alice.identity came from her `oxy identity export`
326
oxy policy grant ci.identity --pattern 'release/*'
327
oxy policy revoke 9458b656         # by KeyId prefix
328
oxy verify                         # signature status of every change in the log
329
```
330
331
Several people can hold root keys:
332
333
```
334
oxy policy root add bob.identity
335
oxy policy root threshold 2        # future updates need two root signatures
336
```
337
338
Once the threshold is above one, an update you make alone becomes a
339
*proposal file* (`policy-<serial>.proposal`, or `--out`). Send it to another
340
root holder, who runs `oxy policy sign policy-7.proposal`; whoever completes
341
the threshold applies it, and the next push publishes it. Everyone else
342
picks it up on fetch, verifying each step from the policy they already
343
trust.
344
345
## 9. Keys over time
346
347
```
348
oxy identity rotate                   # fresh key pair; old signatures stay valid
349
oxy identity renew --expires 365      # same keys, new expiry in days (0 = never)
350
oxy identity delegate add ci.identity # let another key sign on your behalf
351
oxy identity delegate remove 3f2a…
352
oxy identity revoke                   # retire your own key
353
oxy identity revoke 3f2a… --reason "laptop stolen"   # any key, if you hold a root
354
```
355
356
Rotation, renewal, and delegation all issue a successor identity that names
357
the previous one. If a policy names your key, it is updated to the successor
358
in the same step (as a proposal when more root signatures are needed).
359
Changes signed before the rotation remain authorised; a revoked key
360
authorises nothing. `oxy verify` shows signatures by revoked keys as valid
361
but revoked.
362
363
## 10. Tags and workspaces
364
365
```
366
oxy tag create v1.2 -m "First release"   # the current heads; or name changes
367
oxy tag list
368
oxy workspace add ../project-hotfix      # a second checkout sharing the repository
369
oxy workspace list
370
oxy workspace forget ../project-hotfix
371
```
372
373
A tag is an immutable state, signed when you have a key, and travels with
374
push and fetch. Workspaces have their own working copy and bookmark
375
(`workspace.bookmark`) but share objects and history.
376
377
### Receipts from CI
378
379
A runner such as OxygenFlow signs a receipt for every job it runs: what ran,
380
in what environment, on which files, and the result. Receipts are kept with
381
the state they ran on.
382
383
```
384
oxy receipt list                         # receipts for the bookmark's state
385
oxy receipt show 3f2a9c                  # one in full, with its signature checked
386
oxy receipt export 3f2a9c build.receipt  # hand it to someone
387
oxy receipt verify build.receipt         # check one without keeping it
388
oxy receipt import build.receipt         # verify and keep it
389
```
390
391
## 11. Big repositories: partial, sparse, shallow
392
393
```
394
oxy clone URL --max-blob 1M          # files above 1 MiB are fetched on first read
395
oxy clone URL --sparse src --sparse docs   # materialise only these subtrees
396
oxy clone URL --depth 50             # only the last 50 levels of history
397
oxy sparse src docs tests            # change the filter later
398
oxy deepen 100                       # fetch more history below the boundary
399
```
400
401
Lazy blobs and sparse trees do not affect commits: what you do not have is
402
left exactly as it was. A shallow clone starts from a *checkpoint* of the
403
state, so status and commit work at full speed from the first minute.
404
405
## 11a. Nested repositories (submodules)
406
407
A subrepo is another repository checked out at a path and pinned to a state,
408
Oxygen or Git. The pin is versioned like a file, so two people pinning
409
different states get an ordinary conflict.
410
411
```
412
oxy submodule add https://host/lib.git libs/lib     # Git or Oxygen URL; records .oxymodules
413
oxy commit -m "Add lib"                              # the pin is committed with the parent
414
oxy submodule status                                 # pin vs what is on disk
415
oxy submodule update --init                          # after a clone: fetch nested repositories
416
oxy submodule remove libs/lib                        # drop the node; the directory stays
417
```
418
419
Committing the parent records whatever the nested repository is at, and
420
checking out an older parent state moves the nested repository back, unless
421
it has uncommitted changes, which are never overwritten. An absent nested
422
repository keeps its pin until you run `update --init`. Git submodules
423
survive `oxy git import` as Git pins and go back out as gitlinks on export.
424
425
## 12. Git interoperability
426
427
```
428
oxy git import ../project.git ./project-oxy --branch main   # convert a Git history
429
oxy git fetch https://github.com/you/project.git            # bring new Git commits in
430
oxy git push  https://github.com/you/project.git            # publish your changes to Git
431
oxy git export ../mirror.git                                # a plain Git mirror of the bookmark
432
```
433
434
Import turns each commit into one change (merge commits become
435
resolutions), keeps authors and hashes as `Git-Author`/`Git-Commit`
436
trailers, detects renames, and skips submodules. `git fetch`/`git push` keep
437
a bare mirror under `.oxy/git/`; a push is refused until the remote's tip
438
has been fetched, so it always fast-forwards. Exported commits carry
439
`Change-Id` and `Oxy-Hash` trailers.
440
441
## 13. Automate: hooks
442
443
Executables in `.oxy/hooks/<event>` (never cloned) receive one JSON object
444
on stdin. `pre-commit`, `pre-push` and other `pre-*` hooks veto by exiting
445
non-zero, and their stderr becomes the error message. Events:
446
`pre-commit`, `post-commit`, `pre-push`, `post-fetch`, `post-checkout`, and
447
`semantic-deps`, which runs at commit when `hooks.semantic-deps = true` and
448
answers `{"deps": ["<hash>", …]}` to make the change depend on more than it
449
textually references.
450
451
## 14. Per-path attributes, ignores, locks
452
453
`.oxyattributes` uses gitattributes syntax:
454
455
```
456
*.png     binary
457
*.txt     text eol=lf
458
*.psd     lockable nocompress
459
```
460
461
`binary`/`text` override content sniffing, `eol=lf|crlf` normalises line
462
endings in the store and on checkout, `nocompress` stores chunks raw, and
463
`lockable` files are checked out read-only until you take the local lock:
464
465
```
466
oxy lock assets/logo.psd
467
oxy unlock assets/logo.psd
468
```
469
470
Locks are advisory and local; server-side locks are planned.
471
472
## 15. Configuration
473
474
Two files, both `key = "value"` lines: `~/.config/oxy/config.toml`
475
(`oxy config --user KEY VALUE`) and `.oxy/config` (`oxy config KEY VALUE`).
476
The repository file wins. `OXY_HOME` relocates the user directory. `OXY_TIMINGS=1` prints how long each phase of a snapshot takes (loading the base state, rendering it, reading the working copy, building the change) to standard error, for finding out where a slow command spends its time.
477
478
| Key | Meaning |
479
|---|---|
480
| `author.name`, `author.email`, `author.key` | who you are; `key` is set by `identity create` |
481
| `core.sign` | `change` to sign every commit; otherwise seals at push |
482
| `core.op-retention` | days for which old operations keep their states alive (90) |
483
| `core.gc-grace` | days an unreachable object survives (14) |
484
| `core.checkpoint-interval` | changes between automatic checkpoints (256) |
485
| `filter.max-blob`, `filter.paths` | lazy blobs and sparse subtrees (section 11) |
486
| `hooks.semantic-deps` | run the semantic-deps hook at commit |
487
| `workspace.bookmark` | this workspace's bookmark (`main`) |
488
| `remote.<name>.url`, `.token`, `.ca` | remotes; token and CA fall back to `OXY_TOKEN` and `OXY_CA`, then `oxy auth login`'s store |
489
| `auth.helper` (user file) | a Git credential helper to keep `oxy auth` tokens in, such as `libsecret` |
490
491
## 16. Shell prompt
492
493
`oxy prompt` prints `main 658990aa*+2` (bookmark, working copy, `*` dirty,
494
`!` conflicted, ahead/behind origin) in a few milliseconds and records
495
nothing. See [prompt.md]prompt.md for bash, oh-my-bash, zsh, and fish
496
snippets and the `--format` placeholders.
497
498
## 17. Housekeeping
499
500
```
501
oxy gc              # prune unreachable objects past the grace period, repack into one pack
502
oxy gc --now        # ignore the grace period (only when nothing else is writing)
503
oxy fsck            # check every object, the op log, references, signatures, checkpoints
504
oxy doctor          # check identity, config and remotes, with what to do about each problem
505
oxy checkpoint      # serialise the bookmark's state so large histories load instantly
506
```
507
508
Both run automatically: packing when loose objects pile up, checkpoints
509
every `core.checkpoint-interval` changes.
510
511
## 17a. Scripting and editors
512
513
Every reporting command takes `--json` (`status`, `log --path`, `show`,
514
`diff`, `hunks`, `blame`, `resolve`, `op log`, `bookmark list`, `remote list`,
515
`fetch`, `pull`, `push`, `submodule status`, `bisect status`, `verify`,
516
`policy show`, `root`, `version`). `oxy cat PATH -r CHANGE` prints a file as
517
it was, `oxy discard PATH..` restores files to the base, and `oxy hunks`
518
numbers the working copy's hunks for `commit --hunks` and `discard --hunks`.
519
520
## 18. If something looks wrong
521
522
- **"the remote has change … which you do not; pull first"**: someone
523
  pushed since your last fetch. `oxy pull`, then push.
524
- **"policy needs N root signature(s)"** on fetch: the server's policy was
525
  updated in a way your copy cannot verify. Ask a root holder whether the
526
  chain of updates was published; a fresh clone trusts the current policy.
527
- **`oxy status` exits 2**: conflicts remain; see section 6.
528
- **Many heads on `main`**: independent changes that do not reference one
529
  another. Nothing to fix; the state is their union.
530
- **Undo anything**: `oxy undo` reverts the last operation, including
531
  pulls, checkouts, and rewrites.
532
533
## Shell completions and man pages
534
535
```sh
536
oxy completions bash > ~/.local/share/bash-completion/completions/oxy   # bash
537
oxy completions zsh > "${fpath[1]}/_oxy"                                 # zsh
538
oxy completions fish > ~/.config/fish/completions/oxy.fish               # fish
539
oxy man --dir ~/.local/share/man/man1                                    # then: man oxy-commit
540
```
541
542
The oh-my-bash plugin in `contrib/oh-my-bash` loads the bash completions itself.