git worktree: add adopt command for existing git worktrees - #9943
Conversation
dc3e4e4 to
4ed7616
Compare
|
This looks quite messy. Can we instead add a maintenance command to enable/disable Git worktree? |
4ed7616 to
eb478b3
Compare
eb478b3 to
dc99e45
Compare
9564cd7 to
fe10f40
Compare
fe10f40 to
f177bca
Compare
|
I've pushed updates that clean up the implementation and tried to make it less messy. On the design question: this behavior only applies to colocated repositories. The whole point of colocation is that jj and git share the same working state---if a user has opted into colocation, then git worktrees are part of that shared state. When another process modifies git refs, HEAD, or the working copy outside of jj, the next This is particularly relevant with AI coding tools (like Claude Code, Cursor, etc.), which increasingly use I'm not sure how a maintenance command would handle all the different cases that come up:
Happy to discuss further if you have a specific design in mind. |
f177bca to
ad95e0b
Compare
Maybe I don't follow, but since a I don't have a strong feeling about removed worktrees, but it isn't probably a new problem? A jj workspace can also be removed by |
fbade4b to
837ef54
Compare
837ef54 to
70e65d2
Compare
|
I agree with Yuya that this is to messy and see my other comment down in the stack. |
70e65d2 to
d376469
Compare
|
On auto-adopting worktrees: The whole premise of colocation is that jj and git share state, and jj automatically syncs that state on every invocation. When an external tool runs git checkout or modifies refs, jj imports those changes automatically---no maintenance command needed. Git worktrees are just another dimension of that shared git state. If an external tool (which knows nothing about jj) runs On reconciling removed worktrees: This actually is different from |
|
As far as I can tell, colocation is a per-workspace state. Users can freely choose to add a non-colocated jj workspace or Git worktree. I'm not against adding an opt-in feature to synchronize Git worktrees and jj workspaces automatically (similar to |
d376469 to
db4ab64
Compare
0b89d94 to
5ec873f
Compare
5ec873f to
44c9932
Compare
fd76582 to
ab4689f
Compare
|
@yuja, @PhilipMetzger I've restructured the PRs 👍 |
ab4689f to
e17be61
Compare
e17be61 to
b851f05
Compare
|
Same here. Something like |
b851f05 to
3412dc4
Compare
10ac4ef to
ab11256
Compare
ab11256 to
9f4313d
Compare
Add `jj git worktree adopt` command that adopts existing Git worktrees as jj workspaces. Three modes are supported: * No arguments: adopts the Git worktree at the current directory. * Named worktrees: `jj git worktree adopt <name>...` adopts specific Git worktrees by name from any jj workspace or git worktree. * `--all`: adopts all unadopted Git worktrees at once. The command works from within an existing jj workspace or from inside an unadopted git worktree by discovering the parent jj repo via git. Guardrails prevent adopting from the main workspace directory and report clear errors for already-adopted or nonexistent worktrees.
9f4313d to
e8cd42f
Compare
Add
jj git worktree adoptcommand that adopts existing Git worktreesas jj workspaces. Three modes are supported:
jj git worktree adopt <name>...adopts specificGit worktrees by name from any jj workspace or git worktree.
--all: adopts all unadopted Git worktrees at once.The command works from within an existing jj workspace or from inside
an unadopted git worktree by discovering the parent jj repo via git.
Guardrails prevent adopting from the main workspace directory and
report clear errors for already-adopted or nonexistent worktrees.
Checklist
If applicable:
CHANGELOG.mdREADME.md,docs/,demos/)cli/src/config-schema.json)how it works, how it's organized), including any code drafted by an LLM.
an eye towards deleting anything that is irrelevant, clarifying anything
that is confusing, and adding details that are relevant. This includes,
for example, commit descriptions, PR descriptions, and code comments.