You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/gitops.md
+122Lines changed: 122 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -212,3 +212,125 @@ sequenceDiagram
212
212
API-->>Client: HTTP 409
213
213
deactivate API
214
214
```
215
+
216
+
## Version three - Git Worktrees
217
+
218
+
The git worktrees implementation eliminates the performance bottleneck of cloning from remote repository for each request. Instead, a main repository is maintained locally and git worktrees are created for each session. This provides instant session creation while maintaining complete isolation between concurrent operations.
219
+
220
+
**Key improvements:**
221
+
- Main repository cloned once at startup, eliminating remote clone overhead
222
+
- Git worktrees created instantly from local main repository
223
+
- Each session operates on an isolated branch with independent `.git/index.lock` files
224
+
- Direct push from session branch to main branch on remote
225
+
- Automatic cleanup of worktrees and branches after completion
226
+
- No blocking operations between concurrent sessions due to isolated git indexes
227
+
228
+
```mermaid
229
+
sequenceDiagram
230
+
autonumber
231
+
participant Client1 as Client 1
232
+
participant Client2 as Client 2
233
+
participant API as API Server
234
+
participant MainRepo as Main Git Repo
235
+
participant Worktree1 as Session Worktree 1
236
+
participant Worktree2 as Session Worktree 2
237
+
participant Remote as Remote Git Repository
238
+
239
+
240
+
Note over API,MainRepo: Application Startup
241
+
API->>MainRepo: Initialize main repo (clone/pull)
242
+
activate MainRepo
243
+
MainRepo-->>API: Ready
244
+
245
+
246
+
Note over Client1,Remote: Concurrent API Requests
247
+
Client1->>API: POST/PUT/DELETE Request
248
+
activate API
249
+
API->>API: Generate sessionId (UUID)
250
+
API->>MainRepo: createWorktree(sessionId, main)
251
+
MainRepo->>Worktree1: git worktree add -b sessionId path main
Note over Client1,Remote: Result: No slow remote cloning per request
322
+
Note over Client1,Remote: Result: Instant worktree creation from local repo
323
+
Note over Client1,Remote: Each session worked on isolated branch
324
+
Note over Client1,Remote: Direct push to main: sessionBranch:main
325
+
Note over Client1,Remote: No index.lock conflicts between sessions
326
+
```
327
+
328
+
**Git Index Isolation:**
329
+
Version two avoided `.git/index.lock` conflicts by cloning the entire repository from remote to separate directories for each session. While this provided isolation, it created a significant performance bottleneck due to repeated remote cloning.
330
+
331
+
Git worktrees provide the same isolation benefits but with instant creation from a local repository:
332
+
- Main repo: `.git/index` and `.git/index.lock`
333
+
- Worktree 1: `.git/worktrees/sessionId1/index` and `.git/worktrees/sessionId1/index.lock`
334
+
- Worktree 2: `.git/worktrees/sessionId2/index` and `.git/worktrees/sessionId2/index.lock`
335
+
336
+
This maintains the concurrency benefits of version two while eliminating the remote cloning performance penalty.
0 commit comments