Version control for agents

docs/making-changes.md in oak/oak

docs/making-changes.md 114 lines · 4.7 KB

Making changes

See what changed, checkpoint it, publish it, and keep up with main.

See what changed

oak status                 # modified, added, deleted files
oak status --short         # one line per path (same as --porcelain)
oak status --json --compact  # bounded JSON, for agents
oak diff                   # working tree vs. your last checkpoint
oak diff src/ README.md    # only these paths
oak diff --branch          # everything on this branch (commits + uncommitted) vs. where it forked from main
oak diff --stat            # per-file +/- counts
oak diff --name-only       # just the paths
oak diff --print           # plain unified diff to stdout instead of the viewer
oak diff --check           # whitespace errors and leftover conflict markers; exits 1 if any

On a terminal, oak diff opens a full-screen viewer, a file tree beside the diff, that takes arrow, vi and emacs keys; ? lists them. Piped, or with --print or --json, it prints instead. OAK_DIFF_TOOL names an external diff tool to use instead.

oak diff also compares branches and commits without checking anything out; see reviewing.

Checkpoint with oak commit

oak commit                 # snapshot every change in the working tree
oak commit src/parser/     # only changes under these paths
oak commit --push          # checkpoint, then publish the branch

There's no staging area and no commit message; -m is refused and points at oak desc. Commits are checkpoints you can return to, and what the branch does is written once, as its description. They're squashed into one commit on main when the branch merges.

Nothing leaves your machine until you push.

Publish with oak push

oak push

Sends the branch's new commits and its description to the server. Only chunks the server doesn't have are uploaded, so a small change to a large file sends only the changed chunks.

SituationWhat to do
First push of a repository made with oak initoak push --repo <org>/<name>, or answer the prompt on a terminal.
Refused because the branch moved on the serveroak pull, then push again.
Overwrite the branch on the serveroak push --force
See what would be sentoak push --plan --json

Pushing to main is refused; main changes only by merging.

Stay in sync with oak pull

oak pull

oak pull brings in new commits on your branch from the server (pushed from another machine, or by an agent), then merges the latest main into your branch. Conflicts come up here, on your branch; see merging.

CommandWhat it does
oak pullFetch your branch, then merge main into it.
oak pull --branch-onlyFetch your branch only; skip merging main.
oak fetchRefresh your local copy of main without touching your branch or working tree.
oak pull --forceThrow away local commits the server doesn't have and match the remote branch.

Undo things

oak restore path/to/file      # put a file back to your last checkpoint
oak restore -s 3f9fab02 file  # …or to how it was at another commit
oak reset                     # discard every uncommitted change (asks first; -f to skip)
oak reset src/                # …or just under a path

oak switch -d <hash> puts the working tree at an earlier checkpoint, and oak switch -c from there starts a new branch. oak split drops, reorders or splits a branch's commits into separate branches, like git rebase -i.

Ignore files

Put gitignore patterns in .oakignore at the repository root. Without one, Oak reads .gitignore, so an imported git repository keeps working. When both exist, only .oakignore counts.

Always ignored: .oak/, .git/, and OS files such as .DS_Store, ._*, Thumbs.db and desktop.ini.

Hooks

Executable files at .oak/hooks/<event> run at fixed points, like Git hooks:

HookWhenOn failure
pre-commitBefore oak commit writes anythingAborts the commit
post-commitAfter a successful commitPrints a warning

Hooks run from the repository root with OAK_HOOK set to the event name. They're local and never pushed; files ending in .sample are ignored. oak commit --no-verify skips them once.

A typical Rust pre-commit:

#!/bin/sh
set -e
cargo fmt --all
cargo clippy --workspace -- -D warnings

Large files

There's nothing to set up. Files are split into chunks and stored once, so pushes and pulls move only the chunks that changed. One push can carry up to 25 GiB; see limits.

Exit codes

Every command uses the same exit codes: 5 means conflicts, 3 means the repository is locked and you can retry. The table is in cli.