A workspace is a directory where you make changes. It holds the files of main’s latest landing that match its paths, every file by default, and works on one change at a time, or one stack. Make as many as you like: each is cheap, since it holds only its own paths, and each follows main on its own.
Part of the repository
Start a server, and land a repository with two services and a shared library:
$ af-server --dev
...$ source ~/af-dev/dev/env
$ af workspace add ~/all
Workspace at /home/you/all
Paths: **
main has no landing yet
$ cd ~/all
$ af new -m "Lay out the services"
Working on change znunmtrrkrlqvvuuvumpnqkoyymzzmvq at commit ab4393cb6b26af53761071d9e3f161a544ff6020bf3fa5058dbb59b9e59ff12d
$ mkdir -p services/api services/web libs
$ printf 'serve the api\n' > services/api/main.txt
$ printf 'serve the pages\n' > services/web/main.txt
$ printf 'shared code\n' > libs/common.txt
$ af submit
Submitted commit b27159c0174453ee28a1273155c17a78bcd3c128a99ec27b9b9c41d6c1b2252e, 3 edits in its last snapshot$ af status
Change znunmtrrkrlqvvuuvumpnqkoyymzzmvq (landed) at commit b27159c0174453ee28a1273155c17a78bcd3c128a99ec27b9b9c41d6c1b2252e--path takes a glob from the repository’s root, and repeats. A workspace for the API needs its service and the library:
$ af workspace add ~/api --path 'services/api/**' --path 'libs/**'
Workspace at /home/you/api
Paths: services/api/** libs/**
At landing 1, 2 files written
$ cd ~/api
$ find . -path ./.af -prune -o -type f -print | sort
./libs/common.txt
./services/api/main.txtaf workspace root prints the workspace’s root from anywhere inside it:
$ cd ~/api/services/api
$ af workspace root
/home/you/api
$ cd ~/apiOutside its paths
What the workspace does not hold, it does not write. A file made outside its paths is left out of the change, and neither af diff nor af status mentions it, so keep a workspace’s paths to what you will edit:
$ af new -m "Log each request"
Working on change xyzvqzmklvoyrzouwvotxtnltpskowrr at commit dba2e130aeda561f815cd928cd58fe23126ac231c7ec44a164516f2e573bb0cf
$ printf 'serve the api, logging each request\n' > services/api/main.txt
$ mkdir -p services/web && printf 'not this one\n' > services/web/other.txt
$ af diff
M services/api/main.txt
--- a/services/api/main.txt
+++ b/services/api/main.txt
@@ -1 +1 @@
-serve the api
+serve the api, logging each request
$ af status
Change xyzvqzmklvoyrzouwvotxtnltpskowrr (open) at commit 32b1f7d119829929acdfb5e64cd87ed7a59ed5d1a09991f0d1f83e6cc9b96899
Based on landing 1
Landing waits for: scanOne workspace for each line of work
A workspace works on one change, or one stack, at a time: af new with a change open stacks the new one on top. For a second, unrelated piece of work, add a second workspace; each lands on its own:
$ af workspace add ~/web --path 'services/web/**'
Workspace at /home/you/web
Paths: services/web/**
At landing 1, 1 file written
$ cd ~/web
$ af new -m "Add a footer"
Working on change rsosxlkurvoukxpotzqqoprwzzvvtukw at commit e3e889a9146b8fc7f0bc418fcee1c0f10e57ce68a0da436ebc15e4b496b1d2fb
$ printf 'serve the pages, with a footer\n' > services/web/main.txt
$ af submit
Submitted commit 648eda4a7df6df8ef70bc65a40c4c9b71ec03e903b009f2209b88831309c920f, 1 edit in its last snapshot$ af status
Change rsosxlkurvoukxpotzqqoprwzzvvtukw (landed) at commit 648eda4a7df6df8ef70bc65a40c4c9b71ec03e903b009f2209b88831309c920f
Based on landing 1The API’s change is where you left it, and lands whenever you submit it:
$ cd ~/api
$ af submit
Submitted commit 32b1f7d119829929acdfb5e64cd87ed7a59ed5d1a09991f0d1f83e6cc9b96899, 0 edits in its last snapshot$ af status
Change xyzvqzmklvoyrzouwvotxtnltpskowrr (landed) at commit 32b1f7d119829929acdfb5e64cd87ed7a59ed5d1a09991f0d1f83e6cc9b96899
Based on landing 1Change a workspace’s paths
af sparse changes the paths a workspace holds, as jj sparse does. af sparse list prints them; af sparse set adds and removes globs from the repository’s root:
$ af sparse list
services/api/**
libs/**
$ af sparse set --add 'services/web/**'
Added 1 file, removed 0 files
$ cat services/web/main.txt
serve the pagesThe new path’s files come as the landing your files are at holds them, landing 1 here, without the footer: af sparse moves nothing of main, as jj sparse leaves @ where it is.
The file you made under services/web earlier, outside the paths then, is in view now and left as it is: an edit, which goes into your next change. With no change open, a sync refuses it, as it refuses any edit with nowhere to go, so remove it before af sync brings the newer landings:
$ af sync
Error: 1 edited file and no open change, such as services/web/other.txt
[1]
$ rm services/web/other.txt
$ af sync
...
$ cat services/web/main.txt
serve the pages, with a footerBefore it changes anything, af sparse snapshots your files, so an edit under a path you take away stays in your change. A file you edited since, under a path taken away, is left on disk and named; untracked and ignored files are never touched. Take the web service away again:
$ af sparse set --remove 'services/web/**'
Added 0 files, removed 1 file
$ find . -path ./.af -prune -o -type f -print | sort
./libs/common.txt
./services/api/main.txtaf sparse set --clear --add GLOB starts from no paths, and af sparse reset holds every file again.
Move between changes
af edit moves a workspace to another change: it snapshots your files into the change you are on, then writes the other’s. af duplicate copies a change, as a new open change with the same edits and its own change ID, and prints the change it copied and the copy; edit the copy to try a variant without touching the first:
$ af new -m "Retry failed requests"
Working on change mpytzllymuxqnmuxuowuymnskyqrmoqx at commit 74efcb730860979a25d51321f09c470385e6acb5f33cf279099524b682707660
$ printf 'retry three times\n' > services/api/retry.txt
$ af duplicate | tee ~/copy.out
Duplicated change mpytzllymuxqnmuxuowuymnskyqrmoqx as change tknskzvntxqrzlmtwplvkqusryquzlnu at commit 3a11b02405b11caffeccbbec86ca7773ccaeb196d941fa5b467b8196fdcfb02c
$ export COPY=$(sed -n 's/.* \([k-z]\{32\}\).*/\1/p' ~/copy.out | head -1)
$ af edit $COPY
Working on change tknskzvntxqrzlmtwplvkqusryquzlnu at commit 3a11b02405b11caffeccbbec86ca7773ccaeb196d941fa5b467b8196fdcfb02c
$ printf 'retry five times\n' > services/api/retry.txt
$ af diff
A services/api/retry.txt
--- a/services/api/retry.txt
+++ b/services/api/retry.txt
@@ -0,0 +1 @@
+retry five timesNext
- Shape a stack: several changes in one workspace, landing together.
af workspace,af sparse,af editandaf duplicatein the reference.