feat: add git worktree isolation via port shifting#421
Conversation
Korbeil
left a comment
There was a problem hiding this comment.
implementation seems nice !
since the worktree usage is clearly agents focused, I think we should bundle a template AGENTS.md with minimum instruction about this worktree support so agents can use it efficiently
lyrixx
left a comment
There was a problem hiding this comment.
Nice, but IMHO we could simplify this but not using the context for fews keys
4f658da to
bd6a9c1
Compare
lyrixx
left a comment
There was a problem hiding this comment.
Nice ! Except three little comment, I'm 👍🏼
| $urls = [variable('root_domain'), ...variable('extra_domains')]; | ||
|
|
||
| $worktreeName = get_worktree_name(); | ||
| $adminPort = null !== $worktreeName ? get_worktree_ports($worktreeName)['admin'] : null; |
There was a problem hiding this comment.
So admin port can be null? then the next line will fail :/ could the default value ve 8080? (old defefault one)
| } | ||
|
|
||
| io()->listing(array_map(static fn ($url) => "https://{$url}", array_unique($urls))); | ||
| $worktreeName = get_worktree_name(); |
There was a problem hiding this comment.
you already get that var about, L41
| use function worktree\get_worktree_name; | ||
|
|
||
| /** @return array<string, array{env: string, default: int, label: string}> */ | ||
| function get_port_specs(): array |
There was a problem hiding this comment.
I wonder if this function should goes to docker.php, WDYT?
Summary
When using git worktrees (e.g. with an AI coding agent working on multiple branches), each worktree needs its own isolated Docker infrastructure — otherwise containers, volumes, networks, and ports conflict.
This PR adds automatic detection of git worktrees and shifts Docker Compose project names and ports accordingly, so each worktree runs its own stack in parallel without modifying
/etc/hosts.How it works
.gitfile (content:gitdir: ...) to detect worktree mode-wt-<worktree-name>→ Docker Compose isolates containers, volumes, networks automatically/etc/hostsmodifications per worktreeUX
castor startnow prints the allocated ports at the endcastor aboutincludes the HTTPS port in URLs when in a worktreecastor docker:portstask to display ports at any time