Select branches
Each workspace takes the code of each repository from a source. A source is a branch, or a checkout that is on your machine. You select the sources when you make the workspace. You can change them with lo set.
Select the sources of a new workspace
Section titled “Select the sources of a new workspace”-
List the branches that the repositories of the template have:
Terminal window lo template branches shopThe table shows the services of each repository, the branch that
lo newtakes, and all the branches. -
Make the workspace. Add one
service=branchpair for each source that is not the default:Terminal window lo new shop-b --template shop storefront=feature/new-checkoutThe services that you do not name take the default ref of the template.
-
Start the workspace:
Terminal window lo up shop-b
lo new fetches each repository that has an origin remote. If the fetch fails, lo new stops. It does not use a branch list that can be out of date.
Forms of a pair
Section titled “Forms of a pair”Each pair has the form name=value. The name is a service or a repository of the template. The value is a branch or a path.
| Pair | Meaning |
|---|---|
storefront=feature/x |
The branch feature/x of the repository of the service storefront. |
orders-api=feature/x |
The branch feature/x of the repository orders-api. The name is a key in repos:. |
storefront=~/code/storefront |
The checkout in that directory, as it is. |
orders-api=remote:staging |
The remote staging of the service. The service does not run on your machine. |
orders-api=https://... |
A URL that you enter as the remote of the service. |
A value that starts with /, ~/, ./ or ../ is a path. A value that starts with remote:, or that has a scheme such as https://, is a remote. Any other value is a branch. See remotes.
All the services of one repository run from the same source. If two pairs give different values for one repository, lo new fails. A service with an image has no source, and you cannot select a branch for it.
Select branches with a word
Section titled “Select branches with a word”Use --match to select a branch of each repository with one word. For a ticket, this is shorter than a pair for each repository.
lo new shop-c --template shop --match TICKET-12For each repository that you did not name, lo new looks for the branches that contain the word. The word must be a complete part of the branch name. A part ends at the start or end of the name, or at /, -, _ or .. The match ignores case.
- If the repository has one such branch,
lo newtakes it. - If the repository has more than one such branch,
lo newfails and lists them. Name the branch that you want in a pair. - If the repository has no such branch, the repository takes the default ref.
localspace looks at the local branches first. It looks at the branches of origin only if no local branch matches. To see the result before you make a workspace, run lo template branches shop --match TICKET-12.
The default ref
Section titled “The default ref”A repository that has no pair and no match takes its default ref: the ref of the repository in repos:, or defaults.ref of the template. localspace reads it from origin, where it is always current. A repository with no origin remote uses the local branch. If a repository has no pair and the template gives it no default ref, lo new fails.
Run a service on a remote
Section titled “Run a service on a remote”A pair can also tell that a service or a resource runs elsewhere, on a deployment that localspace does not manage. The value is remote:<name> for a remote that the template lists, or a URL. A resource also takes local.
lo new shop-b --template shop orders-api=remote:staginglo new shop-c --template shop orders-api=https://orders.qa.acme.com \ --attr orders-api.api_key='${secret:orders/qa_key}'--attr <unit>.<attribute>=<value> gives an attribute to the remote of one workspace. It replaces the value of the template. lo set takes the same pairs and the same flag. See use services that run elsewhere.
A pair for a repository does not change a service that runs on a remote. A pair for the service does: a branch moves it to your machine.
Where the code runs from
Section titled “Where the code runs from”lo new only records the sources. lo up makes the checkouts.
- A branch that no worktree has: localspace makes a git worktree in
worktrees/<workspace>/<repository>in the localspace home. This is an owned worktree. If the branch is only onorigin, the worktree has a new local branch that tracks it. - The default ref: the owned worktree has a detached HEAD at the commit of
origin. Eachlo upmoves it to the new commit oforigin, if it holds no unsaved work. - A branch that is checked out in a worktree of your repository: localspace uses that worktree as it is. It is not an owned worktree.
- A path: localspace uses that checkout as it is, with its current branch. If HEAD is detached, it uses HEAD.
localspace removes only the worktrees that it made. It does not change or remove a checkout that you made. See Safety.
Switch the branches of a workspace
Section titled “Switch the branches of a workspace”Use lo set to move a workspace to other sources. The resources keep their data.
-
Run the command with the new pairs. The forms are the same as for
lo new:Terminal window lo set shop-b storefront=main orders-api=feature/refund -
Read the warnings. If the changed files include a migration,
lo settells you thatlo db resetcan be necessary. A migration is a.sqlfile, or a file in a directory with the namemigrationsormigrate. -
If necessary, run
lo db reset <workspace> <resource>. See Resources.
lo set does these steps:
- It fetches and finds the new sources.
- It compares the previous commit and the new commit of each repository.
- It finds how each service of the repository runs from the new source.
- It stops each running service that must restart, and removes the previous owned worktree.
- It makes the new worktree, and starts the services again.
The template tells which services restart. Set on_switch on a service to restart, rebuild or none. The default is restart. A service rebuilds when a changed file matches one of its rebuild_on patterns. A pattern that ends in / matches a directory.
Only a service that runs restarts. A stopped service uses the new source at the next lo up.
Unsaved work
Section titled “Unsaved work”lo set refuses to remove an owned worktree that holds work that is not saved. That is an uncommitted change, an untracked file, or a commit that is on no remote. The error tells you each item.
- Go to the worktree that the error names.
- Commit and push your work.
- Run
lo setagain.
Cases that lo set refuses
Section titled “Cases that lo set refuses”- The workspace runs from a worktree of a repository. That is, you started it with
lo upin that worktree. Check out the other branch in the worktree. - No service of the repository runs on your machine in this workspace. The services are shared, or they run on a remote. Name a service of the repository to move it to your machine, or make a new workspace.
- You give no pair and no
--attr.lo setmust have at least one.
Related
Section titled “Related”lo new,lo setandlo template branchesgive all the flags.lo commitsshows the branch, the checkout and the unsaved work of a service.lo rmremoves the owned worktrees of a workspace. It refuses while one holds unsaved work.- Write a template shows
defaults.refandrepos:. - Use services that run elsewhere tells how to use a remote.