Open History to see the last commit
1# Projects with several repositories
2
3A project can cover more than one repository, so one thread can read and change all of them. This
4fits three common setups:
5
6- A plain folder that holds several repositories, such as `shop/api` and `shop/web`.
7- A repository that works alongside others it depends on, anywhere on the machine.
8- A repository with submodules.
9
10The project folder does not have to be a Git repository itself.
11
12## Which repositories a project covers
13
14There is no list to keep. A project covers every repository inside its folder: T3 Code looks one
15level down, and one level further inside folders that are not repositories themselves, such as
16`src` or `packages`. It reads the disk each time, so a repository you clone there is part of the
17project straight away, and one you delete is gone from it. Worktrees of another repository are left
18out.
19
20**Settings → Projects → Repositories** shows what the project covers on each machine.
21
22### Folders outside the project
23
24A repository somewhere else on the machine has to be added, because adding it lets agents work in a
25place they could not reach before.
26
27- On web and desktop, use **Add folder** under **Repositories**.
28- If the project folder has a `.code-workspace` file, the folders it lists outside the project are
29 offered there with an **Add** button, on mobile too.
30- From a script, `t3 project add <path> --track <folder>` adds one.
31
32**Remove** takes an added folder out of the project. It never deletes files. Added folders are
33paths on one machine, so the same project on another machine has its own. A project can cover up to
34128 folders.
35
36### Leave a repository out
37
38To keep a repository inside the project folder out of the project, name it in the `t3.json` in the
39project folder, relative to that folder:
40
41```json
42{
43 "ignoreRepositories": ["vendor/big"]
44}
45```
46
47It is then not reviewed on its own and gets no worktree. Because the file is checked in, the choice
48applies on every machine.
49
50### Submodules
51
52Submodules are checked out when a worktree is created. If that fails, a submodule stays
53uninitialized and the thread does not list it until you run `git submodule update --init` in the
54thread's folder. A thread that changes one shows it as its own repository, with its own diff and
55Git actions, while the repository that holds it shows the changed pin. A submodule never
56gets a worktree of its own, because its parent repository decides where it is checked out.
57
58## Review changes
59
60Each turn lists the files it changed, grouped by repository, and its diff covers all of them. See
61[Review turn changes](source-control.md#review-turn-changes).
62
63On web and desktop, the Diff pane's **Uncommitted**, **Changes**, and **Commits** sources read one
64repository at a time. Pick it from the repository picker next to the source picker. The picker
65lists every repository the thread reaches, including ones no turn has touched, so edits you made by
66hand show up too.
67
68## Commit, push, and open pull requests
69
70Git actions run in one repository at a time.
71
72- **Web and desktop:** the thread details panel lists the repositories the thread changed, most
73 recent first, each with its branch and uncommitted changes. Expand one to commit, push, or open a
74 pull request there. **Other repositories...** adds any other repository of the project.
75- **Mobile:** open **Git controls** in the thread. The sheet lists the repositories under
76 **Repositories**; tap one for its own commit, push, and pull request actions.
77
78A pull request opened in a repository is linked to the thread under that repository, not under the
79project's.
80
81## Worktree threads
82
83**New worktree** works for these projects too. The thread gets its own folder laid out like the
84project, and each repository you choose gets a worktree there, all on the thread's branch.
85
86Choose the repositories with the repositories control next to the workspace picker before you send.
87Every repository is included when the project covers eight or fewer; with more, none is
88included until you choose. A repository with no commit yet is left out, since it has nothing to
89branch from. On web and desktop, your last choice is remembered for the project in
90that browser. To bring another repository into a running thread, pick it under **Other
91repositories** in the thread details panel or the mobile Git sheet.
92
93Each repository starts from the thread's base branch where it has a branch of that name, and from
94its own default branch otherwise. A plain folder has no branch picker, so on web and desktop you
95name the base branch at the bottom of the repositories control.
96
97In a plain folder, the files outside your repositories are shared links to the originals, not
98copies. Editing one changes it for every thread.
99
100### Lay the folder out yourself
101
102If the default layout does not suit your project, for example because build output must be per
103thread, workspace metadata has to be generated, or submodules need preparing, the project can
104create the folder with its own command. Add this to the `t3.json` in the project folder:
105
106```json
107{
108 "worktreeLayout": {
109 "create": "./scripts/new-workspace.sh",
110 "remove": "./scripts/remove-workspace.sh"
111 }
112}
113```
114
115`create` runs in the project folder and must leave the thread's copy of the project folder in
116place. It receives these environment variables:
117
118| Variable | Value |
119| -------------------------- | ---------------------------------------------------------- |
120| `T3_PROJECT_ROOT` | The project folder. |
121| `T3_WORKTREE_ROOT` | The empty folder to fill for this thread. |
122| `T3_WORKTREE_PROJECT_PATH` | Where the project folder goes inside it. |
123| `T3_WORKTREE_BRANCH` | The thread's branch name. |
124| `T3_WORKTREE_BASE` | The base branch, or empty when the thread has none. |
125| `T3_WORKTREE_REPOSITORIES` | The repositories chosen for the thread, one path per line. |
126
127Every repository of the project that the command checks out at the same relative place becomes the
128thread's checkout of it. `remove` is optional and runs before T3 Code removes whatever is left.
129
130What the commands can rely on, and what they must do:
131
132- **Checkouts are linked worktrees on the thread's branch.** Make each one with
133 `git worktree add` from the repository it belongs to, on `T3_WORKTREE_BRANCH`. T3 Code later
134 removes, restores, and renames these through Git, so it refuses a clone or a checkout on another
135 branch and the thread does not start.
136- **`create` can run more than once.** It runs again when a thread's folder has gone missing, by
137 which time the branch already exists. Check the branch out when it is there and create it
138 otherwise.
139- **`remove` can run on a folder that is partly gone**, such as after a failed `create` or an
140 earlier cleanup. Storage cleanup never deletes files that exist only in the thread's folder, so
141 `remove` should delete what `create` generated.
142- **A failed `create` is rolled back.** Checkouts it already made are removed.
143- **One command runs at a time per project**, so a command can update a shared file in the project
144 folder without its own locking.
145- **Each command has ten minutes.**
146
147A project with no other repository can declare a layout too. This example gives each thread
148a worktree with its submodules checked out. The command runs in `sh`, and in `cmd.exe` on Windows,
149so write it for the shell of the machine the project is on; this one is for `sh`:
150
151```json
152{
153 "worktreeLayout": {
154 "create": "(git worktree add \"$T3_WORKTREE_PROJECT_PATH\" \"$T3_WORKTREE_BRANCH\" 2>/dev/null || git worktree add -b \"$T3_WORKTREE_BRANCH\" \"$T3_WORKTREE_PROJECT_PATH\" ${T3_WORKTREE_BASE:-HEAD}) && git -C \"$T3_WORKTREE_PROJECT_PATH\" submodule update --init"
155 }
156}
157```
158
159## Rewind
160
161Rewinding a thread restores its project folder and each repository it works in. Two cases are not
162restored:
163
164- **A plain project folder.** Only repositories have snapshots, so files that sit outside every
165 repository keep their current contents.
166- **A repository with no earlier snapshot.** If nothing was recorded for a repository before the
167 turns you discard, it keeps their changes. The rewind still completes and names the repositories
168 it left, so check their uncommitted changes afterwards.
169
170## Limits
171
172- One Git action runs in one repository. There is no commit or push across several at once.
173- Only the project folder's `t3.json` is read. Setup scripts and actions inside one of its
174 repositories are not picked up.
175- The Diff pane's repository picker and the base branch field for a plain folder are on web and
176 desktop only.